Skip to contentSkip to conversation

xfs: fix memory leak on error in xfs_alloc_zone_info()

PATCH Superseded Wilfred Mallawa 3 participants 3 messages Apr 14

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix memory leak on error in xfs_alloc_zone_info()

From: Wilfred Mallawa <[email protected]>

Currently, the 0th index of the zi_used_bucket_bitmap array is not freed on error due to the pre-decrement then evaluate semantic of this while loop used in xfs_alloc_zone_info(). Fix it by allowing for the i == 0 case to be covered.

Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +1 -1
index a851b98143c0..c64f9ab743a6 100644
@@ -1217,7 +1217,7 @@ xfs_alloc_zone_info(
 	return zi;
 
 out_free_bitmaps:
-	while (--i > 0)
+	while (--i >= 0)
 		kvfree(zi->zi_used_bucket_bitmap[i]);
 	kfree(zi);
 	return NULL;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Wilfred Mallawa

From: Wilfred Mallawa <[email protected]>

Currently, the 0th index of the zi_used_bucket_bitmap array is not freed on error due to the pre-decrement then evaluate semantic of this while loop used

s/this/the

Quoted 1 line

in xfs_alloc_zone_info(). Fix it by allowing for the i == 0 case to be covered.

Please limit your commit message text to 74 chars per line.
(See Documentation/process/submitting-patches.rst, "The canonical patch format" section).

Quoted 1 line

I think that the usual order here is to have the Fixes and CC tag before your signed-off-by.

Quoted 2 lines
Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")

Other than this, looks good to me.

Quoted 17 lines
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +1 -1
index a851b98143c0..c64f9ab743a6 100644
@@ -1217,7 +1217,7 @@ xfs_alloc_zone_info(
 	return zi;
 
 out_free_bitmaps:
-	while (--i > 0)
+	while (--i >= 0)
 		kvfree(zi->zi_used_bucket_bitmap[i]);
 	kfree(zi);
 	return NULL;
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Wilfred Mallawa
Quoted 9 lines · Wilfred Mallawa

From: Wilfred Mallawa <[email protected]>

Currently, the 0th index of the zi_used_bucket_bitmap array is not freed on error due to the pre-decrement then evaluate semantic of this while loop used in xfs_alloc_zone_info(). Fix it by allowing for the i == 0 case to be covered.

Fixes 080d01c41d44 ("xfs: implement zoned garbage collection")

Code looks good.

After fixing Damien's suggestions, feel free to add:

Quoted 21 lines
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +1 -1
index a851b98143c0..c64f9ab743a6 100644
@@ -1217,7 +1217,7 @@ xfs_alloc_zone_info(
 	return zi;
 
 out_free_bitmaps:
-	while (--i > 0)
+	while (--i >= 0)
 		kvfree(zi->zi_used_bucket_bitmap[i]);
 	kfree(zi);
 	return NULL;
Signature · 1 line
2.53.0