Skip to contentSkip to conversation

blk-mq: fix queue reference leak on blk_mq_alloc_disk_for_queue failure

PATCH Applied Christoph Hellwig 3 participants 3 messages Nov 22, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-mq: fix queue reference leak on blk_mq_alloc_disk_for_queue failure

Drop the disk reference just acquired when __alloc_disk_node failed.

Fixes 6f8191fdf41d ("block: simplify disk shutdown")
---
 block/blk-mq.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block/blk-mq.c +6 -1
index a3a5fb4d4ef667..02a1f6e501ea8d 100644
@@ -4108,9 +4108,14 @@ EXPORT_SYMBOL(__blk_mq_alloc_disk);
 struct gendisk *blk_mq_alloc_disk_for_queue(struct request_queue *q,
 		struct lock_class_key *lkclass)
 {
+	struct gendisk *disk;
+
 	if (!blk_get_queue(q))
 		return NULL;
-	return __alloc_disk_node(q, NUMA_NO_NODE, lkclass);
+	disk = __alloc_disk_node(q, NUMA_NO_NODE, lkclass);
+	if (!disk)
+		blk_put_queue(q);
+	return disk;
 }
 EXPORT_SYMBOL(blk_mq_alloc_disk_for_queue);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Christoph Hellwig

Drop the disk reference just acquired when __alloc_disk_node failed.

s/disk reference/request queue reference

Apart from that, looks good to me.

Quoted 28 lines
Fixes 6f8191fdf41d ("block: simplify disk shutdown")
---
 block/blk-mq.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block/blk-mq.c +6 -1
index a3a5fb4d4ef667..02a1f6e501ea8d 100644
@@ -4108,9 +4108,14 @@ EXPORT_SYMBOL(__blk_mq_alloc_disk);
 struct gendisk *blk_mq_alloc_disk_for_queue(struct request_queue *q,
 		struct lock_class_key *lkclass)
 {
+	struct gendisk *disk;
+
 	if (!blk_get_queue(q))
 		return NULL;
-	return __alloc_disk_node(q, NUMA_NO_NODE, lkclass);
+	disk = __alloc_disk_node(q, NUMA_NO_NODE, lkclass);
+	if (!disk)
+		blk_put_queue(q);
+	return disk;
 }
 EXPORT_SYMBOL(blk_mq_alloc_disk_for_queue);
 
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Applied
#2 lore raw
In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

Drop the disk reference just acquired when __alloc_disk_node failed.

Applied, thanks!

[1/1] blk-mq: fix queue reference leak on blk_mq_alloc_disk_for_queue failure

      commit: 22c17e279a1b03bad7987e4a4192b289b890f293

Best regards,

Signature · 1 line
Jens Axboe