Skip to contentSkip to conversation

pinctrl: pinctrl-pic32: Fix resource leak and convert last manual allocation to devres

PATCH In review Ethan Tidmore 2 participants 4 messages Feb 27 – Mar 2

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

v2 cover pinctrl: pinctrl-pic32: Fix resource leak and convert last manual allocation to devres

I made this a series so it's easier to backport the bugfix.

Ethan Tidmore (2):
pinctrl: pinctrl-pic32: Fix resource leak
pinctrl: pinctrl-pic32: Use devres version of gpiochip_add_data()

 drivers/pinctrl/pinctrl-pic32.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 pinctrl: pinctrl-pic32: Fix resource leak

Fix three possible resource leaks by using the devres version of clk_prepare_enable(). Also, update error message accordingly.

Detected by Smatch:
drivers/pinctrl/pinctrl-pic32.c:2211 pic32_pinctrl_probe() warn:
'pctl->clk' from clk_prepare_enable() not released on lines: 2208.

drivers/pinctrl/pinctrl-pic32.c:2274 pic32_gpio_probe() warn:
'bank->clk' from clk_prepare_enable() not released on lines: 2264,2272.

Fixes 2ba384e6c3810 ("pinctrl: pinctrl-pic32: Add PIC32 pin control driver")

---
v2:
- Use devres instead of manual cleanup.

 drivers/pinctrl/pinctrl-pic32.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/pinctrl/pinctrl-pic32.c +4 -16
index eb438c9d9667..d185fe48dc0d 100644
@@ -2174,16 +2174,10 @@ static int pic32_pinctrl_probe(struct platform_device *pdev)
 	if (IS_ERR(pctl->reg_base))
 		return PTR_ERR(pctl->reg_base);
 
-	pctl->clk = devm_clk_get(&pdev->dev, NULL);
+	pctl->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(pctl->clk)) {
 		ret = PTR_ERR(pctl->clk);
-		dev_err(&pdev->dev, "clk get failed\n");
-		return ret;
-	}
-
-	ret = clk_prepare_enable(pctl->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "clk enable failed\n");
+		dev_err(&pdev->dev, "Failed to get and enable clock\n");
 		return ret;
 	}
 
@@ -2239,16 +2233,10 @@ static int pic32_gpio_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	bank->clk = devm_clk_get(&pdev->dev, NULL);
+	bank->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(bank->clk)) {
 		ret = PTR_ERR(bank->clk);
-		dev_err(&pdev->dev, "clk get failed\n");
-		return ret;
-	}
-
-	ret = clk_prepare_enable(bank->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "clk enable failed\n");
+		dev_err(&pdev->dev, "Failed to get and enable clock\n");
 		return ret;
 	}
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/2 pinctrl: pinctrl-pic32: Use devres version of gpiochip_add_data()

In reply to Ethan Tidmore

Convert gpiochip_add_data() to devm_gpiochip_add_data() to use devres style cleanup across entire driver.

---
v2:
- Made this a series, added this patch.

 drivers/pinctrl/pinctrl-pic32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-pic32.c +1 -1
index d185fe48dc0d..07a24e17d35b 100644
@@ -2253,7 +2253,7 @@ static int pic32_gpio_probe(struct platform_device *pdev)
 	girq->default_type = IRQ_TYPE_NONE;
 	girq->handler = handle_level_irq;
 	girq->parents[0] = irq;
-	ret = gpiochip_add_data(&bank->gpio_chip, bank);
+	ret = devm_gpiochip_add_data(&pdev->dev, &bank->gpio_chip, bank);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to add GPIO chip %u: %d\n",
 			id, ret);
Signature · 1 line
2.53.0
maintainer
#3 lore raw
In reply to Ethan Tidmore
Quoted 5 lines · Ethan Tidmore

I made this a series so it's easier to backport the bugfix.

Ethan Tidmore (2):
pinctrl: pinctrl-pic32: Fix resource leak
pinctrl: pinctrl-pic32: Use devres version of gpiochip_add_data()

Patches applied as nonurgent fixes, thanks Ethan!

Yours,
Linus Walleij