raw/ifpga/base: fix uninitialized variables gcc warning

Message ID 20201119150011.4005300-1-conor.walsh@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Qi Zhang
Headers
Series raw/ifpga/base: fix uninitialized variables gcc warning |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing warning Testing issues

Commit Message

Conor Walsh Nov. 19, 2020, 3 p.m. UTC
On Ubuntu 18.04 using gcc 7.5, gcc sees size and start as possibly being
uninitialized. This patch initialises size and start to correct this
warning.

Exact warning:
../drivers/raw/ifpga/base/opae_intel_max10.c:488:22: warning: ‘size’
may be used uninitialized in this function [-Wmaybe-uninitialized]
raw->regs[i].size = size;
../drivers/raw/ifpga/base/opae_intel_max10.c:484:25: warning: ‘start’
may be used uninitialized in this function [-Wmaybe-uninitialized]
raw->regs[i].regoff = start;

Fixes: 45f301724ba7 ("raw/ifpga/base: support sensor")

Signed-off-by: Conor Walsh <conor.walsh@intel.com>
---
 drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Xu, Rosen Nov. 20, 2020, 1:22 a.m. UTC | #1
Hi,


> -----Original Message-----
> From: Walsh, Conor <conor.walsh@intel.com>
> Sent: Thursday, November 19, 2020 23:00
> To: Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Pei, Andy <andy.pei@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Chen, LingliX <linglix.chen@intel.com>;
> Walsh, Conor <conor.walsh@intel.com>
> Subject: [PATCH] raw/ifpga/base: fix uninitialized variables gcc warning
> 
> On Ubuntu 18.04 using gcc 7.5, gcc sees size and start as possibly being
> uninitialized. This patch initialises size and start to correct this warning.
> 
> Exact warning:
> ../drivers/raw/ifpga/base/opae_intel_max10.c:488:22: warning: ‘size’
> may be used uninitialized in this function [-Wmaybe-uninitialized]
> raw->regs[i].size = size;
> ../drivers/raw/ifpga/base/opae_intel_max10.c:484:25: warning: ‘start’
> may be used uninitialized in this function [-Wmaybe-uninitialized]
> raw->regs[i].regoff = start;
> 
> Fixes: 45f301724ba7 ("raw/ifpga/base: support sensor")
> 
> Signed-off-by: Conor Walsh <conor.walsh@intel.com>
> ---
>  drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/base/opae_intel_max10.c
> b/drivers/raw/ifpga/base/opae_intel_max10.c
> index 1a526ea549..1c12a85195 100644
> --- a/drivers/raw/ifpga/base/opae_intel_max10.c
> +++ b/drivers/raw/ifpga/base/opae_intel_max10.c
> @@ -418,7 +418,7 @@ max10_sensor_init(struct intel_max10_device *dev,
> int parent)
>  	int i, ret = 0, offset = 0;
>  	const fdt32_t *num;
>  	const char *ptr;
> -	u64 start, size;
> +	u64 start = 0, size = 0;
>  	struct raw_sensor_info *raw;
>  	struct opae_sensor_info *sensor;
>  	char *fdt_root = dev->fdt_root;
> --
> 2.25.1

Reviewed-by: Rosen Xu <rosen.xu@intel.com>
  
Lingli Chen Nov. 20, 2020, 7:28 a.m. UTC | #2
Tested-by:  Chen, LingliX <linglix.chen@intel.com>

Regards,
Chen, LingliX

> -----Original Message-----
> From: Walsh, Conor
> Sent: Thursday, November 19, 2020 11:00 PM
> To: Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
> <tianfei.zhang@intel.com>; Pei, Andy <andy.pei@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Chen, LingliX <linglix.chen@intel.com>;
> Walsh, Conor <conor.walsh@intel.com>
> Subject: [PATCH] raw/ifpga/base: fix uninitialized variables gcc warning
> 
> On Ubuntu 18.04 using gcc 7.5, gcc sees size and start as possibly being
> uninitialized. This patch initialises size and start to correct this warning.
  
Ferruh Yigit Nov. 23, 2020, 5:18 p.m. UTC | #3
On 11/20/2020 1:22 AM, Xu, Rosen wrote:
> Hi,
> 
> 
>> -----Original Message-----
>> From: Walsh, Conor <conor.walsh@intel.com>
>> Sent: Thursday, November 19, 2020 23:00
>> To: Xu, Rosen <rosen.xu@intel.com>; Zhang, Tianfei
>> <tianfei.zhang@intel.com>; Pei, Andy <andy.pei@intel.com>
>> Cc: dev@dpdk.org; stable@dpdk.org; Chen, LingliX <linglix.chen@intel.com>;
>> Walsh, Conor <conor.walsh@intel.com>
>> Subject: [PATCH] raw/ifpga/base: fix uninitialized variables gcc warning
>>
>> On Ubuntu 18.04 using gcc 7.5, gcc sees size and start as possibly being
>> uninitialized. This patch initialises size and start to correct this warning.
>>
>> Exact warning:
>> ../drivers/raw/ifpga/base/opae_intel_max10.c:488:22: warning: ‘size’
>> may be used uninitialized in this function [-Wmaybe-uninitialized]
>> raw->regs[i].size = size;
>> ../drivers/raw/ifpga/base/opae_intel_max10.c:484:25: warning: ‘start’
>> may be used uninitialized in this function [-Wmaybe-uninitialized]
>> raw->regs[i].regoff = start;
>>
>> Fixes: 45f301724ba7 ("raw/ifpga/base: support sensor")
>>
>> Signed-off-by: Conor Walsh <conor.walsh@intel.com>
>> ---
>>   drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/raw/ifpga/base/opae_intel_max10.c
>> b/drivers/raw/ifpga/base/opae_intel_max10.c
>> index 1a526ea549..1c12a85195 100644
>> --- a/drivers/raw/ifpga/base/opae_intel_max10.c
>> +++ b/drivers/raw/ifpga/base/opae_intel_max10.c
>> @@ -418,7 +418,7 @@ max10_sensor_init(struct intel_max10_device *dev,
>> int parent)
>>   	int i, ret = 0, offset = 0;
>>   	const fdt32_t *num;
>>   	const char *ptr;
>> -	u64 start, size;
>> +	u64 start = 0, size = 0;
>>   	struct raw_sensor_info *raw;
>>   	struct opae_sensor_info *sensor;
>>   	char *fdt_root = dev->fdt_root;
>> --
>> 2.25.1
> 
> Reviewed-by: Rosen Xu <rosen.xu@intel.com>
> 

This also looks a compiler false positive, at least it would be good to 
highlight in the commit log that you are not fixing the code but false compiler 
warning.

And since the code is not in the data path, I guess it is OK to add 
initialization to silence the compiler.

But if the warnings doesn't break the build but just warnings, leaving them as 
it is also an option I think.
  

Patch

diff --git a/drivers/raw/ifpga/base/opae_intel_max10.c b/drivers/raw/ifpga/base/opae_intel_max10.c
index 1a526ea549..1c12a85195 100644
--- a/drivers/raw/ifpga/base/opae_intel_max10.c
+++ b/drivers/raw/ifpga/base/opae_intel_max10.c
@@ -418,7 +418,7 @@  max10_sensor_init(struct intel_max10_device *dev, int parent)
 	int i, ret = 0, offset = 0;
 	const fdt32_t *num;
 	const char *ptr;
-	u64 start, size;
+	u64 start = 0, size = 0;
 	struct raw_sensor_info *raw;
 	struct opae_sensor_info *sensor;
 	char *fdt_root = dev->fdt_root;