Skip to contentSkip to conversation

fuse: drop redundant err assignments in fuse_dev_do_write()

PATCH In review Li Wang 3 participants 3 messages Jul 8 – Jul 17

Subsystems (2)
lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 fuse: drop redundant err assignments in fuse_dev_do_write()

After fuse_copy_one() succeeds, err is set to -EINVAL before validating oh.len. When oh.len equals nbytes, err is already -EINVAL, so the extra assignments before the notification and oh.error checks are redundant.

---
 fs/fuse/dev.c | 2 --
 1 file changed, 2 deletions(-)
fs/fuse/dev.c +0 -2
index 5763a7cd3b37..7813f6214d0e 100644
@@ -1887,7 +1887,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
 		 * Only allow notifications during while the connection is in an
 		 * initialized and connected state
 		 */
-		err = -EINVAL;
 		if (!fch->initialized || !fch->connected)
 			goto copy_finish;
 
@@ -1898,7 +1897,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
 		goto copy_finish;
 	}
 
-	err = -EINVAL;
 	if (oh.error <= -512 || oh.error > 0)
 		goto copy_finish;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Li Wang

After fuse_copy_one() succeeds, err is set to -EINVAL before validating oh.len. When oh.len equals nbytes, err is already -EINVAL, so the extra assignments before the notification and oh.error checks are redundant.

---
 fs/fuse/dev.c | 2 --
 1 file changed, 2 deletions(-)
fs/fuse/dev.c +0 -1
index 5763a7cd3b37..7813f6214d0e 100644
@@ -1887,7 +1887,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
                 * Only allow notifications during while the connection is in an
                 * initialized and connected state
                 */
-               err = -EINVAL;
                if (!fch->initialized || !fch->connected)
                        goto copy_finish;
 

fs/fuse/dev.c static ssize_t fuse_dev_do_write(struct fuse_dev *fud, · line 1902

Quoted 7 lines
fs/fuse/dev.c +0 -1
@@ -1898,7 +1897,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
                goto copy_finish;
        }
 
-       err = -EINVAL;
        if (oh.error <= -512 || oh.error > 0)
                goto copy_finish;
 
maintainer
#2 lore raw
In reply to Li Wang
Quoted 15 lines · Li Wang

After fuse_copy_one() succeeds, err is set to -EINVAL before validating oh.len. When oh.len equals nbytes, err is already -EINVAL, so the extra assignments before the notification and oh.error checks are redundant.

---
 fs/fuse/dev.c | 2 --
 1 file changed, 2 deletions(-)
fs/fuse/dev.c +0 -0
index 5763a7cd3b37..7813f6214d0e 100644

fs/fuse/dev.c static ssize_t fuse_dev_do_write(struct fuse_dev *fud, · line 1891

Quoted 6 lines
fs/fuse/dev.c +0 -1
@@ -1887,7 +1887,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
                 * Only allow notifications during while the connection is in an
                 * initialized and connected state
                 */
-               err = -EINVAL;
                if (!fch->initialized || !fch->connected)
                        goto copy_finish;

Sorry, I won't apply this. It's neither an optimization (the compiler will remove the assignment) nor makes the code more readable (moves the error value further from where the error happens).

If we have a series of error conditions with the same error values, then omitting the "err = ..." each time is valid, but this time there's definite documentation value in redoing the assignment.

Thanks,
Miklos