All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf2127: fix uninitialized variable msg
@ 2020-07-09 10:58 Biwen Li
  2020-07-09 11:29 ` Rasmus Villemoes
  0 siblings, 1 reply; 6+ messages in thread
From: Biwen Li @ 2020-07-09 10:58 UTC (permalink / raw)
  To: u-boot

From: Biwen Li <biwen.li@nxp.com>

Fix uninitialized variable msg

Signed-off-by: Biwen Li <biwen.li@nxp.com>
---
 drivers/rtc/pcf2127.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/pcf2127.c b/drivers/rtc/pcf2127.c
index f695350..58c4ee9 100644
--- a/drivers/rtc/pcf2127.c
+++ b/drivers/rtc/pcf2127.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2016 by NXP Semiconductors Inc.
  * Date & Time support for PCF2127 RTC
+ * Copyright 2020 NXP
  */
 
 /*	#define	DEBUG	*/
@@ -26,7 +27,7 @@ static int pcf2127_read_reg(struct udevice *dev, uint offset,
 			    u8 *buffer, int len)
 {
 	struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
-	struct i2c_msg msg;
+	struct i2c_msg msg = {0};
 	int ret;
 
 	/* Set the address of the start register to be read */
-- 
2.7.4

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

* [PATCH] rtc: pcf2127: fix uninitialized variable msg
  2020-07-09 10:58 [PATCH] rtc: pcf2127: fix uninitialized variable msg Biwen Li
@ 2020-07-09 11:29 ` Rasmus Villemoes
  2020-07-09 11:38   ` [EXT] " Biwen Li
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2020-07-09 11:29 UTC (permalink / raw)
  To: u-boot

On 09/07/2020 12.58, Biwen Li wrote:
> From: Biwen Li <biwen.li@nxp.com>
> 
> Fix uninitialized variable msg
> 
>  	struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
> -	struct i2c_msg msg;
> +	struct i2c_msg msg = {0};
>  	int ret;
>  
>  	/* Set the address of the start register to be read */
> 

I assume it's the

        msg.flags |= I2C_M_RD;

line that is warned about (please include such info)? Isn't the right
fix to replace that by

        msg.flags = I2C_M_RD;

?

Rasmus

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

* [EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg
  2020-07-09 11:29 ` Rasmus Villemoes
@ 2020-07-09 11:38   ` Biwen Li
  2020-07-09 11:57     ` Rasmus Villemoes
  0 siblings, 1 reply; 6+ messages in thread
From: Biwen Li @ 2020-07-09 11:38 UTC (permalink / raw)
  To: u-boot

> 
> On 09/07/2020 12.58, Biwen Li wrote:
> > From: Biwen Li <biwen.li@nxp.com>
> >
> > Fix uninitialized variable msg
> >
> >       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
> > -     struct i2c_msg msg;
> > +     struct i2c_msg msg = {0};
> >       int ret;
> >
> >       /* Set the address of the start register to be read */
> >
> 
> I assume it's the
> 
>         msg.flags |= I2C_M_RD;
> 
> line that is warned about (please include such info)? Isn't the right fix to
> replace that by
> 
>         msg.flags = I2C_M_RD;
> 
> ?
Two lines("struct i2c msg;" and "msg.flags |= I2C_M_RD") are warned by build system. Initializing msg variable will be better.
> 
> Rasmus

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

* [EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg
  2020-07-09 11:38   ` [EXT] " Biwen Li
@ 2020-07-09 11:57     ` Rasmus Villemoes
  2020-07-10  1:53       ` Biwen Li
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2020-07-09 11:57 UTC (permalink / raw)
  To: u-boot

On 09/07/2020 13.38, Biwen Li wrote:
>>
>> On 09/07/2020 12.58, Biwen Li wrote:
>>> From: Biwen Li <biwen.li@nxp.com>
>>>
>>> Fix uninitialized variable msg
>>>
>>>       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
>>> -     struct i2c_msg msg;
>>> +     struct i2c_msg msg = {0};
>>>       int ret;
>>>
>>>       /* Set the address of the start register to be read */
>>>
>>
>> I assume it's the
>>
>>         msg.flags |= I2C_M_RD;
>>
>> line that is warned about (please include such info)? Isn't the right fix to
>> replace that by
>>
>>         msg.flags = I2C_M_RD;
>>
>> ?
> Two lines("struct i2c msg;" and "msg.flags |= I2C_M_RD") are warned by build system. 

What? That doesn't make sense. Perhaps your compiler is just friendly
enough to show you the declaration of the struct i2c_msg, but clearly
declaring an automatic variable without initializing it is not, by
itself, wrong. Otherwise "int ret;" in that very same function should be
warned about, and 100000 other instances in any code base written in C.

Please show the exact output from the compiler and the compiler version.

> Initializing msg variable will be better.

No, understanding the cause of the warning and fixing that is clearly
better.

Rasmus

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

* [EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg
  2020-07-09 11:57     ` Rasmus Villemoes
@ 2020-07-10  1:53       ` Biwen Li
  2020-09-23 13:36         ` Priyanka Jain
  0 siblings, 1 reply; 6+ messages in thread
From: Biwen Li @ 2020-07-10  1:53 UTC (permalink / raw)
  To: u-boot

> 
> On 09/07/2020 13.38, Biwen Li wrote:
> >>
> >> On 09/07/2020 12.58, Biwen Li wrote:
> >>> From: Biwen Li <biwen.li@nxp.com>
> >>>
> >>> Fix uninitialized variable msg
> >>>
> >>>       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
> >>> -     struct i2c_msg msg;
> >>> +     struct i2c_msg msg = {0};
> >>>       int ret;
> >>>
> >>>       /* Set the address of the start register to be read */
> >>>
> >>
> >> I assume it's the
> >>
> >>         msg.flags |= I2C_M_RD;
> >>
> >> line that is warned about (please include such info)? Isn't the right
> >> fix to replace that by
> >>
> >>         msg.flags = I2C_M_RD;
> >>
> >> ?
> > Two lines("struct i2c msg;" and "msg.flags |= I2C_M_RD") are warned by
> build system.
> 
> What? That doesn't make sense. Perhaps your compiler is just friendly enough
> to show you the declaration of the struct i2c_msg, but clearly declaring an
> automatic variable without initializing it is not, by itself, wrong. Otherwise "int
> ret;" in that very same function should be warned about, and 100000 other
> instances in any code base written in C.
> 
> Please show the exact output from the compiler and the compiler version.
Sorry, acctually not build system. It's code analysis tool.
Such as:
Declaring variable msg without initializer. (struce i2c_msg msg;)
Uninitialized scalar variable (UNINIT),  uninit_use: Using uninitialized value msg.flags.(msg.flags |= I2C_M_RD)
> 
> > Initializing msg variable will be better.
> 
> No, understanding the cause of the warning and fixing that is clearly better.
> 
> Rasmus

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

* [EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg
  2020-07-10  1:53       ` Biwen Li
@ 2020-09-23 13:36         ` Priyanka Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Priyanka Jain @ 2020-09-23 13:36 UTC (permalink / raw)
  To: u-boot

>-----Original Message-----
>From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Biwen Li (OSS)
>Sent: Friday, July 10, 2020 7:24 AM
>To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>; Biwen Li (OSS)
><biwen.li@oss.nxp.com>; Jagdish Gediya <jagdish.gediya@nxp.com>; Priyanka
>Jain <priyanka.jain@nxp.com>
>Cc: Jiafei Pan <jiafei.pan@nxp.com>; u-boot at lists.denx.de
>Subject: RE: [EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg
>
>>
>> On 09/07/2020 13.38, Biwen Li wrote:
>> >>
>> >> On 09/07/2020 12.58, Biwen Li wrote:
>> >>> From: Biwen Li <biwen.li@nxp.com>
>> >>>
>> >>> Fix uninitialized variable msg
>> >>>
>> >>>       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
>> >>> -     struct i2c_msg msg;
>> >>> +     struct i2c_msg msg = {0};
>> >>>       int ret;
>> >>>
>> >>>       /* Set the address of the start register to be read */
>> >>>
>> >>
>> >> I assume it's the
>> >>
>> >>         msg.flags |= I2C_M_RD;
>> >>
>> >> line that is warned about (please include such info)? Isn't the
>> >> right fix to replace that by
>> >>
>> >>         msg.flags = I2C_M_RD;
>> >>
>> >> ?
>> > Two lines("struct i2c msg;" and "msg.flags |= I2C_M_RD") are warned
>> > by
>> build system.
>>
>> What? That doesn't make sense. Perhaps your compiler is just friendly
>> enough to show you the declaration of the struct i2c_msg, but clearly
>> declaring an automatic variable without initializing it is not, by
>> itself, wrong. Otherwise "int ret;" in that very same function should
>> be warned about, and 100000 other instances in any code base written in C.
>>
>> Please show the exact output from the compiler and the compiler version.
>Sorry, acctually not build system. It's code analysis tool.

Can you please update subject or description stating that you are fixing issue reported by static analysis tool coverity

Thanks
Priyanka

>Such as:
>Declaring variable msg without initializer. (struce i2c_msg msg;) Uninitialized
>scalar variable (UNINIT),  uninit_use: Using uninitialized value
>msg.flags.(msg.flags |= I2C_M_RD)
>>
>> > Initializing msg variable will be better.
>>
>> No, understanding the cause of the warning and fixing that is clearly better.
>>
>> Rasmus

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

end of thread, other threads:[~2020-09-23 13:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 10:58 [PATCH] rtc: pcf2127: fix uninitialized variable msg Biwen Li
2020-07-09 11:29 ` Rasmus Villemoes
2020-07-09 11:38   ` [EXT] " Biwen Li
2020-07-09 11:57     ` Rasmus Villemoes
2020-07-10  1:53       ` Biwen Li
2020-09-23 13:36         ` Priyanka Jain

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.