Skip to contentSkip to conversation

ext2: super: remove unnecessary goto statement

PATCH In review Seunghun Lee 2 participants 2 messages May 7, 2014 – May 12, 2014 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: super: remove unnecessary goto statement

This patch removes unnecessary goto failed,
and moves kfree to failed.

---
 fs/ext2/super.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/ext2/super.c +4 -6
index 3750031..7d20a50 100644
@@ -777,17 +777,15 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	__le32 features;
 	int err;
 
-	err = -ENOMEM;
 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
 	if (!sbi)
-		goto failed;
+		return -ENOMEM;
 
 	sbi->s_blockgroup_lock =
 		kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
-	if (!sbi->s_blockgroup_lock) {
-		kfree(sbi);
+	if (!sbi->s_blockgroup_lock)
 		goto failed;
-	}
+
 	sb->s_fs_info = sbi;
 	sbi->s_sb_block = sb_block;
 
@@ -1138,8 +1136,8 @@ failed_mount:
 failed_sbi:
 	sb->s_fs_info = NULL;
 	kfree(sbi->s_blockgroup_lock);
-	kfree(sbi);
 failed:
+	kfree(sbi);
 	return ret;
 }
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 20 lines · Seunghun Lee

Date: Thu, 8 May 2014 01:08:03 +0900
From: Seunghun Lee <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Seunghun Lee <[email protected]>
Subject: [PATCH] ext2: super: remove unnecessary goto statement

This patch removes unnecessary goto failed,
and moves kfree to failed.

---
 fs/ext2/super.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/ext2/super.c +0 -0
index 3750031..7d20a50 100644

fs/ext2/super.c static int ext2_fill_super(struct super_block *sb, void *data, int silent) · line 780

Quoted 4 lines
fs/ext2/super.c +0 -1
@@ -777,17 +777,15 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	__le32 features;
 	int err;
 
-	err = -ENOMEM;

The problem here is actually that we return -EINVAL while we should actually return -ENOMEM, which is fixed only partially by your patch.

Also there are number other problems in error handling here mainly because we're using err variable but not setting ret variable which is the one that we return eventually.

Also ret is defined as long (not sure if that's needed) but the function is supposed to return int.

So if you're changing the code around it would be good to actually fix some problems as well :)

Thanks!
-Lukas

Quoted 27 lines
fs/ext2/super.c +4 -5
 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
 	if (!sbi)
-		goto failed;
+		return -ENOMEM;
 
 	sbi->s_blockgroup_lock =
 		kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
-	if (!sbi->s_blockgroup_lock) {
-		kfree(sbi);
+	if (!sbi->s_blockgroup_lock)
 		goto failed;
-	}
+
 	sb->s_fs_info = sbi;
 	sbi->s_sb_block = sb_block;
 
@@ -1138,8 +1136,8 @@ failed_mount:
 failed_sbi:
 	sb->s_fs_info = NULL;
 	kfree(sbi->s_blockgroup_lock);
-	kfree(sbi);
 failed:
+	kfree(sbi);
 	return ret;
 }