[PATCH 2/3] fs: ext4fs: Use unwind goto to free memory on error

Andrew Goodbody andrew.goodbody at linaro.org
Fri Jul 4 14:32:43 CEST 2025


Ensure that allocated memory is freed on error exit replace the direct
return calls with 'goto fail'.

This issue found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
---
 fs/ext4/ext4_write.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index d109ed6e90d..dd8ed40f888 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -877,19 +877,19 @@ int ext4fs_write(const char *fname, const char *buffer,
 
 	if (ext4fs_init() != 0) {
 		printf("error in File System init\n");
-		return -1;
+		goto fail;
 	}
 
 	missing_feat = le32_to_cpu(fs->sb->feature_incompat) & ~EXT4_FEATURE_INCOMPAT_SUPP;
 	if (missing_feat) {
 		log_err("Unsupported features found %08x, not writing.\n", missing_feat);
-		return -1;
+		goto fail;
 	}
 
 	missing_feat = le32_to_cpu(fs->sb->feature_ro_compat) & ~EXT4_FEATURE_RO_COMPAT_SUPP;
 	if (missing_feat) {
 		log_err("Unsupported RO compat features found %08x, not writing.\n", missing_feat);
-		return -1;
+		goto fail;
 	}
 
 	inodes_per_block = fs->blksz / fs->inodesz;

-- 
2.39.5



More information about the U-Boot mailing list