* [PATCH] btrfs: Remove redundant initialization of 'to_add'
@ 2021-05-14 9:24 Yang Li
2021-05-16 8:53 ` Lukas Bulwahn
0 siblings, 1 reply; 2+ messages in thread
From: Yang Li @ 2021-05-14 9:24 UTC (permalink / raw)
To: clm
Cc: josef, dsterba, nathan, ndesaulniers, linux-btrfs, linux-kernel,
clang-built-linux, Yang Li
Variable 'to_add' is being initialized however this value is never
read as 'to_add' is assigned a new value in if statement. Remove the
redundant assignment. At the same time, move its declaration into the
if statement, because the variable is not used elsewhere.
Clean up clang warning:
fs/btrfs/extent-tree.c:2773:8: warning: Value stored to 'to_add' during
its initialization is never read [clang-analyzer-deadcode.DeadStores]
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
fs/btrfs/extent-tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f1d15b6..e7b2289 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2774,10 +2774,10 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
spin_unlock(&cache->lock);
if (!readonly && return_free_space &&
global_rsv->space_info == space_info) {
- u64 to_add = len;
spin_lock(&global_rsv->lock);
if (!global_rsv->full) {
+ u64 to_add;
to_add = min(len, global_rsv->size -
global_rsv->reserved);
global_rsv->reserved += to_add;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: Remove redundant initialization of 'to_add'
2021-05-14 9:24 [PATCH] btrfs: Remove redundant initialization of 'to_add' Yang Li
@ 2021-05-16 8:53 ` Lukas Bulwahn
0 siblings, 0 replies; 2+ messages in thread
From: Lukas Bulwahn @ 2021-05-16 8:53 UTC (permalink / raw)
To: Yang Li
Cc: clm, Josef Bacik, David Sterba, Nathan Chancellor,
Nick Desaulniers, linux-btrfs, Linux Kernel Mailing List,
clang-built-linux
On Fri, May 14, 2021 at 11:24 AM Yang Li <yang.lee@linux.alibaba.com> wrote:
>
> Variable 'to_add' is being initialized however this value is never
> read as 'to_add' is assigned a new value in if statement. Remove the
> redundant assignment. At the same time, move its declaration into the
> if statement, because the variable is not used elsewhere.
>
> Clean up clang warning:
>
> fs/btrfs/extent-tree.c:2773:8: warning: Value stored to 'to_add' during
> its initialization is never read [clang-analyzer-deadcode.DeadStores]
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> ---
> fs/btrfs/extent-tree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index f1d15b6..e7b2289 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2774,10 +2774,10 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
> spin_unlock(&cache->lock);
> if (!readonly && return_free_space &&
> global_rsv->space_info == space_info) {
> - u64 to_add = len;
>
> spin_lock(&global_rsv->lock);
> if (!global_rsv->full) {
> + u64 to_add;
> to_add = min(len, global_rsv->size -
> global_rsv->reserved);
Yang Li, you could just combine these two lines above, right?
So:
u64 to_add = min(len, ...);
By the way, great contribution on addressing all those dead stores
identified by clang analyzer... I wish I would also have more time on
addressing some of those remaining...
Lukas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-16 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 9:24 [PATCH] btrfs: Remove redundant initialization of 'to_add' Yang Li
2021-05-16 8:53 ` Lukas Bulwahn
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.