raw/ifpga/base: fix uninitialized variables gcc warning
Checks
Commit Message
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
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>
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.
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.
@@ -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;