From bdbf45b987a2c76831bbfac547096642682173ba Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 23 Feb 2019 15:37:22 +0800 Subject: [PATCH] blk-mq: Add a NULL check in blk_mq_free_map_and_requests() mainline inclusion from mainline-5.0-rc1 commit 4e6db0f21c99c25980c8d183f95cdb6ad64cebd2 category: bugfix bugzilla: 9684 CVE: NA --------------------------- I recently found some code which called blk_mq_free_map_and_requests() with a NULL set->tags pointer. I fixed the caller, but it seems like a good idea to add a NULL check here as well. Now we can call: blk_mq_free_tag_set(set); blk_mq_free_tag_set(set); twice in a row and it's harmless. Signed-off-by: Dan Carpenter Signed-off-by: Jens Axboe Signed-off-by: Yufen Yu Reviewed-by: Hou Tao Signed-off-by: Yang Yingliang --- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 1218200c2606..8122359fa429 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2285,7 +2285,7 @@ static bool __blk_mq_alloc_rq_map(struct blk_mq_tag_set *set, int hctx_idx) static void blk_mq_free_map_and_requests(struct blk_mq_tag_set *set, unsigned int hctx_idx) { - if (set->tags[hctx_idx]) { + if (set->tags && set->tags[hctx_idx]) { blk_mq_free_rqs(set, set->tags[hctx_idx], hctx_idx); blk_mq_free_rq_map(set->tags[hctx_idx]); set->tags[hctx_idx] = NULL; -- GitLab