Under memory pressure, bio_alloc_bioset() may fail and return NULL,
which could lead to a NULL pointer dereference in the zone GC code.
Add proper error handling to prevent this scenario by checking the
return value and cleaning up resources appropriately.
Signed-off-by: Ye Chey <yechey@ai-sast.com>
---
fs/xfs/xfs_zone_gc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
index d613a4094..ec87b5d6b 100644
--- a/fs/xfs/xfs_zone_gc.c
+++ b/fs/xfs/xfs_zone_gc.c
@@ -697,6 +697,11 @@ xfs_zone_gc_start_chunk(
}
bio = bio_alloc_bioset(bdev, 1, REQ_OP_READ, GFP_NOFS, &data->bio_set);
+ if (!bio) {
+ xfs_irele(ip);
+ xfs_open_zone_put(oz);
+ return false;
+ }
chunk = container_of(bio, struct xfs_gc_bio, bio);
chunk->ip = ip;
--
2.44.0