From 66af6221a0a7aee13b3d3b96544e403a774ea991 Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 26 Dec 2019 16:11:02 -0500 Subject: [PATCH] bdev: check whether memory allocated already In the case of bdev initialization, the memory could not be allocated. When cleaning up, it needs to check whether the memory pointer is valid or not before touching the address of the pointer. This is to fix below issue: https://github.com/spdk/spdk/issues/1126 Change-Id: Iec0e2c5a40ad153a96fb939414a15ac3b9112a01 Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478849 Community-CI: SPDK CI Jenkins Reviewed-by: Reviewed-by: yidong0635 Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki Tested-by: SPDK CI Jenkins --- lib/bdev/bdev.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 26c0fd372..0ceeb3201 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -1125,29 +1125,38 @@ bdev_mgr_unregister_cb(void *io_device) { spdk_bdev_fini_cb cb_fn = g_fini_cb_fn; - if (spdk_mempool_count(g_bdev_mgr.bdev_io_pool) != g_bdev_opts.bdev_io_pool_size) { - SPDK_ERRLOG("bdev IO pool count is %zu but should be %u\n", - spdk_mempool_count(g_bdev_mgr.bdev_io_pool), - g_bdev_opts.bdev_io_pool_size); + if (g_bdev_mgr.bdev_io_pool) { + if (spdk_mempool_count(g_bdev_mgr.bdev_io_pool) != g_bdev_opts.bdev_io_pool_size) { + SPDK_ERRLOG("bdev IO pool count is %zu but should be %u\n", + spdk_mempool_count(g_bdev_mgr.bdev_io_pool), + g_bdev_opts.bdev_io_pool_size); + } + + spdk_mempool_free(g_bdev_mgr.bdev_io_pool); } - if (spdk_mempool_count(g_bdev_mgr.buf_small_pool) != BUF_SMALL_POOL_SIZE) { - SPDK_ERRLOG("Small buffer pool count is %zu but should be %u\n", - spdk_mempool_count(g_bdev_mgr.buf_small_pool), - BUF_SMALL_POOL_SIZE); - assert(false); + if (g_bdev_mgr.buf_small_pool) { + if (spdk_mempool_count(g_bdev_mgr.buf_small_pool) != BUF_SMALL_POOL_SIZE) { + SPDK_ERRLOG("Small buffer pool count is %zu but should be %u\n", + spdk_mempool_count(g_bdev_mgr.buf_small_pool), + BUF_SMALL_POOL_SIZE); + assert(false); + } + + spdk_mempool_free(g_bdev_mgr.buf_small_pool); } - if (spdk_mempool_count(g_bdev_mgr.buf_large_pool) != BUF_LARGE_POOL_SIZE) { - SPDK_ERRLOG("Large buffer pool count is %zu but should be %u\n", - spdk_mempool_count(g_bdev_mgr.buf_large_pool), - BUF_LARGE_POOL_SIZE); - assert(false); + if (g_bdev_mgr.buf_large_pool) { + if (spdk_mempool_count(g_bdev_mgr.buf_large_pool) != BUF_LARGE_POOL_SIZE) { + SPDK_ERRLOG("Large buffer pool count is %zu but should be %u\n", + spdk_mempool_count(g_bdev_mgr.buf_large_pool), + BUF_LARGE_POOL_SIZE); + assert(false); + } + + spdk_mempool_free(g_bdev_mgr.buf_large_pool); } - spdk_mempool_free(g_bdev_mgr.bdev_io_pool); - spdk_mempool_free(g_bdev_mgr.buf_small_pool); - spdk_mempool_free(g_bdev_mgr.buf_large_pool); spdk_free(g_bdev_mgr.zero_buffer); cb_fn(g_fini_cb_arg);