linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] i2c: sh_mobile: eliminate a misreported warning
@ 2020-04-29 12:40 Zhen Lei
  2020-05-29 12:15 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Zhen Lei @ 2020-04-29 12:40 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: Zhen Lei

The warning is caused by the branches "if (pd->pos == -1)" and
"if (pd->pos == 0)", because they appear after "real_pos = pd->pos - 2",
so the compiler doesn't known the value of real_pos is negative through
these two branches.

To avoid this warning, eliminate the middleman "data".

drivers/i2c/busses/i2c-sh_mobile.c: In function ‘sh_mobile_i2c_isr’:
drivers/i2c/busses/i2c-sh_mobile.c:396:26: warning: ‘data’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   pd->msg->buf[real_pos] = data;
                          ^
drivers/i2c/busses/i2c-sh_mobile.c:369:16: note: ‘data’ was declared here
  unsigned char data;

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/i2c/busses/i2c-sh_mobile.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index d83ca4028fa0..2cca1b21e26e 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -366,7 +366,6 @@ static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd)
 
 static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd)
 {
-	unsigned char data;
 	int real_pos;
 
 	/* switch from TX (address) to RX (data) adds two interrupts */
@@ -387,13 +386,11 @@ static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd)
 		if (real_pos < 0)
 			i2c_op(pd, OP_RX_STOP);
 		else
-			data = i2c_op(pd, OP_RX_STOP_DATA);
+			pd->msg->buf[real_pos] = i2c_op(pd, OP_RX_STOP_DATA);
 	} else if (real_pos >= 0) {
-		data = i2c_op(pd, OP_RX);
+		pd->msg->buf[real_pos] = i2c_op(pd, OP_RX);
 	}
 
-	if (real_pos >= 0)
-		pd->msg->buf[real_pos] = data;
  done:
 	pd->pos++;
 	return pd->pos == (pd->msg->len + 2);
-- 
2.26.0.106.g9fadedd



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] i2c: sh_mobile: eliminate a misreported warning
  2020-04-29 12:40 [PATCH 1/1] i2c: sh_mobile: eliminate a misreported warning Zhen Lei
@ 2020-05-29 12:15 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2020-05-29 12:15 UTC (permalink / raw)
  To: Zhen Lei; +Cc: linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

On Wed, Apr 29, 2020 at 08:40:17PM +0800, Zhen Lei wrote:
> The warning is caused by the branches "if (pd->pos == -1)" and
> "if (pd->pos == 0)", because they appear after "real_pos = pd->pos - 2",
> so the compiler doesn't known the value of real_pos is negative through
> these two branches.
> 
> To avoid this warning, eliminate the middleman "data".
> 
> drivers/i2c/busses/i2c-sh_mobile.c: In function ‘sh_mobile_i2c_isr’:
> drivers/i2c/busses/i2c-sh_mobile.c:396:26: warning: ‘data’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    pd->msg->buf[real_pos] = data;
>                           ^
> drivers/i2c/busses/i2c-sh_mobile.c:369:16: note: ‘data’ was declared here
>   unsigned char data;
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>

Thanks for the patch and reminding me about the issue, it is correct.
However, an identical patch has been sent before and is now applied in
for-next:

http://patchwork.ozlabs.org/project/linux-i2c/patch/f526f90ea62741716de2ecfa310ba22d8cf1d3c2.1557377015.git.viresh.kumar@linaro.org/


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-29 12:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 12:40 [PATCH 1/1] i2c: sh_mobile: eliminate a misreported warning Zhen Lei
2020-05-29 12:15 ` 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).