btrfs: Remove redundant assignment to ret
PATCH 1/1 btrfs: Remove redundant assignment to ret
Variable ret is set to zero but this value is never read as it is overwritten or not used later on, hence it is a redundant assignment and can be removed.
Cleans up the following clang-analyzer warning:
fs/btrfs/volumes.c:8019:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].
fs/btrfs/volumes.c:4757:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].
fs/btrfs/volumes.c:7951:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].
--- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/volumes.c +1 -3
@@ -4754,7 +4754,6 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)mutex_unlock (&fs_info->reclaim_bgs_lock);if (ret <0 ) goto done; - ret =0 ;btrfs_release_path (path);break ; }
@@ -7939,7 +7938,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)struct btrfs_key key;u64 prev_devid =0 ;u64 prev_dev_ext_end =0 ; -int ret =0 ; +int ret;/* * We don't have a dev_root because we mounted with ignorebadroots and
@@ -8016,7 +8015,6 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)if (ret <0 ) goto out;if (ret >0 ) { - ret =0 ;break ; } }
Signature · 1 line
1.8.3.1
Quoted 5 lines · Jiapeng Chong
Variable ret is set to zero but this value is never read as it is overwritten or not used later on, hence it is a redundant assignment and can be removed.
Cleans up the following clang-analyzer warning:
I've looked at clang analyzer warnings in the past and the dead stores were ones of the least useful, namely because of the return value assignments.
Quoted 20 lines
fs/btrfs/volumes.c:8019:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].
fs/btrfs/volumes.c:4757:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].
fs/btrfs/volumes.c:7951:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores].Reported-by Abaci Robot <[email protected]>Signed-off-by Jiapeng Chong <[email protected]>--- fs/btrfs/volumes.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) · line 4758
Quoted 6 lines
fs/btrfs/volumes.c +0
-1@@ -4754,7 +4754,6 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)mutex_unlock (&fs_info->reclaim_bgs_lock);if (ret <0 ) goto done; - ret =0 ;btrfs_release_path (path);break ;
So this is a code pattern where 'ret' is used for some local function call but we want to make sure it does not go outside of the block as a non-zero value, potentially being returned from the whole function. No harm done if the value is not used later.
fs/btrfs/volumes.c int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) · line 7941
Quoted 7 lines
fs/btrfs/volumes.c +1
-1}@@ -7939,7 +7938,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)struct btrfs_key key;u64 prev_devid =0 ;u64 prev_dev_ext_end =0 ; -int ret =0 ; +int ret;
Similar here, initializing ret to zero does no harm. We've had compiler warnings about unitialized ret when some error path was jumping around it.
fs/btrfs/volumes.c int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) · line 8019
Quoted 10 lines
fs/btrfs/volumes.c +0
-1/* * We don't have a dev_root because we mounted with ignorebadroots and @@ -8016,7 +8015,6 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)if (ret <0 ) goto out;if (ret >0 ) { - ret =0 ;break ; }
Same pattern as in the first case.