[PATCH RESEND] ext4: Fix exception handling in parse_apply_sb_mount_options()

From: Markus Elfring
Date: Tue Mar 04 2025 - 08:14:50 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 21 Mar 2023 22:33:06 +0100

The label “out_free” was used to jump to another pointer check
despite of the detail in the implementation of the function
“parse_apply_sb_mount_options” that it was determined already
that a corresponding variable contained a null pointer.

* Thus use an additional label.

* Delete a redundant check.


This issue was detected by using the Coccinelle software.

Fixes: 7edfd85b1ffd ("ext4: Completely separate options parsing and sb setup")
Fixes: c069db76ed7b ("ext4: fix memory leak in parse_apply_sb_mount_options()")
Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
fs/ext4/super.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e6d84c1e34a4..c0bc46956353 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2435,7 +2435,7 @@ static int parse_apply_sb_mount_options(struct super_block *sb,

fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL);
if (!fc)
- goto out_free;
+ goto free_mount_opts;

s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL);
if (!s_ctx)
@@ -2467,10 +2467,9 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
ret = 0;

out_free:
- if (fc) {
- ext4_fc_free(fc);
- kfree(fc);
- }
+ ext4_fc_free(fc);
+ kfree(fc);
+free_mount_opts:
kfree(s_mount_opts);
return ret;
}
--
2.40.0