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] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 7 Sep 2020 16:28:41 +0200
From:   Wolfram Sang <wsa@...nel.org>
To:     trix@...hat.com
Cc:     syniurge@...il.com, nehal-bakulchandra.shah@....com,
        shyam-sundar.s-k@....com, natechancellor@...il.com,
        ndesaulniers@...gle.com, linux-i2c@...r.kernel.org,
        linux-kernel@...r.kernel.org, clang-built-linux@...glegroups.com
Subject: Re: [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer

On Fri, Sep 04, 2020 at 11:06:47AM -0700, trix@...hat.com wrote:
> From: Tom Rix <trix@...hat.com>
> 
> clang static analyzer reports this problem
> 
> i2c-amd-mp2-plat.c:174:9: warning: Branch condition evaluates
>   to a garbage value
>         return err ? err : num;
>                ^~~
> 
> err is not initialized, it depends on the being set in the
> transfer loop which will not happen if num is 0.  Surveying
> other master_xfer() implementations show all handle a 0 num.
> 
> Because returning 0 is expected, initialize err to 0.

Well, it is not expected. The core does:

2019         if (WARN_ON(!msgs || num < 1))
2020                 return -EINVAL;

Dunno if we should apply the patch nonetheless or add a comment that num
is guaranteed to be at least 1.

> 
> Signed-off-by: Tom Rix <trix@...hat.com>
> ---
>  drivers/i2c/busses/i2c-amd-mp2-plat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> index 17df9e8845b6..506433bc0ff2 100644
> --- a/drivers/i2c/busses/i2c-amd-mp2-plat.c
> +++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c
> @@ -155,7 +155,7 @@ static int i2c_amd_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
>  	struct amd_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
>  	int i;
>  	struct i2c_msg *pmsg;
> -	int err;
> +	int err = 0;
>  
>  	/* the adapter might have been deleted while waiting for the bus lock */
>  	if (unlikely(!i2c_dev->common.mp2_dev))
> -- 
> 2.18.1
> 

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ