Skip to contentSkip to conversation

raw/ifpga/base: fix uninitialized variables gcc warning

PATCH In review Conor Walsh 4 participants 4 messages Nov 19, 2020 – Nov 23, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/base/opae_intel_max10.c +1 -1
index 1a526ea549..1c12a85195 100644
@@ -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;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 41 lines

-----Original Message-----
From: Walsh, Conor <[email protected]>
Sent: Thursday, November 19, 2020 23:00
To: Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Pei, Andy <[email protected]>
Cc: [email protected]; [email protected]; Chen, LingliX <[email protected]>; Walsh, Conor <[email protected]>
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")
---
 drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/base/opae_intel_max10.c +1 -1
index 1a526ea549..1c12a85195 100644
@@ -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;
Quoted 3 lines

char *fdt_root = dev->fdt_root;
--
2.25.1

#2 lore raw
Quoted 41 lines · Rosen

Hi,

Quoted 38 lines

-----Original Message-----
From: Walsh, Conor <[email protected]>
Sent: Thursday, November 19, 2020 23:00
To: Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Pei, Andy <[email protected]>
Cc: [email protected]; [email protected]; Chen, LingliX <[email protected]>; Walsh, Conor <[email protected]>
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")
---
  drivers/raw/ifpga/base/opae_intel_max10.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/ifpga/base/opae_intel_max10.c +0 -1
index 1a526ea549..1c12a85195 100644
@@ -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;
Quoted 9 lines
Quoted 6 lines
drivers/raw/ifpga/base/opae_intel_max10.c +1 -0
+	u64 start = 0, size = 0;
  	struct raw_sensor_info *raw;
  	struct opae_sensor_info *sensor;

char *fdt_root = dev->fdt_root;
--
2.25.1

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.

Tested-by on v1 1/1
#3 lore raw
In reply to Conor Walsh

Regards,
Chen, LingliX

Quoted 11 lines

-----Original Message-----
From: Walsh, Conor
Sent: Thursday, November 19, 2020 11:00 PM
To: Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Pei, Andy <[email protected]>
Cc: [email protected]; [email protected]; Chen, LingliX <[email protected]>; Walsh, Conor <[email protected]>
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.