Skip to contentSkip to conversation

reiserfs: kstrdup() memory handling

PATCH In review Sanidhya Kashyap 2 participants 4 messages Mar 21, 2015 – Mar 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reiserfs: kstrdup() memory handling

Checking for ENOMEM even for new_opts in reiserfs_remount function as there is a possibility of nothing being allocated.

---
 fs/reiserfs/super.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/reiserfs/super.c +6 -0
index 71fbbe3..bf9bc66 100644
@@ -1397,6 +1397,11 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
 	int i;
 #endif
 
+	if (!new_opts) {
+		err = -ENOMEM;
+		goto out_err_no_kfree;
+	}
+
 	sync_filesystem(s);
 	reiserfs_write_lock(s);
 
@@ -1549,6 +1554,7 @@ out_err_unlock:
 	reiserfs_write_unlock(s);
 out_err:
 	kfree(new_opts);
+out_err_no_kfree:
 	return err;
 }
 
Signature · 1 line
2.1.0
#1 lore raw
Quoted 2 lines · Sanidhya Kashyap

Checking for ENOMEM even for new_opts in reiserfs_remount function as there is a possibility of nothing being allocated.

You don't need to add a new label; kfree(NULL) is a no-op.

Quoted 32 lines
---
 fs/reiserfs/super.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/reiserfs/super.c +6 -0
index 71fbbe3..bf9bc66 100644
@@ -1397,6 +1397,11 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
 	int i;
 #endif
 
+	if (!new_opts) {
+		err = -ENOMEM;
+		goto out_err_no_kfree;
+	}
+
 	sync_filesystem(s);
 	reiserfs_write_lock(s);
 
@@ -1549,6 +1554,7 @@ out_err_unlock:
 	reiserfs_write_unlock(s);
 out_err:
 	kfree(new_opts);
+out_err_no_kfree:
 	return err;
 }
 
Signature · 1 line
2.1.0
#2 lore raw
Quoted 6 lines · Josh Triplett
Quoted 2 lines · Sanidhya Kashyap

Checking for ENOMEM even for new_opts in reiserfs_remount function as there is a possibility of nothing being allocated.

You don't need to add a new label; kfree(NULL) is a no-op.

Shall I resubmit the patch?

Thanks,
Sanidhya

Quoted 32 lines
Quoted 32 lines
---
 fs/reiserfs/super.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/reiserfs/super.c +6 -1
index 71fbbe3..bf9bc66 100644
@@ -1397,6 +1397,11 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
      int i;
 #endif
 
+     if (!new_opts) {
+             err = -ENOMEM;
+             goto out_err_no_kfree;
+     }
+
      sync_filesystem(s);
      reiserfs_write_lock(s);
 
@@ -1549,6 +1554,7 @@ out_err_unlock:
      reiserfs_write_unlock(s);
 out_err:
      kfree(new_opts);
+out_err_no_kfree:
      return err;
 }
 
--

2.1.0

#3 lore raw
Quoted 9 lines · Sanidhya Kashyap
Quoted 6 lines · Josh Triplett
Quoted 2 lines · Sanidhya Kashyap

Checking for ENOMEM even for new_opts in reiserfs_remount function as there is a possibility of nothing being allocated.

You don't need to add a new label; kfree(NULL) is a no-op.

Shall I resubmit the patch?

I would suggest doing so, yes, after you see if anyone else has feedback on it.

- Josh Triplett