public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] block: fix zones_cond memory leak on zone revalidation error paths
@ 2026-03-31 11:12 Jackie Liu
  2026-03-31 13:07 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Jackie Liu @ 2026-03-31 11:12 UTC (permalink / raw)
  To: dlemoal, axboe; +Cc: linux-block

From: Jackie Liu <liuyun01@kylinos.cn>

When blk_revalidate_disk_zones() fails after disk_revalidate_zone_resources()
has allocated args.zones_cond, the memory is leaked because no error path
frees it.

Fixes: 6e945ffb6555 ("block: use zone condition to determine conventional zones")
Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/blk-zoned.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 9d1dd6ccfad7..42b9a10138c3 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1910,6 +1910,7 @@ static int disk_revalidate_zone_resources(struct gendisk *disk,
 {
 	struct queue_limits *lim = &disk->queue->limits;
 	unsigned int pool_size;
+	int ret = 0;
 
 	args->disk = disk;
 	args->nr_zones =
@@ -1932,10 +1933,13 @@ static int disk_revalidate_zone_resources(struct gendisk *disk,
 		pool_size =
 			min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, args->nr_zones);
 
-	if (!disk->zone_wplugs_hash)
-		return disk_alloc_zone_resources(disk, pool_size);
+	if (!disk->zone_wplugs_hash) {
+		ret = disk_alloc_zone_resources(disk, pool_size);
+		if (ret)
+			kfree(args->zones_cond);
+	}
 
-	return 0;
+	return ret;
 }
 
 /*
@@ -1967,6 +1971,7 @@ static int disk_update_zone_resources(struct gendisk *disk,
 	disk->zone_capacity = args->zone_capacity;
 	disk->last_zone_capacity = args->last_zone_capacity;
 	disk_set_zones_cond_array(disk, args->zones_cond);
+	args->zones_cond = NULL;
 
 	/*
 	 * Some devices can advertise zone resource limits that are larger than
@@ -2249,21 +2254,30 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
 	}
 	memalloc_noio_restore(noio_flag);
 
+	if (ret <= 0)
+		goto free_resources;
+
 	/*
 	 * If zones where reported, make sure that the entire disk capacity
 	 * has been checked.
 	 */
-	if (ret > 0 && args.sector != capacity) {
+	if (args.sector != capacity) {
 		pr_warn("%s: Missing zones from sector %llu\n",
 			disk->disk_name, args.sector);
 		ret = -ENODEV;
+		goto free_resources;
 	}
 
-	if (ret > 0)
-		return disk_update_zone_resources(disk, &args);
+	ret = disk_update_zone_resources(disk, &args);
+	if (ret)
+		goto free_resources;
+
+	return 0;
 
+free_resources:
 	pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
 
+	kfree(args.zones_cond);
 	memflags = blk_mq_freeze_queue(q);
 	disk_free_zone_resources(disk);
 	blk_mq_unfreeze_queue(q, memflags);
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] block: fix zones_cond memory leak on zone revalidation error paths
  2026-03-31 11:12 [PATCH v3] block: fix zones_cond memory leak on zone revalidation error paths Jackie Liu
@ 2026-03-31 13:07 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2026-03-31 13:07 UTC (permalink / raw)
  To: dlemoal, Jackie Liu; +Cc: linux-block


On Tue, 31 Mar 2026 19:12:16 +0800, Jackie Liu wrote:
> When blk_revalidate_disk_zones() fails after disk_revalidate_zone_resources()
> has allocated args.zones_cond, the memory is leaked because no error path
> frees it.

Applied, thanks!

[1/1] block: fix zones_cond memory leak on zone revalidation error paths
      commit: 2a2f520fda824b5a25c93f2249578ea150c24e06

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-31 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 11:12 [PATCH v3] block: fix zones_cond memory leak on zone revalidation error paths Jackie Liu
2026-03-31 13:07 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox