diff options
author | Marcelo Araujo <araujo@FreeBSD.org> | 2018-08-20 04:44:29 +0000 |
---|---|---|
committer | Marcelo Araujo <araujo@FreeBSD.org> | 2018-08-20 04:44:29 +0000 |
commit | df90fce298821ae3bff305b42d35ea8a3c037d20 (patch) | |
tree | 4c8e2efbba58374e8bf6c5b1ad6c32881a90c208 /usr.sbin | |
parent | b991b318d40c221f39b54333f0725900c48f9020 (diff) | |
download | src-df90fce298821ae3bff305b42d35ea8a3c037d20.tar.gz src-df90fce298821ae3bff305b42d35ea8a3c037d20.zip |
Fix double mutex lock.
Reported by: Coverity
CID: 1394833
Discussed with: Leon Dang
Sponsored by: iXsystems Inc.
Notes
Notes:
svn path=/head/; revision=338087
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bhyve/pci_nvme.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index 5fc4c2af705a..3671db162752 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -358,7 +358,7 @@ pci_nvme_init_nsdata(struct pci_nvme_softc *sc) } static void -pci_nvme_reset(struct pci_nvme_softc *sc) +pci_nvme_reset_locked(struct pci_nvme_softc *sc) { DPRINTF(("%s\r\n", __func__)); @@ -374,7 +374,6 @@ pci_nvme_reset(struct pci_nvme_softc *sc) sc->regs.csts = 0; if (sc->submit_queues != NULL) { - pthread_mutex_lock(&sc->mtx); sc->num_cqueues = sc->num_squeues = sc->max_queues; for (int i = 0; i <= sc->max_queues; i++) { @@ -398,8 +397,6 @@ pci_nvme_reset(struct pci_nvme_softc *sc) sc->compl_queues[i].tail = 0; sc->compl_queues[i].head = 0; } - - pthread_mutex_unlock(&sc->mtx); } else sc->submit_queues = calloc(sc->max_queues + 1, sizeof(struct nvme_submission_queue)); @@ -414,6 +411,14 @@ pci_nvme_reset(struct pci_nvme_softc *sc) } static void +pci_nvme_reset(struct pci_nvme_softc *sc) +{ + pthread_mutex_lock(&sc->mtx); + pci_nvme_reset_locked(sc); + pthread_mutex_unlock(&sc->mtx); +} + +static void pci_nvme_init_controller(struct vmctx *ctx, struct pci_nvme_softc *sc) { uint16_t acqs, asqs; @@ -1537,7 +1542,7 @@ pci_nvme_write_bar_0(struct vmctx *ctx, struct pci_nvme_softc* sc, if (NVME_CC_GET_EN(ccreg) != NVME_CC_GET_EN(sc->regs.cc)) { if (NVME_CC_GET_EN(ccreg) == 0) /* transition 1-> causes controller reset */ - pci_nvme_reset(sc); + pci_nvme_reset_locked(sc); else pci_nvme_init_controller(ctx, sc); } |