lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210429125524.GU7604@twin.jikos.cz>
Date:   Thu, 29 Apr 2021 14:55:24 +0200
From:   David Sterba <dsterba@...e.cz>
To:     Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
Cc:     clm@...com, josef@...icpanda.com, dsterba@...e.com,
        linux-btrfs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] btrfs: Remove redundant assignment to ret

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@...ux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@...ux.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ