From 37baa108b86b3350c5f0c8138b552a4dc12f05f7 Mon Sep 17 00:00:00 2001 From: seanc Date: Fri, 12 Jul 2019 18:33:58 +0000 Subject: [PATCH] usr.sbin/bhyve: only unassign a pt device after obtaining bus/slot/func Coverity CID: 1194302, 1194303, 1194304 Approved by: jhb, markj Differential Revision: https://reviews.freebsd.org/D20933 --- usr.sbin/bhyve/pci_passthru.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 852643e9d77..40bbc4c7827 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -668,14 +668,14 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) memflags = vm_get_memflags(ctx); if (!(memflags & VM_MEM_F_WIRED)) { warnx("passthru requires guest memory to be wired"); - goto done; + return (error); } if (pcifd < 0) { pcifd = open(_PATH_DEVPCI, O_RDWR, 0); if (pcifd < 0) { warn("failed to open %s", _PATH_DEVPCI); - goto done; + return (error); } } @@ -690,7 +690,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) iofd = open(_PATH_DEVIO, O_RDWR, 0); if (iofd < 0) { warn("failed to open %s", _PATH_DEVIO); - goto done; + return (error); } } @@ -705,7 +705,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) memfd = open(_PATH_MEM, O_RDWR, 0); if (memfd < 0) { warn("failed to open %s", _PATH_MEM); - goto done; + return (error); } } @@ -719,7 +719,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) if (opts == NULL || sscanf(opts, "%d/%d/%d", &bus, &slot, &func) != 3) { warnx("invalid passthru options"); - goto done; + return (error); } if (vm_assign_pptdev(ctx, bus, slot, func) != 0) { @@ -734,10 +734,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) sc->psc_pi = pi; /* initialize config space */ - if ((error = cfginit(ctx, pi, bus, slot, func)) != 0) - goto done; - - error = 0; /* success */ + error = cfginit(ctx, pi, bus, slot, func); done: if (error) { free(sc); -- 2.45.0