[EXT] Re: [PATCH] rtc: pcf2127: fix uninitialized variable msg

Rasmus Villemoes rasmus.villemoes at prevas.dk
Thu Jul 9 13:57:44 CEST 2020


On 09/07/2020 13.38, Biwen Li wrote:
>>
>> On 09/07/2020 12.58, Biwen Li wrote:
>>> From: Biwen Li <biwen.li at 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


More information about the U-Boot mailing list