All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
To: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Kees Cook <kees@kernel.org>, Weigang He <geoffreyhe2@gmail.com>,
	Daniel Palmer <daniel@thingy.jp>,
	Benjamin Krill <ben@codiert.org>,
	David Woodhouse <David.Woodhouse@intel.com>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mtd: parsers: ofpart: call of_node_put() only in ofpart_fail path
Date: Thu, 12 Mar 2026 12:29:27 +0100	[thread overview]
Message-ID: <abKjlwKu-UntV5Fu@tom-desktop> (raw)
In-Reply-To: <20260311153957.1984446-2-cosmin-gabriel.tanislav.xa@renesas.com>

On Wed, Mar 11, 2026 at 05:39:56PM +0200, Cosmin Tanislav wrote:
> ofpart_none can only be reached after the for_each_child_of_node() loop
> finishes. for_each_child_of_node() correctly calls of_node_put() for all
> device nodes it iterates over as long as we don't break or jump out of
> the loop.
> 
> Calling of_node_put() inside the ofpart_none path will wrongly decrement
> the ref count of the last node in the for_each_child_of_node() loop.
> 
> Move the call to of_node_put() under the ofpart_fail label to fix this.
> 

Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>

> Fixes: ebd5a74db74e ("mtd: ofpart: Check availability of reg property instead of name property")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> ---
>  drivers/mtd/parsers/ofpart_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart_core.c
> index 0029bda165bd..181ae9616b2e 100644
> --- a/drivers/mtd/parsers/ofpart_core.c
> +++ b/drivers/mtd/parsers/ofpart_core.c
> @@ -195,11 +195,11 @@ static int parse_fixed_partitions(struct mtd_info *master,
>  ofpart_fail:
>  	pr_err("%s: error parsing ofpart partition %pOF (%pOF)\n",
>  	       master->name, pp, mtd_node);
> +	of_node_put(pp);
>  	ret = -EINVAL;
>  ofpart_none:
>  	if (dedicated)
>  		of_node_put(ofpart_node);
> -	of_node_put(pp);
>  	kfree(parts);
>  	return ret;
>  }
> -- 
> 2.53.0
> 

Kind Regards,
Tommaso

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

WARNING: multiple messages have this Message-ID (diff)
From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
To: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Kees Cook <kees@kernel.org>, Weigang He <geoffreyhe2@gmail.com>,
	Daniel Palmer <daniel@thingy.jp>,
	Benjamin Krill <ben@codiert.org>,
	David Woodhouse <David.Woodhouse@intel.com>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mtd: parsers: ofpart: call of_node_put() only in ofpart_fail path
Date: Thu, 12 Mar 2026 12:29:27 +0100	[thread overview]
Message-ID: <abKjlwKu-UntV5Fu@tom-desktop> (raw)
In-Reply-To: <20260311153957.1984446-2-cosmin-gabriel.tanislav.xa@renesas.com>

On Wed, Mar 11, 2026 at 05:39:56PM +0200, Cosmin Tanislav wrote:
> ofpart_none can only be reached after the for_each_child_of_node() loop
> finishes. for_each_child_of_node() correctly calls of_node_put() for all
> device nodes it iterates over as long as we don't break or jump out of
> the loop.
> 
> Calling of_node_put() inside the ofpart_none path will wrongly decrement
> the ref count of the last node in the for_each_child_of_node() loop.
> 
> Move the call to of_node_put() under the ofpart_fail label to fix this.
> 

Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>

> Fixes: ebd5a74db74e ("mtd: ofpart: Check availability of reg property instead of name property")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> ---
>  drivers/mtd/parsers/ofpart_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart_core.c
> index 0029bda165bd..181ae9616b2e 100644
> --- a/drivers/mtd/parsers/ofpart_core.c
> +++ b/drivers/mtd/parsers/ofpart_core.c
> @@ -195,11 +195,11 @@ static int parse_fixed_partitions(struct mtd_info *master,
>  ofpart_fail:
>  	pr_err("%s: error parsing ofpart partition %pOF (%pOF)\n",
>  	       master->name, pp, mtd_node);
> +	of_node_put(pp);
>  	ret = -EINVAL;
>  ofpart_none:
>  	if (dedicated)
>  		of_node_put(ofpart_node);
> -	of_node_put(pp);
>  	kfree(parts);
>  	return ret;
>  }
> -- 
> 2.53.0
> 

Kind Regards,
Tommaso

  reply	other threads:[~2026-03-12 11:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 15:39 [PATCH 0/2] MTD fixes for OF node refcounting Cosmin Tanislav
2026-03-11 15:39 ` Cosmin Tanislav
2026-03-11 15:39 ` [PATCH 1/2] mtd: parsers: ofpart: call of_node_put() only in ofpart_fail path Cosmin Tanislav
2026-03-11 15:39   ` Cosmin Tanislav
2026-03-12 11:29   ` Tommaso Merciai [this message]
2026-03-12 11:29     ` Tommaso Merciai
2026-03-11 15:39 ` [PATCH 2/2] mtd: parsers: ofpart: call of_node_get() for dedicated subpartitions Cosmin Tanislav
2026-03-11 15:39   ` Cosmin Tanislav
2026-03-12 11:27   ` Tommaso Merciai
2026-03-12 11:27     ` Tommaso Merciai
2026-03-16 16:37 ` [PATCH 0/2] MTD fixes for OF node refcounting Miquel Raynal
2026-03-16 16:37   ` Miquel Raynal

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=abKjlwKu-UntV5Fu@tom-desktop \
    --to=tommaso.merciai.xr@bp.renesas.com \
    --cc=David.Woodhouse@intel.com \
    --cc=ben@codiert.org \
    --cc=cosmin-gabriel.tanislav.xa@renesas.com \
    --cc=daniel@thingy.jp \
    --cc=geoffreyhe2@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.