mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pinctrl: core: fix pin name leak on radix_tree_insert() error path
@ 2026-10-09  5:45 Haotian Zhang
  2026-10-09  6:06 ` Krzysztof Kozlowski
  2026-10-09 15:58 ` Sergey Shtylyov
  0 siblings, 2 replies; 3+ messages in thread
From: Haotian Zhang @ 2026-10-09  5:45 UTC (permalink / raw)
  To: Linus Walleij, Sergey Shtylyov; +Cc: linux-gpio, linux-kernel

pinctrl_register_one_pin() allocates pindesc->name with kasprintf() when
the pin has no static name, and marks it with pindesc->dynamic_name.  If
the subsequent radix_tree_insert() fails, the function jumps to the
failed label, which only calls kfree(pindesc) and never frees the
dynamically allocated name, leaking it.

Since the insertion failed, the pin is not in the radix tree, so the
caller's pinctrl_free_pindescs() cleanup cannot find it and cannot
release the name either.

Release pindesc->name on the failed path when it was dynamically
allocated.

Fixes: ecfe9a015d3e ("pinctrl: core: handle radix_tree_insert() errors in pinctrl_register_one_pin()")
Assisted-by: DeepSeek-V4.1-Flash
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/pinctrl/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 1675dd36bd5c..3a1d1ff871ef 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -249,6 +249,8 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
 	return 0;
 
 failed:
+	if (pindesc->dynamic_name)
+		kfree(pindesc->name);
 	kfree(pindesc);
 	return error;
 }
-- 
2.25.1


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

end of thread, other threads:[~2026-10-09 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09  5:45 [PATCH] pinctrl: core: fix pin name leak on radix_tree_insert() error path Haotian Zhang
2026-10-09  6:06 ` Krzysztof Kozlowski
2026-10-09 15:58 ` Sergey Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®