linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: devicetree: fix refcount leak in pinctrl_dt_to_map()
@ 2024-04-15 10:53 Zeng Heng
  2024-04-15 11:08 ` Dan Carpenter
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Zeng Heng @ 2024-04-15 10:53 UTC (permalink / raw)
  To: linus.walleij
  Cc: linux-kernel, xiexiuqi, linux-gpio, weiyongjun1, dan.carpenter, liwei391

If we fail to allocate propname buffer, we need to drop the reference
count we just took. Because the pinctrl_dt_free_maps() includes the
droping operation, here we call it directly.

Fixes: 91d5c5060ee2 ("pinctrl: devicetree: fix null pointer dereferencing in pinctrl_dt_to_map")
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Zeng Heng <zengheng4@huawei.com>
---
 drivers/pinctrl/devicetree.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index df1efc2e5202..6a94ecd6a8de 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -220,14 +220,16 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
 	for (state = 0; ; state++) {
 		/* Retrieve the pinctrl-* property */
 		propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
-		if (!propname)
-			return -ENOMEM;
+		if (!propname) {
+			ret = -ENOMEM;
+			goto err;
+		}
 		prop = of_find_property(np, propname, &size);
 		kfree(propname);
 		if (!prop) {
 			if (state == 0) {
-				of_node_put(np);
-				return -ENODEV;
+				ret = -ENODEV;
+				goto err;
 			}
 			break;
 		}
-- 
2.25.1


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

end of thread, other threads:[~2024-04-19 13:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 10:53 [PATCH] pinctrl: devicetree: fix refcount leak in pinctrl_dt_to_map() Zeng Heng
2024-04-15 11:08 ` Dan Carpenter
2024-04-15 16:36 ` Markus Elfring
2024-04-16 13:33 ` Linus Walleij
2024-04-17 15:30 ` Andy Shevchenko
2024-04-17 15:38   ` Dan Carpenter
2024-04-17 17:12     ` Andy Shevchenko
2024-04-17 17:49       ` Dan Carpenter
2024-04-18 10:05         ` Andy Shevchenko
2024-04-19 13:24         ` 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).