Skip to content

Commit 518d00b

Browse files
ming1torvalds
authored andcommitted
block: null_blk: fix queue leak inside removing device
When queue_mode is NULL_Q_MQ and null_blk is being removed, blk_cleanup_queue() isn't called to cleanup queue, so the queue allocated won't be freed. This patch calls blk_cleanup_queue() for MQ to drain all pending requests first and release the reference counter of queue kobject, then blk_mq_free_queue() will be called in queue kobject's release handler when queue kobject's reference counter drops to zero. Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 228fdc0 commit 518d00b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

drivers/block/null_blk.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,7 @@ static void null_del_dev(struct nullb *nullb)
425425
list_del_init(&nullb->list);
426426

427427
del_gendisk(nullb->disk);
428-
if (queue_mode == NULL_Q_MQ)
429-
blk_mq_free_queue(nullb->q);
430-
else
431-
blk_cleanup_queue(nullb->q);
428+
blk_cleanup_queue(nullb->q);
432429
put_disk(nullb->disk);
433430
kfree(nullb);
434431
}
@@ -578,10 +575,7 @@ static int null_add_dev(void)
578575
disk = nullb->disk = alloc_disk_node(1, home_node);
579576
if (!disk) {
580577
queue_fail:
581-
if (queue_mode == NULL_Q_MQ)
582-
blk_mq_free_queue(nullb->q);
583-
else
584-
blk_cleanup_queue(nullb->q);
578+
blk_cleanup_queue(nullb->q);
585579
cleanup_queues(nullb);
586580
err:
587581
kfree(nullb);

0 commit comments

Comments
 (0)