summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2017-01-26 21:02:06 +0000
committermav <mav@FreeBSD.org>2017-01-26 21:02:06 +0000
commit0a3bb39848013e69351df193897f1a7c963babfa (patch)
treed81cffc3c88860600962407725fe5c9fb8a4ee00
parentcce5ebe6044dbb57219042e8ebe92b059dac6dfc (diff)
downloadFreeBSD-src-0a3bb39848013e69351df193897f1a7c963babfa.zip
FreeBSD-src-0a3bb39848013e69351df193897f1a7c963babfa.tar.gz
MFC r311873: Fix malloc(M_WAITOK) under mutex, introduced at r311787.
-rw-r--r--sys/cam/ctl/ctl.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c
index 30082cb..d37daa4 100644
--- a/sys/cam/ctl/ctl.c
+++ b/sys/cam/ctl/ctl.c
@@ -4584,6 +4584,8 @@ ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun,
printf("ctl: requested LUN ID %d is already "
"in use\n", be_lun->req_lun_id);
}
+fail:
+ free(lun->lun_devid, M_CTL);
if (lun->flags & CTL_LUN_MALLOCED)
free(lun, M_CTL);
be_lun->lun_config_status(be_lun->be_lun,
@@ -4596,14 +4598,11 @@ ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun,
if (lun_number == -1) {
mtx_unlock(&ctl_softc->ctl_lock);
printf("ctl: can't allocate LUN, out of LUNs\n");
- if (lun->flags & CTL_LUN_MALLOCED)
- free(lun, M_CTL);
- be_lun->lun_config_status(be_lun->be_lun,
- CTL_LUN_CONFIG_FAILURE);
- return (ENOSPC);
+ goto fail;
}
}
ctl_set_mask(ctl_softc->ctl_lun_mask, lun_number);
+ mtx_unlock(&ctl_softc->ctl_lock);
mtx_init(&lun->lun_lock, "CTL LUN", NULL, MTX_DEF);
lun->lun = lun_number;
@@ -4655,22 +4654,6 @@ ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun,
ctl_init_page_index(lun);
ctl_init_log_page_index(lun);
- /*
- * Now, before we insert this lun on the lun list, set the lun
- * inventory changed UA for all other luns.
- */
- STAILQ_FOREACH(nlun, &ctl_softc->lun_list, links) {
- mtx_lock(&nlun->lun_lock);
- ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE);
- mtx_unlock(&nlun->lun_lock);
- }
-
- STAILQ_INSERT_TAIL(&ctl_softc->lun_list, lun, links);
-
- ctl_softc->ctl_luns[lun_number] = lun;
-
- ctl_softc->num_luns++;
-
/* Setup statistics gathering */
#ifdef CTL_LEGACY_STATS
lun->legacy_stats.device_type = be_lun->lun_type;
@@ -4683,6 +4666,19 @@ ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun,
#endif /* CTL_LEGACY_STATS */
lun->stats.item = lun_number;
+ /*
+ * Now, before we insert this lun on the lun list, set the lun
+ * inventory changed UA for all other luns.
+ */
+ mtx_lock(&ctl_softc->ctl_lock);
+ STAILQ_FOREACH(nlun, &ctl_softc->lun_list, links) {
+ mtx_lock(&nlun->lun_lock);
+ ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE);
+ mtx_unlock(&nlun->lun_lock);
+ }
+ STAILQ_INSERT_TAIL(&ctl_softc->lun_list, lun, links);
+ ctl_softc->ctl_luns[lun_number] = lun;
+ ctl_softc->num_luns++;
mtx_unlock(&ctl_softc->ctl_lock);
lun->be_lun->lun_config_status(lun->be_lun->be_lun, CTL_LUN_CONFIG_OK);
OpenPOWER on IntegriCloud