linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>
To: "Macpaul Lin" <macpaul.lin@mediatek.com>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	"Nícolas F . R . A . Prado" <nfraprado@collabora.com>,
	"Chen-Yu Tsai" <wenst@chromium.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Cc: Weiyi Lu <Weiyi.Lu@mediatek.com>,
	Jian Hui Lee <jianhui.lee@canonical.com>,
	 Irving-CH Lin <Irving-CH.Lin@mediatek.com>,
	conor@kernel.org, krzk@kernel.org,
	Bear Wang <bear.wang@mediatek.com>,
	 Pablo Sun <pablo.sun@mediatek.com>,
	Ramax Lo <ramax.lo@mediatek.com>, Macpaul Lin <macpaul@gmail.com>,
	 MediaTek Chromebook Upstream
	<Project_Global_Chrome_Upstream_Group@mediatek.com>
Subject: Re: [PATCH] pmdomains: mtk-pm-domains: improve spinlock recursion fix in probe
Date: Wed, 26 Nov 2025 13:51:23 +0100	[thread overview]
Message-ID: <47cb520046a1dab6ea49abd402d3a9647aabf7b0.camel@collabora.com> (raw)
In-Reply-To: <20251125105617.1564725-1-macpaul.lin@mediatek.com>

Hi Macpaul,

On Tue, 2025-11-25 at 18:56 +0800, Macpaul Lin wrote:
> Remove scpsys_get_legacy_regmap() and update usages with
> of_find_node_with_property(). Use an explicit of_node_get(np) to
> ensure
> correct node referencing against of_node_put() and ensuring it is
> called
> in a safe context (i.e., not while holding devtree_lock).
> 
> If fwnode_count_parents() obtains parent nodes via
> fwnode_for_each_parent_node() and this process requires device tree
> operations, it may result in repeated acquisition of devtree_lock in
> the same thread/context, leading to spinlock recursion errors.
> 
> Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
> ---
>  drivers/pmdomain/mediatek/mtk-pm-domains.c | 21 ++++++--------------
> -
>  1 file changed, 6 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c
> b/drivers/pmdomain/mediatek/mtk-pm-domains.c
> index 80561d27f2b2..f64f24d520dd 100644
> --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c
> +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c
> @@ -984,18 +984,6 @@ static void scpsys_domain_cleanup(struct scpsys
> *scpsys)
>  	}
>  }
>  
> -static struct device_node *scpsys_get_legacy_regmap(struct
> device_node *np, const char *pn)
> -{
> -	struct device_node *local_node;
> -
> -	for_each_child_of_node(np, local_node) {
> -		if (of_property_present(local_node, pn))
> -			return local_node;
> -	}
> -
> -	return NULL;
> -}
> -
>  static int scpsys_get_bus_protection_legacy(struct device *dev,
> struct scpsys *scpsys)
>  {
>  	const u8 bp_blocks[3] = {
> @@ -1017,7 +1005,8 @@ static int
> scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
>  	 * this makes it then possible to allocate the array of
> bus_prot
>  	 * regmaps and convert all to the new style handling.
>  	 */
> -	node = scpsys_get_legacy_regmap(np, "mediatek,infracfg");
> +	of_node_get(np);
> +	node = of_find_node_with_property(np, "mediatek,infracfg");

with a kernel based on next-20251125 plus this patch, my Mediatek Genio
350, 510 and 1200 EVK boards booted OK.

About the patch itself, it looks that you try to balance the
of_node_put() done by of_find_node_with_property() on its `from`
parameter (np in this case): 
https://elixir.bootlin.com/linux/v6.18-rc7/source/drivers/of/base.c#L1066

Your patch description is a bit unclear about that and could be
reworded.

I'm not sure if it is the proper way to use the
of_find_node_with_property API, seems a bit hacky. Though, I found 
similar sequences for other of_find_* calls (like
of_find_compatible_node or of_find_node_by_name) in the `from is not
null` case but not all the times. Hope someone else can confirm if
using of_node_get before calling these API is OK.

Finally the patch also misses the Fixes tag since it is a follow up
one.

Regards,
Louis-Alexis

>  	if (node) {
>  		regmap[0] = syscon_regmap_lookup_by_phandle(node,
> "mediatek,infracfg");
>  		of_node_put(node);
> @@ -1030,7 +1019,8 @@ static int
> scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
>  		regmap[0] = NULL;
>  	}
>  
> -	node = scpsys_get_legacy_regmap(np, "mediatek,smi");
> +	of_node_get(np);
> +	node = of_find_node_with_property(np, "mediatek,smi");
>  	if (node) {
>  		smi_np = of_parse_phandle(node, "mediatek,smi", 0);
>  		of_node_put(node);
> @@ -1048,7 +1038,8 @@ static int
> scpsys_get_bus_protection_legacy(struct device *dev, struct scpsys *s
>  		regmap[1] = NULL;
>  	}
>  
> -	node = scpsys_get_legacy_regmap(np, "mediatek,infracfg-
> nao");
> +	of_node_get(np);
> +	node = of_find_node_with_property(np, "mediatek,infracfg-
> nao");
>  	if (node) {
>  		regmap[2] = syscon_regmap_lookup_by_phandle(node,
> "mediatek,infracfg-nao");
>  		num_regmaps++;


  reply	other threads:[~2025-11-26 12:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-25 10:56 [PATCH] pmdomains: mtk-pm-domains: improve spinlock recursion fix in probe Macpaul Lin
2025-11-26 12:51 ` Louis-Alexis Eyraud [this message]
2025-11-28  2:51   ` Macpaul Lin (林智斌)

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=47cb520046a1dab6ea49abd402d3a9647aabf7b0.camel@collabora.com \
    --to=louisalexis.eyraud@collabora.com \
    --cc=Irving-CH.Lin@mediatek.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=Weiyi.Lu@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bear.wang@mediatek.com \
    --cc=conor@kernel.org \
    --cc=jianhui.lee@canonical.com \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=macpaul.lin@mediatek.com \
    --cc=macpaul@gmail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=pablo.sun@mediatek.com \
    --cc=ramax.lo@mediatek.com \
    --cc=ulf.hansson@linaro.org \
    --cc=wenst@chromium.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;
as well as URLs for NNTP newsgroup(s).