Skip to contentSkip to conversation

gfs2: Set error on error path

PATCH In review Deepak R Varma 2 participants 3 messages Sep 29, 2023 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: Set error on error path

Set the error variable inside the error path on failure. Saves unnecessary variable assignment during normal execution.

---
 fs/gfs2/bmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/gfs2/bmap.c +3 -2
index ef7017fb6951..93bd8ea34444 100644
@@ -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);
Signature · 1 line
2.39.2
#1 lore raw
Quoted 13 lines · Deepak R Varma

Set the error variable inside the error path on failure. Saves unnecessary variable assignment during normal execution.

---
 fs/gfs2/bmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/gfs2/bmap.c +0 -0
index ef7017fb6951..93bd8ea34444 100644

fs/gfs2/bmap.c int gfs2_unstuff_dinode(struct gfs2_inode *ip) · line 168

Quoted 9 lines
fs/gfs2/bmap.c +3 -2
@@ -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

author
#2 lore raw
Quoted 19 lines · Dan Carpenter
Quoted 18 lines · Deepak R Varma

Set the error variable inside the error path on failure. Saves unnecessary variable assignment during normal execution.

---
 fs/gfs2/bmap.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
fs/gfs2/bmap.c +0 -0
index ef7017fb6951..93bd8ea34444 100644
@@ -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)

Quoted 9 lines
Quoted 4 lines

+       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.

Quoted 3 lines

regards,
dan carpenter