diff mbox series

[next,V2] xattr: remove redundant check on variable err

Message ID 20241030182547.3103729-1-colin.i.king@gmail.com (mailing list archive)
State New
Headers show
Series [next,V2] xattr: remove redundant check on variable err | expand

Commit Message

Colin Ian King Oct. 30, 2024, 6:25 p.m. UTC
Curretly in function generic_listxattr the for_each_xattr_handler loop
checks err and will return out of the function if err is non-zero.
It's impossible for err to be non-zero at the end of the function where
err is checked again for a non-zero value. The final non-zero check is
therefore redundant and can be removed. Also move the declaration of
err into the loop.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
V2: Move declaration of err into the loop as per Al Viro's suggestion
---
 fs/xattr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Al Viro Oct. 31, 2024, 6:43 a.m. UTC | #1
On Wed, Oct 30, 2024 at 06:25:47PM +0000, Colin Ian King wrote:
> Curretly in function generic_listxattr the for_each_xattr_handler loop
> checks err and will return out of the function if err is non-zero.
> It's impossible for err to be non-zero at the end of the function where
> err is checked again for a non-zero value. The final non-zero check is
> therefore redundant and can be removed. Also move the declaration of
> err into the loop.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

Applied (viro/vfs.git #work.xattr2)
diff mbox series

Patch

diff --git a/fs/xattr.c b/fs/xattr.c
index 05ec7e7d9e87..fd4e3ab8034d 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -1005,9 +1005,10 @@  generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 {
 	const struct xattr_handler *handler, * const *handlers = dentry->d_sb->s_xattr;
 	ssize_t remaining_size = buffer_size;
-	int err = 0;
 
 	for_each_xattr_handler(handlers, handler) {
+		int err;
+
 		if (!handler->name || (handler->list && !handler->list(dentry)))
 			continue;
 		err = xattr_list_one(&buffer, &remaining_size, handler->name);
@@ -1015,7 +1016,7 @@  generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 			return err;
 	}
 
-	return err ? err : buffer_size - remaining_size;
+	return buffer_size - remaining_size;
 }
 EXPORT_SYMBOL(generic_listxattr);