Fix double mutex lock.

Reported by:	Coverity
CID:		1394833
Discussed with:	Leon Dang
Sponsored by:	iXsystems Inc.
This commit is contained in:
Marcelo Araujo 2018-08-20 04:44:29 +00:00
parent b991b318d4
commit df90fce298
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=338087

View File

@ -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));
@ -413,6 +410,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)
{
@ -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);
}