Skip to contentSkip to conversation

watchdog: qcom: Check for platform_get_resource() failure

PATCH In review Fabio Estevam 2 participants 2 messages Jul 22, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: qcom: Check for platform_get_resource() failure

From: Fabio Estevam <[email protected]>

platform_get_resource() may fail, so we should better check its return value and propagate an error in case it fails.

This avoids a NULL pointer dereference a bit later in the code.

---
 drivers/watchdog/qcom-wdt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/watchdog/qcom-wdt.c +2 -0
index 4f47b5e..7809713 100644
@@ -162,6 +162,8 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENOMEM;
 
 	/* We use CPU0's DGT for the watchdog */
 	if (of_property_read_u32(np, "cpu-offset", &percpu_offset))
Signature · 1 line
2.7.4
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

platform_get_resource() may fail, so we should better check its return value and propagate an error in case it fails.

This avoids a NULL pointer dereference a bit later in the code.

Quoted 20 lines
---
 drivers/watchdog/qcom-wdt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/watchdog/qcom-wdt.c +2 -0
index 4f47b5e..7809713 100644
@@ -162,6 +162,8 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENOMEM;
 
 	/* We use CPU0's DGT for the watchdog */
 	if (of_property_read_u32(np, "cpu-offset", &percpu_offset))
Signature · 1 line
2.7.4