[PATCH] erofs-utils: lib: fix wrong NULL check after erofs_balloc() in metabox
Utkal Singh
singhutkal015 at gmail.com
Mon Mar 16 03:02:16 AEDT 2026
erofs_balloc() returns an error pointer via ERR_PTR(-errno) on failure,
never NULL. The previous check:
if (!bh)
fails to detect error pointers since ERR_PTR encodes errors as non-zero
pointers near ULONG_MAX. This causes PTR_ERR(bh) on the next line to be
unreachable, and the subsequent erofs_mapbh() call to receive an invalid
pointer, potentially causing a crash or silent memory corruption.
Replace with the correct IS_ERR() pattern which properly detects all
error pointer values returned by erofs_balloc().
Fixes: 7928074b7643 ("erofs-utils: introduce metadata compression [metabox]")
Signed-off-by: Utkal Singh <utkalsingh059 at gmail.com>
---
lib/metabox.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/metabox.c b/lib/metabox.c
index d6abd51..12706aa 100644
--- a/lib/metabox.c
+++ b/lib/metabox.c
@@ -127,7 +127,7 @@ int erofs_metazone_flush(struct erofs_sb_info *sbi)
if (!m2gr)
return 0;
bh = erofs_balloc(sbi->bmgr, DATA, 0, 0);
- if (!bh)
+ if (IS_ERR(bh))
return PTR_ERR(bh);
erofs_mapbh(NULL, bh->block);
pos_out = erofs_btell(bh, false);
--
2.43.0
More information about the Linux-erofs
mailing list