Skip to contentSkip to conversation

fuse: drop redundant err assignment in fuse_create_open()

PATCH Superseded Li Wang 3 participants 5 messages Apr 9 – Apr 16

Subsystems (2)
lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 fuse: drop redundant err assignment in fuse_create_open()

In fuse_create_open(), err is initialized to -ENOMEM immediately before the fuse_alloc_forget() NULL check. If forget allocation fails, it branches to out_err with that value. If it succeeds, it falls through without modifying err, so err is still -ENOMEM at the point where fuse_file_alloc() is called. The second err = -ENOMEM before fuse_file_alloc() therefore is redundant.

Removing this redundant assignment not only improves performance but also makes the intended error semantics obvious: a single ENOMEM initialization covers both allocation failure exits that share this prelude.

---
 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)
fs/fuse/dir.c +0 -1
index f7443ca37e35..b118cf23d41a 100644
@@ -838,7 +838,6 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 	if (!forget)
 		goto out_err;
 
-	err = -ENOMEM;
 	ff = fuse_file_alloc(fm, true);
 	if (!ff)
 		goto out_put_forget_req;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Li Wang

In fuse_create_open(), err is initialized to -ENOMEM immediately before the fuse_alloc_forget() NULL check. If forget allocation fails, it branches to out_err with that value. If it succeeds, it falls through without modifying err, so err is still -ENOMEM at the point where fuse_file_alloc() is called. The second err = -ENOMEM before fuse_file_alloc() therefore is redundant.

Removing this redundant assignment not only improves performance

This LGTM but imo this line is inaccurate. Modern compilers (gcc/clang) will likely optimize away redundant assignments anyways. Even if it were not optimized away, the impact on performance is negligible. I think you could get rid of the second paragraph entirely, as you explain it clearly in the first paragraph already (eg the second err = -ENOMEM is redundant).

Thanks,
Joanne

Quoted 25 lines

but also makes the intended error semantics obvious: a single ENOMEM initialization covers both allocation failure exits that share this prelude.

---
 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)
fs/fuse/dir.c +0 -2
index f7443ca37e35..b118cf23d41a 100644
@@ -838,7 +838,6 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
        if (!forget)
                goto out_err;
 
-       err = -ENOMEM;
        ff = fuse_file_alloc(fm, true);
        if (!ff)
                goto out_put_forget_req;
--

2.34.1

author
#2 lore raw

PATCH v2 1/1 fuse: drop redundant err assignment in fuse_create_open()

In reply to Li Wang

In fuse_create_open(), err is initialized to -ENOMEM immediately before the fuse_alloc_forget() NULL check. If forget allocation fails, it branches to out_err with that value. If it succeeds, it falls through without modifying err, so err is still -ENOMEM at the point where fuse_file_alloc() is called. The second err = -ENOMEM before fuse_file_alloc() therefore is redundant.

---
Changes since v1:
- Per review, removed the second paragraph of the commit message.

 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)
fs/fuse/dir.c +0 -1
index f7443ca37e35..b118cf23d41a 100644
@@ -838,7 +838,6 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
 	if (!forget)
 		goto out_err;
 
-	err = -ENOMEM;
 	ff = fuse_file_alloc(fm, true);
 	if (!ff)
 		goto out_put_forget_req;
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 9 lines · Li Wang

In fuse_create_open(), err is initialized to -ENOMEM immediately before the fuse_alloc_forget() NULL check. If forget allocation fails, it branches to out_err with that value. If it succeeds, it falls through without modifying err, so err is still -ENOMEM at the point where fuse_file_alloc() is called. The second err = -ENOMEM before fuse_file_alloc() therefore is redundant.

Thanks for making the change to the commit message.

Quoted 24 lines

---
Changes since v1:
- Per review, removed the second paragraph of the commit message.

 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)
fs/fuse/dir.c +0 -2
index f7443ca37e35..b118cf23d41a 100644
@@ -838,7 +838,6 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir,
        if (!forget)
                goto out_err;
 
-       err = -ENOMEM;
        ff = fuse_file_alloc(fm, true);
        if (!ff)
                goto out_put_forget_req;
--

2.34.1

maintainer Applied
#4 lore raw
In reply to Li Wang
Quoted 9 lines · Li Wang

In fuse_create_open(), err is initialized to -ENOMEM immediately before the fuse_alloc_forget() NULL check. If forget allocation fails, it branches to out_err with that value. If it succeeds, it falls through without modifying err, so err is still -ENOMEM at the point where fuse_file_alloc() is called. The second err = -ENOMEM before fuse_file_alloc() therefore is redundant.

Applied, thanks.

Miklos