Skip to contentSkip to conversation

gpio: lpc32xx: check devm_gpiochip_add_data() return value

PATCH Superseded Jayaraj Devaraj 3 participants 5 messages Oct 14 – Oct 16

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: lpc32xx: check devm_gpiochip_add_data() return value

lpc32xx_gpio_probe() registers each gpio chip with devm_gpiochip_add_data() but ignores the return value. If registering a chip fails, probe still returns 0, so the driver binds with a chip missing and no error is reported.

Check the return value, print an error naming the failing chip and return the error code. Chips registered earlier in the loop are devm managed and are removed automatically on failure.

---
 drivers/gpio/gpio-lpc32xx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpio/gpio-lpc32xx.c +7 -3
index 37fc54fc7385..014eb8bc70da 100644
@@ -510,7 +510,7 @@ static int lpc32xx_of_xlate(struct gpio_chip *gc,
 
 static int lpc32xx_gpio_probe(struct platform_device *pdev)
 {
-	int i;
+	int i, ret;
 	void __iomem *reg_base;
 
 	reg_base = devm_platform_ioremap_resource(pdev, 0);
@@ -524,8 +524,12 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev)
 			lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
 			lpc32xx_gpiochip[i].reg_base = reg_base;
 		}
-		devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
-				  &lpc32xx_gpiochip[i]);
+		ret = devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
+					     &lpc32xx_gpiochip[i]);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to register gpio chip %d: %d\n", i, ret);
+			return ret;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jayaraj Devaraj

lpc32xx_gpio_probe() registers each gpio chip with devm_gpiochip_add_data() but ignores the return value. If registering a chip fails, probe still returns 0, so the driver binds with a chip missing and no error is reported.

Check the return value, print an error naming the failing chip and return the error code. Chips registered earlier in the loop are devm managed and are removed automatically on failure.

Thank you for the change!

Signature · 2 lines
Best wishes,
Vladimir
#2 lore raw
In reply to Jayaraj Devaraj
Quoted 28 lines · Jayaraj Devaraj

lpc32xx_gpio_probe() registers each gpio chip with devm_gpiochip_add_data() but ignores the return value. If registering a chip fails, probe still returns 0, so the driver binds with a chip missing and no error is reported.

Check the return value, print an error naming the failing chip and return the error code. Chips registered earlier in the loop are devm managed and are removed automatically on failure.

---
 drivers/gpio/gpio-lpc32xx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpio/gpio-lpc32xx.c +1 -1
index 37fc54fc7385..014eb8bc70da 100644
@@ -510,7 +510,7 @@ static int lpc32xx_of_xlate(struct gpio_chip *gc,
 
 static int lpc32xx_gpio_probe(struct platform_device *pdev)
 {
-	int i;
+	int i, ret;
 	void __iomem *reg_base;
 
 	reg_base = devm_platform_ioremap_resource(pdev, 0);

drivers/gpio/gpio-lpc32xx.c static int lpc32xx_gpio_probe(struct platform_device *pdev) · line 531

Quoted 10 lines
drivers/gpio/gpio-lpc32xx.c +5 -2
@@ -524,8 +524,12 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev)
 			lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
 			lpc32xx_gpiochip[i].reg_base = reg_base;
 		}
-		devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
-				  &lpc32xx_gpiochip[i]);
+		ret = devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
+					     &lpc32xx_gpiochip[i]);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to register gpio chip %d: %d\n", i, ret);
+			return ret;

Please use return dev_err_probe().

Bart

Quoted 8 lines
drivers/gpio/gpio-lpc32xx.c +1 -1
+		}
 	}
 
 	return 0;
--

2.34.1

#3 lore raw

PATCH v2 1/1 gpio: lpc32xx: check devm_gpiochip_add_data() return value

In reply to Jayaraj Devaraj

lpc32xx_gpio_probe() registers each gpio chip with devm_gpiochip_add_data() but ignores the return value. If registering a chip fails, probe still returns 0, so the driver binds with a chip missing and no error is reported.

Check the return value, print an error naming the failing chip and return the error code. Chips registered earlier in the loop are devm managed and are removed automatically on failure.

---
v2: use dev_err_probe() as suggested by Bartosz

 drivers/gpio/gpio-lpc32xx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-lpc32xx.c +6 -3
index 37fc54fc7385..7fb46262e18c 100644
@@ -510,7 +510,7 @@ static int lpc32xx_of_xlate(struct gpio_chip *gc,
 
 static int lpc32xx_gpio_probe(struct platform_device *pdev)
 {
-	int i;
+	int i, ret;
 	void __iomem *reg_base;
 
 	reg_base = devm_platform_ioremap_resource(pdev, 0);
@@ -524,8 +524,11 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev)
 			lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
 			lpc32xx_gpiochip[i].reg_base = reg_base;
 		}
-		devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
-				  &lpc32xx_gpiochip[i]);
+		ret = devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
+					     &lpc32xx_gpiochip[i]);
+		if (ret)
+			return dev_err_probe(&pdev->dev, ret,
+					"failed to register gpio chip %d\n", i);
 	}
 
 	return 0;
Signature · 1 line
2.34.1
#4 lore raw
Quoted 5 lines · Jayaraj Devaraj

lpc32xx_gpio_probe() registers each gpio chip with devm_gpiochip_add_data() but ignores the return value. If registering a chip fails, probe still returns 0, so the driver binds with a chip missing and no error is reported.

Quoted 7 lines

Check the return value, print an error naming the failing chip and return the error code. Chips registered earlier in the loop are devm managed and are removed automatically on failure.

---

Please don't send new versions of patches in response to existing threads. They must be new threads. Please consider using b4 for managing patches[1].

Please resend it as a new thread.

Bartosz

[1] https://b4.docs.kernel.org/en/latest/