Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Manush Prajwal <manushprajwal555@gmail.com>
Cc: Frank Li <Frank.Li@nxp.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] pinctrl: imx1-core: fix device_node refcount leak
Date: Thu, 13 Aug 2026 11:34:47 -0500	[thread overview]
Message-ID: <an3yJxpt_DvIYLXC@SMW015318> (raw)
In-Reply-To: <20260813110938.1512-1-manushprajwal555@gmail.com>

On Thu, Aug 13, 2026 at 04:39:38PM +0530, Manush Prajwal wrote:
> [You don't often get email from manushprajwal555@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> imx1_pinctrl_dt_is_flat_functions() iterates child and grandchild
> device nodes with for_each_child_of_node() but returns early from
> inside both loops without dropping the reference the iterator holds
> on the current node. Since the function returns a bool rather than a
> node, there is no legitimate reason to keep the reference: call
> of_node_put() on both loop variables before the early returns.
>
> Found by inspection; the sibling helper in pinctrl-imx.c avoids this
> by using for_each_child_of_node_scoped() instead.
>
> Signed-off-by: Manush Prajwal <manushprajwal555@gmail.com>
> ---
>  drivers/pinctrl/freescale/pinctrl-imx1-core.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx1-core.c b/drivers/pinctrl/freescale/pinctrl-imx1-core.c
> index b7bd4ef9c0..fa8f6a7e03 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx1-core.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx1-core.c
> @@ -551,12 +551,17 @@ static bool imx1_pinctrl_dt_is_flat_functions(struct device_node *np)
>         struct device_node *pinctrl_np;
>
>         for_each_child_of_node(np, function_np) {

use for_each_child_of_node_scoped() to fix it.

Frank

> -               if (of_property_present(function_np, "fsl,pins"))
> +               if (of_property_present(function_np, "fsl,pins")) {
> +                       of_node_put(function_np);
>                         return true;
> +               }
>
>                 for_each_child_of_node(function_np, pinctrl_np) {
> -                       if (of_property_present(pinctrl_np, "fsl,pins"))
> +                       if (of_property_present(pinctrl_np, "fsl,pins")) {
> +                               of_node_put(pinctrl_np);
> +                               of_node_put(function_np);
>                                 return false;
> +                       }
>                 }
>         }
>
> --
> 2.46.2.windows.1
>
>


      reply	other threads:[~2026-08-13 16:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 11:09 [PATCH] pinctrl: imx1-core: fix device_node refcount leak Manush Prajwal
2026-08-13 16:34 ` Frank Li [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=an3yJxpt_DvIYLXC@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@nxp.com \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=manushprajwal555@gmail.com \
    --cc=s.hauer@pengutronix.de \
    /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