[dpdk-dev] [PATCH] raw/ifpga/base: fix uninitialized variables gcc warning

Ferruh Yigit ferruh.yigit at intel.com
Mon Nov 23 18:18:25 CET 2020


On 11/20/2020 1:22 AM, Xu, Rosen wrote:
> Hi,
> 
> 
>> -----Original Message-----
>> From: Walsh, Conor <conor.walsh at intel.com>
>> Sent: Thursday, November 19, 2020 23:00
>> To: Xu, Rosen <rosen.xu at intel.com>; Zhang, Tianfei
>> <tianfei.zhang at intel.com>; Pei, Andy <andy.pei at intel.com>
>> Cc: dev at dpdk.org; stable at dpdk.org; Chen, LingliX <linglix.chen at intel.com>;
>> Walsh, Conor <conor.walsh at 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 at 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 at 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.


More information about the dev mailing list