From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Ma Ke <make_ruc2021@163.com>
Cc: antonio.borneo@foss.st.com, linusw@kernel.org,
mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
fabien.dessenne@foss.st.com, linux-gpio@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
stable@vger.kernel.org
Subject: Re: [PATCH] pinctrl: stm32: Fix fwnode reference leak in stm32_gpiolib_register_bank()
Date: Tue, 13 Oct 2026 16:16:42 +0300 [thread overview]
Message-ID: <as4vOoSRE0zjh8NT@ashevche-desk.local> (raw)
In-Reply-To: <20261011061722.3159941-1-make_ruc2021@163.com>
On Sun, Oct 11, 2026 at 02:17:22PM +0800, Ma Ke wrote:
> stm32_gpiolib_register_bank() walks the "gpio-ranges" property with
> fwnode_property_get_reference_args(). As documented in
> drivers/base/property.c:
>
> * The caller is responsible for calling fwnode_handle_put() on the
> * returned @args->fwnode pointer.
>
> The returned reference is never put. The function calls the helper
> twice, once directly and then repeatedly in a while loop, and each
> call overwrites args, so only the last reference is even reachable
> and all the earlier ones are leaked for good.
>
> Put the reference as soon as args.args[] has been consumed, both for
> the initial call and for every iteration of the loop.
>
> Found by code review.
...
> /* get the last defined gpio line (offset + nb of pins) */
> npins = args.args[0] + args.args[2];
> - while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args))
> + fwnode_handle_put(args.fwnode);
> +
> + while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) {
> npins = max(npins, (int)(args.args[0] + args.args[2]));
> + fwnode_handle_put(args.fwnode);
> + }
Can we use GPIOLIB facility to fulfil the task? Yeah, it seems non-trivial
change, so for the quick fix the above seems okay.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-10-13 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 6:17 Ma Ke
2026-10-11 9:27 ` Antonio Borneo
2026-10-13 13:16 ` Andy Shevchenko [this message]
2026-10-13 23:37 ` Linus Walleij
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=as4vOoSRE0zjh8NT@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexandre.torgue@foss.st.com \
--cc=antonio.borneo@foss.st.com \
--cc=fabien.dessenne@foss.st.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=make_ruc2021@163.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=stable@vger.kernel.org \
/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®