* [PATCH] btrfs: Remove redundant assignment to ret
@ 2021-05-08 10:38 Jiapeng Chong
2021-05-10 13:41 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Jiapeng Chong @ 2021-05-08 10:38 UTC (permalink / raw)
To: clm; +Cc: josef, dsterba, linux-btrfs, linux-kernel, 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.
Clean up the following clang-analyzer warning:
fs/btrfs/extent_io.c:5357:4: warning: Value stored to 'ret' is never
read [clang-analyzer-deadcode.DeadStores].
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
fs/btrfs/extent_io.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 074a78a..cea58be 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -5354,7 +5354,6 @@ int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo,
goto out_free;
if (ret)
flags |= FIEMAP_EXTENT_SHARED;
- ret = 0;
}
if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
flags |= FIEMAP_EXTENT_ENCODED;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: Remove redundant assignment to ret
2021-05-08 10:38 [PATCH] btrfs: Remove redundant assignment to ret Jiapeng Chong
@ 2021-05-10 13:41 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-05-10 13:41 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel
On Sat, May 08, 2021 at 06:38:49PM +0800, Jiapeng Chong wrote:
> 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.
>
> Clean up the following clang-analyzer warning:
>
> fs/btrfs/extent_io.c:5357:4: warning: Value stored to 'ret' is never
> read [clang-analyzer-deadcode.DeadStores].
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> fs/btrfs/extent_io.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 074a78a..cea58be 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -5354,7 +5354,6 @@ int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo,
> goto out_free;
> if (ret)
> flags |= FIEMAP_EXTENT_SHARED;
> - ret = 0;
This leaves the scope where the value of 'ret' has been used for
something and it's reset to 0 for clarity. This is a pattern that we use
and will not change it just to silence clang analyzer.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: Remove redundant assignment to ret
2021-04-29 10:15 Jiapeng Chong
@ 2021-04-29 12:55 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-04-29 12:55 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel
On Thu, Apr 29, 2021 at 06:15:20PM +0800, Jiapeng Chong wrote:
> 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.
> 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 <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> fs/btrfs/volumes.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 9a1ead0..30504fa 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -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.
> }
> @@ -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.
>
> /*
> * 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] btrfs: Remove redundant assignment to ret
@ 2021-04-29 10:15 Jiapeng Chong
2021-04-29 12:55 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Jiapeng Chong @ 2021-04-29 10:15 UTC (permalink / raw)
To: clm; +Cc: josef, dsterba, linux-btrfs, linux-kernel, 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:
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 <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
fs/btrfs/volumes.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9a1ead0..30504fa 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-10 13:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-08 10:38 [PATCH] btrfs: Remove redundant assignment to ret Jiapeng Chong
2021-05-10 13:41 ` David Sterba
-- strict thread matches above, loose matches on Subject: below --
2021-04-29 10:15 Jiapeng Chong
2021-04-29 12:55 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.