mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haotian Zhang <vulab@iscas.ac.cn>
To: Linus Walleij <linusw@kernel.org>, Sergey Shtylyov <s.shtylyov@omp.ru>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] pinctrl: core: fix pin name leak on radix_tree_insert() error path
Date: Fri,  9 Oct 2026 13:45:56 +0800	[thread overview]
Message-ID: <20261009054556.3151123-1-vulab@iscas.ac.cn> (raw)

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


             reply	other threads:[~2026-10-09  5:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  5:45 Haotian Zhang [this message]
2026-10-09  6:06 ` Krzysztof Kozlowski
2026-10-09 15:58 ` Sergey Shtylyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261009054556.3151123-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.shtylyov@omp.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®