Skip to contentSkip to conversation

pinctrl: nuvoton: Add missing fwnode_handle_put in wpcm450_gpio_register

PATCH In review Peng Wu 2 participants 2 messages Apr 21, 2022

Subsystems (3)
lore
Share & tools
lore

Peng Wu

author
#0 lore raw

PATCH 1/1 pinctrl: nuvoton: Add missing fwnode_handle_put in wpcm450_gpio_register

In one of the error paths of the device_for_each_child_node() loop in wpcm450_gpio_register, add missing call to fwnode_handle_put.

---
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +17 -6
index 0dbeb91f0bf2..de4388b512d7 100644
@@ -1038,15 +1038,19 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 			continue;
 
 		ret = fwnode_property_read_u32(child, "reg", &reg);
-		if (ret < 0)
+		if (ret < 0) {
+			fwnode_handle_put(child);
 			return ret;
+		}
 
 		gpio = &pctrl->gpio_bank[reg];
 		gpio->pctrl = pctrl;
 
-		if (reg >= WPCM450_NUM_BANKS)
+		if (reg >= WPCM450_NUM_BANKS) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, -EINVAL,
-					     "GPIO index %d out of range!\n", reg);
+					"GPIO index %d out of range!\n", reg);
+		}
 
 		bank = &wpcm450_banks[reg];
 		gpio->bank = bank;
@@ -1060,8 +1064,10 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		}
 		ret = bgpio_init(&gpio->gc, dev, 4,
 				 dat, set, NULL, dirout, NULL, flags);
-		if (ret < 0)
+		if (ret < 0) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, ret, "GPIO initialization failed\n");
+		}
 
 		gpio->gc.ngpio = bank->length;
 		gpio->gc.set_config = wpcm450_gpio_set_config;
@@ -1074,8 +1080,11 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		girq->parent_handler = wpcm450_gpio_irqhandler;
 		girq->parents = devm_kcalloc(dev, WPCM450_NUM_GPIO_IRQS,
 					     sizeof(*girq->parents), GFP_KERNEL);
-		if (!girq->parents)
+		if (!girq->parents) {
+			fwnode_handle_put(child);
 			return -ENOMEM;
+		}
+
 		girq->default_type = IRQ_TYPE_NONE;
 		girq->handler = handle_bad_irq;
 
@@ -1091,8 +1100,10 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		}
 
 		ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
-		if (ret)
+		if (ret) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, ret, "Failed to add GPIO chip\n");
+		}
 	}
 
 	return 0;
Signature · 1 line
2.17.1
#1 lore raw

Hello,

thank you for your patch!

Quoted 2 lines · Peng Wu

In one of the error paths of the device_for_each_child_node() loop in wpcm450_gpio_register, add missing call to fwnode_handle_put.

Your patch changes multiple error patches, not just one of them. Please change the commit message accordingly.

To make it easier to understand for the unfamiliar, please also mention:
- Where fwnode is acquired (in device_for_each_child_node?)
- Where the fwnode is released or used in the success (non-error) path. I think (part of) the answer is: It is assigned to gpio->gc.fwnode

drivers/pinctrl/nuvoton/pinctrl-wpcm450.c static int wpcm450_gpio_register(struct platform_device *pdev, · line 1039

Quoted 13 lines
---
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +0 -0
index 0dbeb91f0bf2..de4388b512d7 100644
@@ -1038,15 +1038,19 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		if (!fwnode_property_read_bool(child, "gpio-controller"))
 			continue;

Does the 'continue' also need a fwnode_handle_put call?

Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +3 -1
 		ret = fwnode_property_read_u32(child, "reg", &reg);
-		if (ret < 0)
+		if (ret < 0) {
+			fwnode_handle_put(child);
 			return ret;
+		}

drivers/pinctrl/nuvoton/pinctrl-wpcm450.c static int wpcm450_gpio_register(struct platform_device *pdev, · line 1052

Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +3 -2
 
 		gpio = &pctrl->gpio_bank[reg];
 		gpio->pctrl = pctrl;
 
-		if (reg >= WPCM450_NUM_BANKS)
+		if (reg >= WPCM450_NUM_BANKS) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, -EINVAL,
-					     "GPIO index %d out of range!\n", reg);
+					"GPIO index %d out of range!\n", reg);

Please leave the indentation as is, in this line.

Quoted 44 lines
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +11 -3
+		}
 
 		bank = &wpcm450_banks[reg];
 		gpio->bank = bank;
@@ -1060,8 +1064,10 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		}
 		ret = bgpio_init(&gpio->gc, dev, 4,
 				 dat, set, NULL, dirout, NULL, flags);
-		if (ret < 0)
+		if (ret < 0) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, ret, "GPIO initialization failed\n");
+		}
 
 		gpio->gc.ngpio = bank->length;
 		gpio->gc.set_config = wpcm450_gpio_set_config;
@@ -1074,8 +1080,11 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		girq->parent_handler = wpcm450_gpio_irqhandler;
 		girq->parents = devm_kcalloc(dev, WPCM450_NUM_GPIO_IRQS,
 					     sizeof(*girq->parents), GFP_KERNEL);
-		if (!girq->parents)
+		if (!girq->parents) {
+			fwnode_handle_put(child);
 			return -ENOMEM;
+		}
+
 		girq->default_type = IRQ_TYPE_NONE;
 		girq->handler = handle_bad_irq;
 
@@ -1091,8 +1100,10 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		}
 
 		ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
-		if (ret)
+		if (ret) {
+			fwnode_handle_put(child);
 			return dev_err_probe(dev, ret, "Failed to add GPIO chip\n");
+		}
 	}
 
 	return 0;
Signature · 1 line
2.17.1

Thanks,
Jonathan