mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Haotian Zhang <vulab@iscas.ac.cn>, Linus Walleij <linusw@kernel.org>
Cc: <linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] pinctrl: core: fix pin name leak on radix_tree_insert() error path
Date: Fri, 9 Oct 2026 18:58:21 +0300	[thread overview]
Message-ID: <65555593-0e68-4769-bb7e-2737ba7050d1@omp.ru> (raw)
In-Reply-To: <20261009054556.3151123-1-vulab@iscas.ac.cn>

On 10/9/26 8:45 AM, Haotian Zhang wrote:

> 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>
   Oops, my fault indeed! :-(   If you want, you can add my:
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

> 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);

   You may as well add another label here -- for the 1st *goto*...

>         kfree(pindesc);
>         return error;
>  }
[...]
MBR, Sergey


      parent reply	other threads:[~2026-10-09 15:58 UTC|newest]

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

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=65555593-0e68-4769-bb7e-2737ba7050d1@omp.ru \
    --to=s.shtylyov@omp.ru \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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®