All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efivarfs: Eliminate dead code in efivarfs_create()
@ 2016-02-23 16:07 Tobias Klauser
       [not found] ` <1456243630-24834-1-git-send-email-tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Klauser @ 2016-02-23 16:07 UTC (permalink / raw)
  To: Matthew Garrett, Jeremy Kerr, Matt Fleming
  Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA

After commit ed8b0de5a33d ("efi: Make efivarfs entries immutable by
default"), inode will always be NULL in the error check before iput(),
thus remove the check and the call to iput() alltogether. Also directly
fold the error handling code into the only place it is needed, which
makes the code a bit smaller.

Found by the Coverity scanner (CID 1353443).

Signed-off-by: Tobias Klauser <tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
---
 fs/efivarfs/inode.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
index e2ab6d0497f2..43321c9cd71b 100644
--- a/fs/efivarfs/inode.c
+++ b/fs/efivarfs/inode.c
@@ -106,7 +106,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
 {
 	struct inode *inode = NULL;
 	struct efivar_entry *var;
-	int namelen, i = 0, err = 0;
+	int namelen, i = 0;
 	bool is_removable = false;
 
 	if (!efivarfs_valid_name(dentry->d_name.name, dentry->d_name.len))
@@ -128,8 +128,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
 
 	inode = efivarfs_get_inode(dir->i_sb, dir, mode, 0, is_removable);
 	if (!inode) {
-		err = -ENOMEM;
-		goto out;
+		kfree(var);
+		return -ENOMEM;
 	}
 
 	for (i = 0; i < namelen; i++)
@@ -142,13 +142,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
 	efivar_entry_add(var, &efivarfs_list);
 	d_instantiate(dentry, inode);
 	dget(dentry);
-out:
-	if (err) {
-		kfree(var);
-		if (inode)
-			iput(inode);
-	}
-	return err;
+
+	return 0;
 }
 
 static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
-- 
2.7.0.297.g563e384

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

* Re: [PATCH] efivarfs: Eliminate dead code in efivarfs_create()
       [not found] ` <1456243630-24834-1-git-send-email-tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
@ 2016-02-24 16:47   ` Matt Fleming
       [not found]     ` <20160224164734.GC2603-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Fleming @ 2016-02-24 16:47 UTC (permalink / raw)
  To: Tobias Klauser
  Cc: Matthew Garrett, Jeremy Kerr, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	Peter Jones

On Tue, 23 Feb, at 05:07:10PM, Tobias Klauser wrote:
> After commit ed8b0de5a33d ("efi: Make efivarfs entries immutable by
> default"), inode will always be NULL in the error check before iput(),
> thus remove the check and the call to iput() alltogether. Also directly
> fold the error handling code into the only place it is needed, which
> makes the code a bit smaller.
> 
> Found by the Coverity scanner (CID 1353443).
> 
> Signed-off-by: Tobias Klauser <tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
> ---
>  fs/efivarfs/inode.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
> index e2ab6d0497f2..43321c9cd71b 100644
> --- a/fs/efivarfs/inode.c
> +++ b/fs/efivarfs/inode.c
> @@ -106,7 +106,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
>  {
>  	struct inode *inode = NULL;
>  	struct efivar_entry *var;
> -	int namelen, i = 0, err = 0;
> +	int namelen, i = 0;
>  	bool is_removable = false;
>  
>  	if (!efivarfs_valid_name(dentry->d_name.name, dentry->d_name.len))
> @@ -128,8 +128,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
>  
>  	inode = efivarfs_get_inode(dir->i_sb, dir, mode, 0, is_removable);
>  	if (!inode) {
> -		err = -ENOMEM;
> -		goto out;
> +		kfree(var);
> +		return -ENOMEM;
>  	}
>  
>  	for (i = 0; i < namelen; i++)
> @@ -142,13 +142,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
>  	efivar_entry_add(var, &efivarfs_list);
>  	d_instantiate(dentry, inode);
>  	dget(dentry);
> -out:
> -	if (err) {
> -		kfree(var);
> -		if (inode)
> -			iput(inode);
> -	}
> -	return err;
> +
> +	return 0;
>  }
>  
>  static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)

Looks good to me. Thanks, applied!

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

* Re: [PATCH] efivarfs: Eliminate dead code in efivarfs_create()
       [not found]     ` <20160224164734.GC2603-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
@ 2016-07-19 11:06       ` Tobias Klauser
       [not found]         ` <20160719110614.GA23998-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Klauser @ 2016-07-19 11:06 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Matthew Garrett, Jeremy Kerr, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	Peter Jones

On 2016-02-24 at 17:47:34 +0100, Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> wrote:
> On Tue, 23 Feb, at 05:07:10PM, Tobias Klauser wrote:
> > After commit ed8b0de5a33d ("efi: Make efivarfs entries immutable by
> > default"), inode will always be NULL in the error check before iput(),
> > thus remove the check and the call to iput() alltogether. Also directly
> > fold the error handling code into the only place it is needed, which
> > makes the code a bit smaller.
> > 
> > Found by the Coverity scanner (CID 1353443).
> > 
> > Signed-off-by: Tobias Klauser <tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
> > ---
> >  fs/efivarfs/inode.c | 15 +++++----------
> >  1 file changed, 5 insertions(+), 10 deletions(-)
> > 
> > diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
> > index e2ab6d0497f2..43321c9cd71b 100644
> > --- a/fs/efivarfs/inode.c
> > +++ b/fs/efivarfs/inode.c
> > @@ -106,7 +106,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
> >  {
> >  	struct inode *inode = NULL;
> >  	struct efivar_entry *var;
> > -	int namelen, i = 0, err = 0;
> > +	int namelen, i = 0;
> >  	bool is_removable = false;
> >  
> >  	if (!efivarfs_valid_name(dentry->d_name.name, dentry->d_name.len))
> > @@ -128,8 +128,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
> >  
> >  	inode = efivarfs_get_inode(dir->i_sb, dir, mode, 0, is_removable);
> >  	if (!inode) {
> > -		err = -ENOMEM;
> > -		goto out;
> > +		kfree(var);
> > +		return -ENOMEM;
> >  	}
> >  
> >  	for (i = 0; i < namelen; i++)
> > @@ -142,13 +142,8 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry,
> >  	efivar_entry_add(var, &efivarfs_list);
> >  	d_instantiate(dentry, inode);
> >  	dget(dentry);
> > -out:
> > -	if (err) {
> > -		kfree(var);
> > -		if (inode)
> > -			iput(inode);
> > -	}
> > -	return err;
> > +
> > +	return 0;
> >  }
> >  
> >  static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
> 
> Looks good to me. Thanks, applied!

Ping, this doesn't seem to have made it into Linus' tree, linux-next or
your publicly accessible tree yet. It seems the patch still applies, or
should I resubmit it?

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

* Re: [PATCH] efivarfs: Eliminate dead code in efivarfs_create()
       [not found]         ` <20160719110614.GA23998-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
@ 2016-07-21 11:28           ` Matt Fleming
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Fleming @ 2016-07-21 11:28 UTC (permalink / raw)
  To: Tobias Klauser
  Cc: Matthew Garrett, Jeremy Kerr, linux-efi-u79uwXL29TY76Z2rM5mHXA,
	Peter Jones

On Tue, 19 Jul, at 01:06:14PM, Tobias Klauser wrote:
> 
> Ping, this doesn't seem to have made it into Linus' tree, linux-next or
> your publicly accessible tree yet. It seems the patch still applies, or
> should I resubmit it?

Sorry about that, I've no idea what happened to this patch. I've
queued this up for v4.9 now, no need to resubmit.

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

end of thread, other threads:[~2016-07-21 11:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-23 16:07 [PATCH] efivarfs: Eliminate dead code in efivarfs_create() Tobias Klauser
     [not found] ` <1456243630-24834-1-git-send-email-tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
2016-02-24 16:47   ` Matt Fleming
     [not found]     ` <20160224164734.GC2603-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-07-19 11:06       ` Tobias Klauser
     [not found]         ` <20160719110614.GA23998-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
2016-07-21 11:28           ` Matt Fleming

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.