From 42ec0c007e6b62017fd0544b7852d2c32dba65e8 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 8 Aug 2017 14:03:25 -0700 Subject: [PATCH] nvmf: fix crash on shutdown with invalid config If a bdev-based controller is partially set up but then needs to be torn down due to an invalid configuration, the nvmf_bdev_ctrlr_detach() function could try to put a NULL spdk_io_channel. Add checks to avoid releasing resources that weren't allocated yet. Change-Id: I779c80f4dc654af3c4b0a49d8d216e13ab5f8333 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/373390 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker --- lib/nvmf/ctrlr_bdev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/nvmf/ctrlr_bdev.c b/lib/nvmf/ctrlr_bdev.c index e142b5fd0..398855070 100644 --- a/lib/nvmf/ctrlr_bdev.c +++ b/lib/nvmf/ctrlr_bdev.c @@ -675,9 +675,14 @@ nvmf_bdev_ctrlr_detach(struct spdk_nvmf_subsystem *subsystem) for (i = 0; i < subsystem->dev.max_nsid; i++) { if (subsystem->dev.ns_list[i]) { - spdk_put_io_channel(subsystem->dev.ch[i]); - spdk_bdev_close(subsystem->dev.desc[i]); - subsystem->dev.ch[i] = NULL; + if (subsystem->dev.ch[i]) { + spdk_put_io_channel(subsystem->dev.ch[i]); + subsystem->dev.ch[i] = NULL; + } + if (subsystem->dev.desc[i]) { + spdk_bdev_close(subsystem->dev.desc[i]); + subsystem->dev.desc[i] = NULL; + } subsystem->dev.ns_list[i] = NULL; } }