Skip to contentSkip to conversation

watchdog: wdat_wdt: fix return value check in wdat_wdt_probe()

PATCH In review Wei Yongjun 4 participants 5 messages Sep 28, 2016 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: wdat_wdt: fix return value check in wdat_wdt_probe()

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap_resource() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR().

---
 drivers/watchdog/wdat_wdt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/watchdog/wdat_wdt.c +4 -3
index 6b64645..4594723 100644
@@ -351,16 +351,17 @@ static int wdat_wdt_probe(struct platform_device *pdev)
 		res = &pdev->resource[i];
 		if (resource_type(res) == IORESOURCE_MEM) {
 			reg = devm_ioremap_resource(&pdev->dev, res);
+			if (IS_ERR(reg))
+				return PTR_ERR(reg);
 		} else if (resource_type(res) == IORESOURCE_IO) {
 			reg = devm_ioport_map(&pdev->dev, res->start, 1);
+			if (!reg)
+				return -ENOMEM;
 		} else {
 			dev_err(&pdev->dev, "Unsupported resource\n");
 			return -EINVAL;
 		}
 
-		if (!reg)
-			return -ENOMEM;
-
 		regs[i] = reg;
 	}
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Wei Yongjun
Quoted 7 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap_resource() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR().

Quoted 33 lines
---
 drivers/watchdog/wdat_wdt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/watchdog/wdat_wdt.c +4 -4
index 6b64645..4594723 100644
@@ -351,16 +351,17 @@ static int wdat_wdt_probe(struct platform_device *pdev)
 		res = &pdev->resource[i];
 		if (resource_type(res) == IORESOURCE_MEM) {
 			reg = devm_ioremap_resource(&pdev->dev, res);
+			if (IS_ERR(reg))
+				return PTR_ERR(reg);
 		} else if (resource_type(res) == IORESOURCE_IO) {
 			reg = devm_ioport_map(&pdev->dev, res->start, 1);
+			if (!reg)
+				return -ENOMEM;
 		} else {
 			dev_err(&pdev->dev, "Unsupported resource\n");
 			return -EINVAL;
 		}
 
-		if (!reg)
-			return -ENOMEM;
-
 		regs[i] = reg;
 	}
 
--

To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Wei Yongjun
Quoted 7 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

In case of error, the function devm_ioremap_resource() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR().

Can you please CC your fixes to a mailing list, [email protected] at least if you can't find a more specific one?

They are much easier to handle then, to me at least.

Quoted 18 lines
---
  drivers/watchdog/wdat_wdt.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/watchdog/wdat_wdt.c +4 -0
index 6b64645..4594723 100644
@@ -351,16 +351,17 @@ static int wdat_wdt_probe(struct platform_device *pdev)
  		res = &pdev->resource[i];
  		if (resource_type(res) == IORESOURCE_MEM) {
  			reg = devm_ioremap_resource(&pdev->dev, res);
+			if (IS_ERR(reg))
+				return PTR_ERR(reg);
  		} else if (resource_type(res) == IORESOURCE_IO) {
  			reg = devm_ioport_map(&pdev->dev, res->start, 1);
+			if (!reg)
+				return -ENOMEM;

drivers/watchdog/wdat_wdt.c static int wdat_wdt_probe(struct platform_device *pdev) · line 366

Quoted 10 lines
drivers/watchdog/wdat_wdt.c +0 -3
  		} else {
  			dev_err(&pdev->dev, "Unsupported resource\n");
  			return -EINVAL;
  		}
 
-		if (!reg)
-			return -ENOMEM;
-
  		regs[i] = reg;
  	}

Thanks,

Rafael