[PATCH] fuse: drop redundant err assignment in fuse_create_open()

Li Wang posted 1 patch 2 months, 1 week ago
There is a newer version of this series
fs/fuse/dir.c | 1 -
1 file changed, 1 deletion(-)
[PATCH] fuse: drop redundant err assignment in fuse_create_open()
Posted by Li Wang 2 months, 1 week ago
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.

Signed-off-by: Li Wang <liwang@kylinos.cn>
---
 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index f7443ca37e35..b118cf23d41a 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -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
Re: [PATCH] fuse: drop redundant err assignment in fuse_create_open()
Posted by Joanne Koong 2 months ago
On Wed, Apr 8, 2026 at 8:06 PM Li Wang <liwang@kylinos.cn> wrote:
>
> 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).

Reviewed-by: Joanne Koong <joannelkoong@gmail.com>

Thanks,
Joanne

> but also makes the intended error semantics obvious: a single ENOMEM
> initialization covers both allocation failure exits that share
> this prelude.
>
> Signed-off-by: Li Wang <liwang@kylinos.cn>
> ---
>  fs/fuse/dir.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index f7443ca37e35..b118cf23d41a 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -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
>
>
[PATCH v2] fuse: drop redundant err assignment in fuse_create_open()
Posted by Li Wang 2 months ago
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.

Signed-off-by: Li Wang <liwang@kylinos.cn>
---
Changes since v1:
- Per review, removed the second paragraph of the commit message.


 fs/fuse/dir.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index f7443ca37e35..b118cf23d41a 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -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
Re: [PATCH v2] fuse: drop redundant err assignment in fuse_create_open()
Posted by Miklos Szeredi 1 month, 4 weeks ago
On Fri, 10 Apr 2026 at 04:35, Li Wang <liwang@kylinos.cn> wrote:
>
> 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.
>
> Signed-off-by: Li Wang <liwang@kylinos.cn>

Applied, thanks.

Miklos
Re: [PATCH v2] fuse: drop redundant err assignment in fuse_create_open()
Posted by Joanne Koong 2 months ago
On Thu, Apr 9, 2026 at 7:35 PM Li Wang <liwang@kylinos.cn> wrote:
>
> 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.
>
> Signed-off-by: Li Wang <liwang@kylinos.cn>

Reviewed-by: Joanne Koong <joannelkoong@gmail.com>

Thanks for making the change to the commit message.

> ---
> Changes since v1:
> - Per review, removed the second paragraph of the commit message.
>
>
>  fs/fuse/dir.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index f7443ca37e35..b118cf23d41a 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -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
>
>