block: fix resource leak in blk_register_queue() error path
authorZheng Qixing <zhengqixing@huawei.com>
Sat, 12 Apr 2025 09:25:54 +0000 (17:25 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:42 +0000 (10:45 +0200)
[ Upstream commit 40f2eb9b531475dd01b683fdaf61ca3cfd03a51e ]

When registering a queue fails after blk_mq_sysfs_register() is
successful but the function later encounters an error, we need
to clean up the blk_mq_sysfs resources.

Add the missing blk_mq_sysfs_unregister() call in the error path
to properly clean up these resources and prevent a memory leak.

Fixes: 320ae51feed5 ("blk-mq: new multi-queue block IO queueing mechanism")
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250412092554.475218-1-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-sysfs.c

index 4990a19e60133431c60e1ecb61db3351f6f8fe86..74839f6f2e0cb3ff45e03599f5d1a57cb756588f 100644 (file)
@@ -854,6 +854,8 @@ out_unregister_ia_ranges:
 out_debugfs_remove:
        blk_debugfs_remove(disk);
        mutex_unlock(&q->sysfs_lock);
+       if (queue_is_mq(q))
+               blk_mq_sysfs_unregister(disk);
 out_put_queue_kobj:
        kobject_put(&disk->queue_kobj);
        mutex_unlock(&q->sysfs_dir_lock);