inode.c: Fix incorrect variable freeing.
PATCH 1/1 inode.c: Fix incorrect variable freeing.
Hi,
In ramfs_fill_super(), if fsi's memory allocation fails, it will go to 'fail', which immediately tries to free the variable, potentially producing an Oops. This patch addresses this issue.
Thanks.
--- fs/ramfs/inode.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
fs/ramfs/inode.c +5 -3
@@ -219,7 +219,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; - goto fail; + goto fail2; } err =ramfs_parse_options (data, &fsi->mount_opts);
@@ -247,11 +247,13 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) }return 0 ; -fail: -kfree (fsi); +fail2: sb->s_fs_info =NULL ;iput (inode);return err; +fail: +kfree (fsi); + goto fail2; } int ramfs_get_sb(struct file_system_type *fs_type,
Signature · 1 line
1.7.0.4
Quoted 32 lines · On Sun, 20 Jun 2010 15:27:37 -0400 Davidlohr Bueso <[email protected]> wrote:
Hi,
In
ramfs_fill_super(), if fsi's memory allocation fails, it will go to 'fail', which immediately tries to free the variable, potentially producing an Oops. This patch addresses this issue.Thanks.
Signed-off-by Davidlohr Bueso <[email protected]>--- fs/ramfs/inode.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)fs/ramfs/inode.c +1
-3@@ -219,7 +219,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; - goto fail; + goto fail2; } err =ramfs_parse_options (data, &fsi->mount_opts);@@ -247,11 +247,13 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) }return 0 ; -fail: -kfree (fsi);
fs/ramfs/inode.c int ramfs_fill_super(struct super_block *sb, void *data, int silent) · line 259
Quoted 10 lines
fs/ramfs/inode.c +4
-0+fail2: sb->s_fs_info =NULL ;iput (inode);return err; +fail: +kfree (fsi); + goto fail2; } int ramfs_get_sb(struct file_system_type *fs_type,
notabug. kfree(NULL) is an OK thing to do. The kernel does this pretty regularly in recovery paths - it usually results in slightly simpler and slightly smaller code.
Quoted 44 lines · Andrew Morton
Quoted 41 lines · On Sun, 20 Jun 2010 15:27:37 -0400 Davidlohr Bueso <[email protected]> wrote:
Hi,
In
ramfs_fill_super(), if fsi's memory allocation fails, it will go to 'fail', which immediately tries to free the variable, potentially producing an Oops. This patch addresses this issue.Thanks.
Signed-off-by Davidlohr Bueso <[email protected]>--- fs/ramfs/inode.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)fs/ramfs/inode.c +5
-3@@ -219,7 +219,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; - goto fail; + goto fail2; } err =ramfs_parse_options (data, &fsi->mount_opts);@@ -247,11 +247,13 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) }return 0 ; -fail: -kfree (fsi); +fail2: sb->s_fs_info =NULL ;iput (inode);return err; +fail: +kfree (fsi); + goto fail2; }
Quoted 5 lines
fs/ramfs/inode.c int ramfs_fill_super(struct super_block *sb, void *data, int silent) · line 259
Quoted 1 line
fs/ramfs/inode.c +0
-0int ramfs_get_sb(struct file_system_type *fs_type,notabug. kfree(NULL) is an OK thing to do. The kernel does this pretty regularly in recovery paths - it usually results in slightly simpler and slightly smaller code.
Yeah I kind of knew that but slipped my mind. Sorry for the noise.