* [PATCH 5.15.y] block: fix resource leak in blk_register_queue() error path
@ 2026-04-09 6:36 Robert Garcia
2026-04-13 4:14 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Robert Garcia @ 2026-04-09 6:36 UTC (permalink / raw)
To: stable, Zheng Qixing
Cc: Jens Axboe, Robert Garcia, Christoph Hellwig, Yu Kuai,
linux-block, linux-kernel
From: Zheng Qixing <zhengqixing@huawei.com>
[ 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>
[ Change disk to q in blk_mq_sysfs_unregister(). ]
Signed-off-by: Robert Garcia <rob_garcia@163.com>
---
block/blk-sysfs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 4ea84e46a665..c1917992e619 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -900,6 +900,8 @@ int blk_register_queue(struct gendisk *disk)
if (q->elevator)
kobject_uevent(&q->elevator->kobj, KOBJ_ADD);
mutex_unlock(&q->sysfs_lock);
+ if (queue_is_mq(q))
+ blk_mq_sysfs_unregister(q);
ret = 0;
unlock:
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 5.15.y] block: fix resource leak in blk_register_queue() error path
2026-04-09 6:36 [PATCH 5.15.y] block: fix resource leak in blk_register_queue() error path Robert Garcia
@ 2026-04-13 4:14 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-04-13 4:14 UTC (permalink / raw)
To: Robert Garcia; +Cc: Sasha Levin, stable, Jens Axboe
> [PATCH 5.15.y] block: fix resource leak in blk_register_queue()
> error path
This patch places blk_mq_sysfs_unregister(q) on the success path (after
kobject_uevent, before 'ret = 0') rather than on the error path. As written,
this would unregister sysfs on every successful blk_register_queue() call,
breaking block device initialization.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-13 4:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 6:36 [PATCH 5.15.y] block: fix resource leak in blk_register_queue() error path Robert Garcia
2026-04-13 4:14 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox