Skip to contentSkip to conversation

xfs: fix memory leak on error in xfs_alloc_zone_info()

PATCH Applied Wilfred Mallawa 5 participants 5 messages Apr 14 – Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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 the 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 v2 1/1
#1 lore raw
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 the 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")
Cc <[email protected]> # v6.15

(autobackport plz, I need all the help I can get)

Quoted 12 lines
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +0 -0
index a851b98143c0..c64f9ab743a6 100644

fs/xfs/xfs_zone_alloc.c xfs_alloc_zone_info( · line 1220

Quoted 5 lines
fs/xfs/xfs_zone_alloc.c +1 -1
@@ -1217,7 +1217,7 @@ xfs_alloc_zone_info(
 	return zi;
 
 out_free_bitmaps:
-	while (--i > 0)
+	while (--i >= 0)

With the git trailer amended,

--D

Quoted 7 lines
fs/xfs/xfs_zone_alloc.c +0 -0
 		kvfree(zi->zi_used_bucket_bitmap[i]);
 	kfree(zi);
 	return NULL;
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#3 lore raw
In reply to Wilfred Mallawa
Quoted 21 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 the 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 +0 -0
index a851b98143c0..c64f9ab743a6 100644

fs/xfs/xfs_zone_alloc.c xfs_alloc_zone_info( · line 1223

Quoted 8 lines
fs/xfs/xfs_zone_alloc.c +1 -1
@@ -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;

Thanks!

maintainer Applied
#4 lore raw
In reply to Wilfred Mallawa
Quoted 6 lines · Wilfred Mallawa

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 the while loop used in xfs_alloc_zone_info(). Fix it by allowing for the i == 0 case to be covered.

Applied to for-next, thanks!

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

      commit: 592975da8c3ca87b043077e6eafa37665eae7936

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>