[PATCH] gfs2: Set error on error path

Deepak R Varma posted 1 patch 2 years, 2 months ago
fs/gfs2/bmap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] gfs2: Set error on error path
Posted by Deepak R Varma 2 years, 2 months ago
Set the error variable inside the error path on failure. Saves
unnecessary variable assignment during normal execution.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 fs/gfs2/bmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index ef7017fb6951..93bd8ea34444 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -162,9 +162,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip)
 
 	down_write(&ip->i_rw_mutex);
 	page = grab_cache_page(inode->i_mapping, 0);
-	error = -ENOMEM;
-	if (!page)
+	if (!page) {
+		error = -ENOMEM;
 		goto out;
+	}
 	error = __gfs2_unstuff_inode(ip, page);
 	unlock_page(page);
 	put_page(page);
-- 
2.39.2
Re: [PATCH] gfs2: Set error on error path
Posted by Dan Carpenter 2 years, 2 months ago
On Fri, Sep 29, 2023 at 11:44:40AM +0530, Deepak R Varma wrote:
> Set the error variable inside the error path on failure. Saves
> unnecessary variable assignment during normal execution.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>  fs/gfs2/bmap.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
> index ef7017fb6951..93bd8ea34444 100644
> --- a/fs/gfs2/bmap.c
> +++ b/fs/gfs2/bmap.c
> @@ -162,9 +162,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip)
>  
>  	down_write(&ip->i_rw_mutex);
>  	page = grab_cache_page(inode->i_mapping, 0);
> -	error = -ENOMEM;
> -	if (!page)
> +	if (!page) {
> +		error = -ENOMEM;
>  		goto out;
> +	}

It used to be that the other way was faster?  I'm pretty sure the
compiler can figure it out these days.  Please don't randomly start
changing people's prefered style unless it's drivers/staging/ code.

regards,
dan carpenter
Re: [PATCH] gfs2: Set error on error path
Posted by drv 2 years, 2 months ago
On Fri, 2023-09-29 at 10:14 +0300, Dan Carpenter wrote:
> On Fri, Sep 29, 2023 at 11:44:40AM +0530, Deepak R Varma wrote:
> > Set the error variable inside the error path on failure. Saves
> > unnecessary variable assignment during normal execution.
> > 
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > ---
> >  fs/gfs2/bmap.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
> > index ef7017fb6951..93bd8ea34444 100644
> > --- a/fs/gfs2/bmap.c
> > +++ b/fs/gfs2/bmap.c
> > @@ -162,9 +162,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip)
> >  
> >         down_write(&ip->i_rw_mutex);
> >         page = grab_cache_page(inode->i_mapping, 0);
> > -       error = -ENOMEM;
> > -       if (!page)
> > +       if (!page) {
> > +               error = -ENOMEM;
> >                 goto out;
> > +       }
> 
> It used to be that the other way was faster?  I'm pretty sure the
> compiler can figure it out these days.  Please don't randomly start
> changing people's prefered style unless it's drivers/staging/ code.
> 
Hi Dan,
Thank you for the feedback. I did not know about the compiler
optimization resulting in original code being faster.
I will let the maintainers comment on breaking the style.

regards,
deepak.

> regards,
> dan carpenter
>