LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH fs/ramfs] inode.c: Fix incorrect variable freeing.
@ 2010-06-20 19:27 Davidlohr Bueso
  2010-06-22 19:41 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Davidlohr Bueso @ 2010-06-20 19:27 UTC (permalink / raw
  To: linux-kernel; +Cc: linux-fsdevel

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 <dave@gnu.org>
---
 fs/ramfs/inode.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index a5ebae7..40af7a2 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -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,
-- 
1.7.0.4





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH fs/ramfs] inode.c: Fix incorrect variable freeing.
  2010-06-20 19:27 [PATCH fs/ramfs] inode.c: Fix incorrect variable freeing Davidlohr Bueso
@ 2010-06-22 19:41 ` Andrew Morton
  2010-06-23 13:20   ` Davidlohr Bueso
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2010-06-22 19:41 UTC (permalink / raw
  To: dave.bueso; +Cc: linux-kernel, linux-fsdevel

On Sun, 20 Jun 2010 15:27:37 -0400
Davidlohr Bueso <dave.bueso@gmail.com> 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 <dave@gnu.org>
> ---
>  fs/ramfs/inode.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
> index a5ebae7..40af7a2 100644
> --- a/fs/ramfs/inode.c
> +++ b/fs/ramfs/inode.c
> @@ -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,

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH fs/ramfs] inode.c: Fix incorrect variable freeing.
  2010-06-22 19:41 ` Andrew Morton
@ 2010-06-23 13:20   ` Davidlohr Bueso
  0 siblings, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2010-06-23 13:20 UTC (permalink / raw
  To: Andrew Morton; +Cc: linux-kernel, linux-fsdevel

On Tue, 2010-06-22 at 12:41 -0700, Andrew Morton wrote:
> On Sun, 20 Jun 2010 15:27:37 -0400
> Davidlohr Bueso <dave.bueso@gmail.com> 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 <dave@gnu.org>
> > ---
> >  fs/ramfs/inode.c |    8 +++++---
> >  1 files changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
> > index a5ebae7..40af7a2 100644
> > --- a/fs/ramfs/inode.c
> > +++ b/fs/ramfs/inode.c
> > @@ -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,
> 
> 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-23 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-20 19:27 [PATCH fs/ramfs] inode.c: Fix incorrect variable freeing Davidlohr Bueso
2010-06-22 19:41 ` Andrew Morton
2010-06-23 13:20   ` Davidlohr Bueso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).