diff mbox series

[2/2] aspeed/i2c: Prevent uninitialized warning

Message ID 07957dcab31f65de3dd30efa91e6b9152ac79879.1579598240.git.mrezanin@redhat.com
State New
Headers show
Series Prevent uninitialized warnings | expand

Commit Message

Miroslav Rezanina Jan. 21, 2020, 9:28 a.m. UTC
From: Miroslav Rezanina <mrezanin@redhat.com>

Compiler reports uninitialized warning for cmd_flags variable.

Adding NULL initialization to prevent this warning.

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 hw/i2c/aspeed_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Huth Jan. 21, 2020, 10:02 a.m. UTC | #1
On 21/01/2020 10.28, mrezanin@redhat.com wrote:
> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> Compiler reports uninitialized warning for cmd_flags variable.
> 
> Adding NULL initialization to prevent this warning.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> ---
>  hw/i2c/aspeed_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
> index 2da04a4..445182a 100644
> --- a/hw/i2c/aspeed_i2c.c
> +++ b/hw/i2c/aspeed_i2c.c
> @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
>  
>  static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
>  {
> -    g_autofree char *cmd_flags;
> +    g_autofree char *cmd_flags = NULL;
>      uint32_t count;
>  
>      if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {

Reviewed-by: Thomas Huth <thuth@redhat.com>

... maybe someone with enough Perl-foo (i.e. not me ;-)) should add a
check to our check_patch.pl script so that it complains when new code is
introduced that uses g_autofree without initializing the variable...
Cédric Le Goater Jan. 21, 2020, 10:44 a.m. UTC | #2
On 1/21/20 11:02 AM, Thomas Huth wrote:
> On 21/01/2020 10.28, mrezanin@redhat.com wrote:
>> From: Miroslav Rezanina <mrezanin@redhat.com>
>>
>> Compiler reports uninitialized warning for cmd_flags variable.
>>
>> Adding NULL initialization to prevent this warning.
>>
>> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
>> ---
>>  hw/i2c/aspeed_i2c.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
>> index 2da04a4..445182a 100644
>> --- a/hw/i2c/aspeed_i2c.c
>> +++ b/hw/i2c/aspeed_i2c.c
>> @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
>>  
>>  static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
>>  {
>> -    g_autofree char *cmd_flags;
>> +    g_autofree char *cmd_flags = NULL;
>>      uint32_t count;
>>  
>>      if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 
> ... maybe someone with enough Perl-foo (i.e. not me ;-)) should add a
> check to our check_patch.pl script so that it complains when new code is
> introduced that uses g_autofree without initializing the variable...

weird. The cmd_flags variable is assigned just after and used
in a trace. 

C.
Miroslav Rezanina Jan. 21, 2020, 10:57 a.m. UTC | #3
----- Original Message -----
> From: "Cédric Le Goater" <clg@kaod.org>
> To: "Thomas Huth" <thuth@redhat.com>, mrezanin@redhat.com, qemu-devel@nongnu.org
> Cc: "peter maydell" <peter.maydell@linaro.org>, "Andrew Jeffery" <andrew@aj.id.au>, "Joel Stanley" <joel@jms.id.au>,
> qemu-trivial@nongnu.org
> Sent: Tuesday, January 21, 2020 11:44:14 AM
> Subject: Re: [PATCH 2/2] aspeed/i2c: Prevent uninitialized warning
> 
> On 1/21/20 11:02 AM, Thomas Huth wrote:
> > On 21/01/2020 10.28, mrezanin@redhat.com wrote:
> >> From: Miroslav Rezanina <mrezanin@redhat.com>
> >>
> >> Compiler reports uninitialized warning for cmd_flags variable.
> >>
> >> Adding NULL initialization to prevent this warning.
> >>
> >> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> >> ---
> >>  hw/i2c/aspeed_i2c.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
> >> index 2da04a4..445182a 100644
> >> --- a/hw/i2c/aspeed_i2c.c
> >> +++ b/hw/i2c/aspeed_i2c.c
> >> @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
> >>  
> >>  static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
> >>  {
> >> -    g_autofree char *cmd_flags;
> >> +    g_autofree char *cmd_flags = NULL;
> >>      uint32_t count;
> >>  
> >>      if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {
> > 
> > Reviewed-by: Thomas Huth <thuth@redhat.com>
> > 
> > ... maybe someone with enough Perl-foo (i.e. not me ;-)) should add a
> > check to our check_patch.pl script so that it complains when new code is
> > introduced that uses g_autofree without initializing the variable...
> 
> weird. The cmd_flags variable is assigned just after and used
> in a trace.
> 

As g_autofree is used, variable has to be initialized otherwise will compiler
complain even in the case we write to variable immediately after.

Mirek

> C.
> 
>
Thomas Huth Jan. 21, 2020, 11:43 a.m. UTC | #4
On 21/01/2020 11.44, Cédric Le Goater wrote:
> On 1/21/20 11:02 AM, Thomas Huth wrote:
>> On 21/01/2020 10.28, mrezanin@redhat.com wrote:
>>> From: Miroslav Rezanina <mrezanin@redhat.com>
>>>
>>> Compiler reports uninitialized warning for cmd_flags variable.
>>>
>>> Adding NULL initialization to prevent this warning.
>>>
>>> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
>>> ---
>>>  hw/i2c/aspeed_i2c.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
>>> index 2da04a4..445182a 100644
>>> --- a/hw/i2c/aspeed_i2c.c
>>> +++ b/hw/i2c/aspeed_i2c.c
>>> @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
>>>  
>>>  static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
>>>  {
>>> -    g_autofree char *cmd_flags;
>>> +    g_autofree char *cmd_flags = NULL;
>>>      uint32_t count;
>>>  
>>>      if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {
>>
>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>
>> ... maybe someone with enough Perl-foo (i.e. not me ;-)) should add a
>> check to our check_patch.pl script so that it complains when new code is
>> introduced that uses g_autofree without initializing the variable...
> 
> weird. The cmd_flags variable is assigned just after and used
> in a trace. 

I don't know, but my guess is that you could compile with tracing
disabled - in that case gcc might maybe optimize the assignment away,
too... ?

 Thomas
Laurent Vivier Feb. 6, 2020, 10:13 a.m. UTC | #5
Le 21/01/2020 à 10:28, mrezanin@redhat.com a écrit :
> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> Compiler reports uninitialized warning for cmd_flags variable.
> 
> Adding NULL initialization to prevent this warning.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> ---
>  hw/i2c/aspeed_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
> index 2da04a4..445182a 100644
> --- a/hw/i2c/aspeed_i2c.c
> +++ b/hw/i2c/aspeed_i2c.c
> @@ -400,7 +400,7 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
>  
>  static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
>  {
> -    g_autofree char *cmd_flags;
> +    g_autofree char *cmd_flags = NULL;
>      uint32_t count;
>  
>      if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {
> 

Applied to my trivial-patches branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
index 2da04a4..445182a 100644
--- a/hw/i2c/aspeed_i2c.c
+++ b/hw/i2c/aspeed_i2c.c
@@ -400,7 +400,7 @@  static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
 
 static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
 {
-    g_autofree char *cmd_flags;
+    g_autofree char *cmd_flags = NULL;
     uint32_t count;
 
     if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) {