* [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer
@ 2020-09-04 18:06 trix
2020-09-05 12:33 ` Elie Morisse
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: trix @ 2020-09-04 18:06 UTC (permalink / raw)
To: syniurge, nehal-bakulchandra.shah, shyam-sundar.s-k,
natechancellor, ndesaulniers
Cc: linux-i2c, linux-kernel, clang-built-linux, Tom Rix
From: Tom Rix <trix@redhat.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.
Signed-off-by: Tom Rix <trix@redhat.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer
2020-09-04 18:06 [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer trix
@ 2020-09-05 12:33 ` Elie Morisse
2020-09-07 14:28 ` Wolfram Sang
2020-09-21 9:39 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: Elie Morisse @ 2020-09-05 12:33 UTC (permalink / raw)
To: trix
Cc: Shah, Nehal-bakulchandra, Shyam Sundar S K, natechancellor,
ndesaulniers, linux-i2c, linux-kernel, clang-built-linux
Acked-by: Elie Morisse <syniurge@gmail.com>
Le ven. 4 sept. 2020 à 20:06, <trix@redhat.com> a écrit :
>
> From: Tom Rix <trix@redhat.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.
>
> Signed-off-by: Tom Rix <trix@redhat.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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer
2020-09-04 18:06 [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer trix
2020-09-05 12:33 ` Elie Morisse
@ 2020-09-07 14:28 ` Wolfram Sang
2020-09-21 9:39 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2020-09-07 14:28 UTC (permalink / raw)
To: trix
Cc: syniurge, nehal-bakulchandra.shah, shyam-sundar.s-k,
natechancellor, ndesaulniers, linux-i2c, linux-kernel,
clang-built-linux
[-- Attachment #1: Type: text/plain, Size: 1567 bytes --]
On Fri, Sep 04, 2020 at 11:06:47AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.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@redhat.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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer
2020-09-04 18:06 [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer trix
2020-09-05 12:33 ` Elie Morisse
2020-09-07 14:28 ` Wolfram Sang
@ 2020-09-21 9:39 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2020-09-21 9:39 UTC (permalink / raw)
To: trix
Cc: syniurge, nehal-bakulchandra.shah, shyam-sundar.s-k,
natechancellor, ndesaulniers, linux-i2c, linux-kernel,
clang-built-linux
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
On Fri, Sep 04, 2020 at 11:06:47AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.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.
>
> Signed-off-by: Tom Rix <trix@redhat.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-21 9:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 18:06 [PATCH] i2c: amd_mp2: handle num is 0 input for i2c_amd_xfer trix
2020-09-05 12:33 ` Elie Morisse
2020-09-07 14:28 ` Wolfram Sang
2020-09-21 9:39 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).