linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: nomadik: fix possible object reference leak
@ 2019-02-15  8:01 WangBo
  2019-02-20  9:53 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: WangBo @ 2019-02-15  8:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: linus.walleij, linux-gpio, linux-arm-kernel, wang.bo116

The of_find_device_by_node takes a reference to the struct device
when find the match device ,we should release it when fail.

Signed-off-by: WangBo <wang.bo116@zte.com.cn>
---
 drivers/pinctrl/nomadik/pinctrl-nomadik.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
index 4cc2c47f8778..ec02739bd21b 100644
--- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c
+++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
@@ -1056,17 +1056,22 @@ static struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np,
 	}
 	if (of_property_read_u32(np, "gpio-bank", &id)) {
 		dev_err(&pdev->dev, "populate: gpio-bank property not found\n");
+		platform_device_put(gpio_pdev);
 		return ERR_PTR(-EINVAL);
 	}
 
 	/* Already populated? */
 	nmk_chip = nmk_gpio_chips[id];
-	if (nmk_chip)
+	if (nmk_chip) {
+		platform_device_put(gpio_pdev);
 		return nmk_chip;
+	}
 
 	nmk_chip = devm_kzalloc(&pdev->dev, sizeof(*nmk_chip), GFP_KERNEL);
-	if (!nmk_chip)
+	if (!nmk_chip) {
+		platform_device_put(gpio_pdev);
 		return ERR_PTR(-ENOMEM);
+	}
 
 	nmk_chip->bank = id;
 	chip = &nmk_chip->chip;
@@ -1077,13 +1082,17 @@ static struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np,
 
 	res = platform_get_resource(gpio_pdev, IORESOURCE_MEM, 0);
 	base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(base))
+	if (IS_ERR(base)) {
+		platform_device_put(gpio_pdev);
 		return ERR_CAST(base);
+	}
 	nmk_chip->addr = base;
 
 	clk = clk_get(&gpio_pdev->dev, NULL);
-	if (IS_ERR(clk))
+	if (IS_ERR(clk)) {
+		platform_device_put(gpio_pdev);
 		return (void *) clk;
+	}
 	clk_prepare(clk);
 	nmk_chip->clk = clk;
 
-- 
2.15.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pinctrl: nomadik: fix possible object reference leak
  2019-02-15  8:01 [PATCH] pinctrl: nomadik: fix possible object reference leak WangBo
@ 2019-02-20  9:53 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2019-02-20  9:53 UTC (permalink / raw)
  To: WangBo; +Cc: linux-kernel, open list:GPIO SUBSYSTEM, Linux ARM, wang.bo116

On Fri, Feb 15, 2019 at 9:01 AM WangBo <wdjjwb@163.com> wrote:

> The of_find_device_by_node takes a reference to the struct device
> when find the match device ,we should release it when fail.
>
> Signed-off-by: WangBo <wang.bo116@zte.com.cn>

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-20  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15  8:01 [PATCH] pinctrl: nomadik: fix possible object reference leak WangBo
2019-02-20  9:53 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).