The branch main has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=b29dc5a30cce666896217a03a8067eba8b018eb6

commit b29dc5a30cce666896217a03a8067eba8b018eb6
Author:     John Baldwin <[email protected]>
AuthorDate: 2026-08-26 19:30:17 +0000
Commit:     John Baldwin <[email protected]>
CommitDate: 2026-08-26 19:30:17 +0000

    bhyve: Return void from pci_emul_alloc_bar
    
    This function never fails.
    
    Reviewed by:    bnovkov, chuck, markj
    Differential Revision:  https://reviews.freebsd.org/D58579
---
 usr.sbin/bhyve/pci_emul.c     | 22 ++++++----------------
 usr.sbin/bhyve/pci_emul.h     |  2 +-
 usr.sbin/bhyve/pci_fbuf.c     |  7 ++-----
 usr.sbin/bhyve/pci_nvme.c     |  6 +-----
 usr.sbin/bhyve/pci_passthru.c |  6 ++----
 5 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index 538e4f284bec..7637049f0dd9 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -795,7 +795,7 @@ update_bar_address(struct pci_devinst *pi, uint64_t addr, 
int idx, int type)
                register_bar(pi, idx);
 }
 
-int
+void
 pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type,
     uint64_t size)
 {
@@ -863,7 +863,7 @@ pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum 
pcibar_type type,
         * ROM to handle this.
         */
        if (!get_config_bool_default("pci.enable_bars", !bootrom_boot()))
-               return (0);
+               return;
 
        /*
         * pci_passthru devices synchronize their physical and virtual command
@@ -886,8 +886,6 @@ pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum 
pcibar_type type,
 
        const uint16_t cmd = pci_get_cfgdata16(pdi, PCIR_COMMAND);
        pci_set_cfgdata16(pdi, PCIR_COMMAND, cmd | enbit);
-
-       return (0);
 }
 
 static int
@@ -1027,10 +1025,7 @@ pci_emul_alloc_rom(struct pci_devinst *const pdi, const 
uint64_t size,
        }
 
        /* allocate ROM BAR */
-       const int error = pci_emul_alloc_bar(pdi, PCI_ROM_IDX, PCIBAR_ROM,
-           rom_size);
-       if (error)
-               return error;
+       pci_emul_alloc_bar(pdi, PCI_ROM_IDX, PCIBAR_ROM, rom_size);
 
        /* return address */
        *addr = pci_emul_rombase + pci_emul_romoffset;
@@ -2620,14 +2615,9 @@ pci_emul_dinit(struct pci_devinst *pi, nvlist_t *nvl 
__unused)
        error = pci_emul_add_msicap(pi, PCI_EMUL_MSI_MSGS);
        assert(error == 0);
 
-       error = pci_emul_alloc_bar(pi, 0, PCIBAR_IO, DIOSZ);
-       assert(error == 0);
-
-       error = pci_emul_alloc_bar(pi, 1, PCIBAR_MEM32, DMEMSZ);
-       assert(error == 0);
-
-       error = pci_emul_alloc_bar(pi, 2, PCIBAR_MEM32, DMEMSZ);
-       assert(error == 0);
+       pci_emul_alloc_bar(pi, 0, PCIBAR_IO, DIOSZ);
+       pci_emul_alloc_bar(pi, 1, PCIBAR_MEM32, DMEMSZ);
+       pci_emul_alloc_bar(pi, 2, PCIBAR_MEM32, DMEMSZ);
 
        return (0);
 }
diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h
index 4bf617dc3219..9aeb11496943 100644
--- a/usr.sbin/bhyve/pci_emul.h
+++ b/usr.sbin/bhyve/pci_emul.h
@@ -233,7 +233,7 @@ int init_pci(struct vmctx *ctx);
 void   pci_callback(void);
 uint32_t pci_config_read_reg(const struct pci_conf *host_conf, nvlist_t *nvl,
            uint32_t reg, uint8_t size, uint32_t def);
-int    pci_emul_alloc_bar(struct pci_devinst *pdi, int idx,
+void   pci_emul_alloc_bar(struct pci_devinst *pdi, int idx,
            enum pcibar_type type, uint64_t size);
 int    pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size,
            void **const addr);
diff --git a/usr.sbin/bhyve/pci_fbuf.c b/usr.sbin/bhyve/pci_fbuf.c
index 560c2bc839d6..011bb606d708 100644
--- a/usr.sbin/bhyve/pci_fbuf.c
+++ b/usr.sbin/bhyve/pci_fbuf.c
@@ -409,11 +409,8 @@ pci_fbuf_init(struct pci_devinst *pi, nvlist_t *nvl)
                goto done;
        }
 
-       error = pci_emul_alloc_bar(pi, 0, PCIBAR_MEM32, DMEMSZ);
-       assert(error == 0);
-
-       error = pci_emul_alloc_bar(pi, 1, PCIBAR_MEM32, FB_SIZE);
-       assert(error == 0);
+       pci_emul_alloc_bar(pi, 0, PCIBAR_MEM32, DMEMSZ);
+       pci_emul_alloc_bar(pi, 1, PCIBAR_MEM32, FB_SIZE);
 
        error = pci_emul_add_msicap(pi, PCI_FBUF_MSI_MSGS);
        assert(error == 0);
diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c
index 0e20122648a6..7e6768de8550 100644
--- a/usr.sbin/bhyve/pci_nvme.c
+++ b/usr.sbin/bhyve/pci_nvme.c
@@ -3342,11 +3342,7 @@ pci_nvme_init(struct pci_devinst *pi, nvlist_t *nvl)
 
        DPRINTF("nvme membar size: %u", pci_membar_sz);
 
-       error = pci_emul_alloc_bar(pi, 0, PCIBAR_MEM64, pci_membar_sz);
-       if (error) {
-               WPRINTF("%s pci alloc mem bar failed", __func__);
-               goto done;
-       }
+       pci_emul_alloc_bar(pi, 0, PCIBAR_MEM64, pci_membar_sz);
 
        error = pci_emul_add_msixcap(pi, sc->max_queues + 1, NVME_MSIX_BAR);
        if (error) {
diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index 24d96764964d..740d9ad45d03 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -627,7 +627,7 @@ init_msix_table(struct passthru_softc *sc)
 static int
 cfginitbar(struct passthru_softc *sc)
 {
-       int i, error;
+       int i;
        struct pci_devinst *pi;
        struct pci_bar_io bar;
        enum pcibar_type bartype;
@@ -681,9 +681,7 @@ cfginitbar(struct passthru_softc *sc)
                sc->psc_bar[i].lobits = 0;
 
                /* Allocate the BAR in the guest I/O or MMIO space */
-               error = pci_emul_alloc_bar(pi, i, bartype, size);
-               if (error)
-                       return (-1);
+               pci_emul_alloc_bar(pi, i, bartype, size);
 
                /* Use same lobits as physical bar */
                lobits = (uint8_t)passthru_read_config(&sc->psc_sel,

Reply via email to