[PATCH] btrfs: remove redundant condition checks

Xichao Zhao posted 1 patch 4 days, 8 hours ago
fs/btrfs/inode-item.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] btrfs: remove redundant condition checks
Posted by Xichao Zhao 4 days, 8 hours ago
Remove redundant condition checks and replace else if with else.

Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
---
 fs/btrfs/inode-item.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c
index f06cf701ae5a..3d0631bf7389 100644
--- a/fs/btrfs/inode-item.c
+++ b/fs/btrfs/inode-item.c
@@ -531,7 +531,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 			if (extent_type != BTRFS_FILE_EXTENT_INLINE)
 				item_end +=
 				    btrfs_file_extent_num_bytes(leaf, fi);
-			else if (extent_type == BTRFS_FILE_EXTENT_INLINE)
+			else
 				item_end += btrfs_file_extent_ram_bytes(leaf, fi);
 
 			btrfs_trace_truncate(control->inode, leaf, fi,
@@ -586,7 +586,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 					control->sub_bytes += num_dec;
 			}
 			clear_len = num_dec;
-		} else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
+		} else {
 			/*
 			 * We can't truncate inline items that have had
 			 * special encodings
-- 
2.34.1
Re: [PATCH] btrfs: remove redundant condition checks
Posted by David Sterba 3 days, 23 hours ago
On Fri, Sep 05, 2025 at 04:01:03PM +0800, Xichao Zhao wrote:
> Remove redundant condition checks and replace else if with else.
> 
> Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
> ---
>  fs/btrfs/inode-item.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c
> index f06cf701ae5a..3d0631bf7389 100644
> --- a/fs/btrfs/inode-item.c
> +++ b/fs/btrfs/inode-item.c
> @@ -531,7 +531,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
>  			if (extent_type != BTRFS_FILE_EXTENT_INLINE)
>  				item_end +=
>  				    btrfs_file_extent_num_bytes(leaf, fi);
> -			else if (extent_type == BTRFS_FILE_EXTENT_INLINE)
> +			else

I'd rather explicitly check for the values and add a separate fallback
statement that will catch unexpected values and propagates the errors.
As you did it we'd assume that everything "else" has to be
BTRFS_FILE_EXTENT_INLINE which may not be true in case of error.

>  				item_end += btrfs_file_extent_ram_bytes(leaf, fi);
>  
>  			btrfs_trace_truncate(control->inode, leaf, fi,