Skip to contentSkip to conversation

xattr: remove redundant check on variable err

PATCH Superseded Colin Ian King 3 participants 3 messages Oct 30, 2024 – Oct 31, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xattr: remove redundant check on variable err

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.

---
 fs/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xattr.c +1 -1
index 05ec7e7d9e87..21beb82ab5dc 100644
@@ -1015,7 +1015,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);
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 5 lines · Colin Ian King

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.

I'd suggest taking err itself into the loop body, while we are at it...

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Colin Ian King
Quoted 7 lines · Colin Ian King

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.

Yeah, makes sense. Feel free to add:

Honza

Quoted 20 lines
---
 fs/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xattr.c +1 -1
index 05ec7e7d9e87..21beb82ab5dc 100644
@@ -1015,7 +1015,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);
 
Signature · 1 line
2.39.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR