From 0e2ea8797f1c24fd55b4b3a5d40e910ecf16724c Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Fri, 17 Mar 2017 12:39:51 +0100 Subject: [PATCH] bdev/nvme: remove dangling pointer from g_nvme_bdevs list on bdev_nvme destruction It was causing segfaults and infinite looping. Change-Id: I4c19b5d3af1ba1360250cd5f6aa573a27003409f Signed-off-by: Dariusz Stojaczyk --- lib/bdev/nvme/blockdev_nvme.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/bdev/nvme/blockdev_nvme.c b/lib/bdev/nvme/blockdev_nvme.c index ee410b58d..bef6769ea 100644 --- a/lib/bdev/nvme/blockdev_nvme.c +++ b/lib/bdev/nvme/blockdev_nvme.c @@ -197,20 +197,16 @@ bdev_nvme_poll_adminq(void *arg) static int bdev_nvme_destruct(struct spdk_bdev *bdev) { - bool removable = true; struct nvme_bdev *nvme_disk = (struct nvme_bdev *)bdev; struct nvme_ctrlr *nvme_ctrlr = nvme_disk->nvme_ctrlr; pthread_mutex_lock(&g_bdev_nvme_mutex); nvme_ctrlr->ref--; - if (nvme_ctrlr->ref != 0) { - removable = false; - } - + TAILQ_REMOVE(&g_nvme_bdevs, nvme_disk, link); free(nvme_disk); - if (removable == true) { + if (nvme_ctrlr->ref == 0) { TAILQ_REMOVE(&g_nvme_ctrlrs, nvme_ctrlr, tailq); pthread_mutex_unlock(&g_bdev_nvme_mutex); spdk_io_device_unregister(nvme_ctrlr->ctrlr); @@ -808,7 +804,6 @@ bdev_nvme_library_fini(void) struct nvme_bdev *nvme_bdev, *btmp; TAILQ_FOREACH_SAFE(nvme_bdev, &g_nvme_bdevs, link, btmp) { - TAILQ_REMOVE(&g_nvme_bdevs, nvme_bdev, link); bdev_nvme_destruct(&nvme_bdev->disk); } }