Skip to contentSkip to conversation

hwmon: axi-fan-control: fix uninitialized dereference of pointer res

PATCH In review Colin King 2 participants 3 messages Feb 11, 2020

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 hwmon: axi-fan-control: fix uninitialized dereference of pointer res

From: Colin Ian King <[email protected]>

Currently the resource pointer ret is uninitialized and it is being dereferenced when printing out a debug message. Fix this by fetching the resource and assigning pointer res. It is a moot point that we sanity check for a null res since a successful call to devm_platform_ioremap_resource has already occurred so in theory it should never be non-null.

Addresses-Coverity: ("Uninitialized pointer read")

Fixes 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")
---
 drivers/hwmon/axi-fan-control.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/axi-fan-control.c +3 -0
index 8041ba7cc152..36e0d060510a 100644
@@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
 	if (!ctl->clk_rate)
 		return -EINVAL;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
 		(unsigned long long)res->start, ctl->base);
 
Signature · 1 line
2.25.0
maintainer
#1 lore raw
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Currently the resource pointer ret is uninitialized and it is being dereferenced when printing out a debug message. Fix this by fetching the resource and assigning pointer res. It is a moot point that we sanity check for a null res since a successful call to devm_platform_ioremap_resource has already occurred so in theory it should never be non-null.

Quoted 3 lines

Addresses-Coverity: ("Uninitialized pointer read")

Fixes 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")

This has already been fixed by removing the message (and the then unused variable). The message was useless anyway since it printed the remapped address with %p.

Guenter

Quoted 21 lines
---
 drivers/hwmon/axi-fan-control.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/axi-fan-control.c +3 -0
index 8041ba7cc152..36e0d060510a 100644
@@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
 	if (!ctl->clk_rate)
 		return -EINVAL;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
 		(unsigned long long)res->start, ctl->base);
 
Signature · 1 line
2.25.0
#2 lore raw
Quoted 14 lines · Guenter Roeck
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Currently the resource pointer ret is uninitialized and it is being dereferenced when printing out a debug message. Fix this by fetching the resource and assigning pointer res. It is a moot point that we sanity check for a null res since a successful call to devm_platform_ioremap_resource has already occurred so in theory it should never be non-null.

Quoted 3 lines

Addresses-Coverity: ("Uninitialized pointer read")

Fixes 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")
Quoted 5 lines

This has already been fixed by removing the message (and the then unused variable). The message was useless anyway since it printed the remapped address with %p.

Guenter

OK, thanks. My static anaylsis can't keep up!

Quoted 22 lines
Quoted 22 lines
---
 drivers/hwmon/axi-fan-control.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hwmon/axi-fan-control.c +3 -0
index 8041ba7cc152..36e0d060510a 100644
@@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
 	if (!ctl->clk_rate)
 		return -EINVAL;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
 		(unsigned long long)res->start, ctl->base);
 
Signature · 1 line
2.25.0