Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Lee Jones <lee@kernel.org>
Cc: Dong Aisheng <aisheng.dong@nxp.com>,
	Fabio Estevam <festevam@gmail.com>, Frank Li <Frank.Li@nxp.com>,
	Jacky Bai <ping.bai@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	NXP S32 Linux Team <s32@nxp.com>,
	Linus Walleij <linusw@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Mehmet Fide <mehmet.fide@screeningeagle.com>,
	Gary Bisson <gary.bisson@boundarydevices.com>,
	linux-gpio@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt()
Date: Wed, 2 Dec 2026 11:20:51 -0600	[thread overview]
Message-ID: <axBTc8gxNjfjytW-@SMW015318> (raw)
In-Reply-To: <de2872a5a06de4bb480cbbc0b284f7327844f397.1796203691.git.lee@kernel.org>

On Wed, Dec 02, 2026 at 09:29:58AM +0000, Lee Jones wrote:
> imx_pinctrl_parse_functions() inserts each group descriptor into
> pctl->pin_group_tree before calling imx_pinctrl_parse_groups() and
> ignores the return value of imx_pinctrl_parse_groups().  Likewise,
> imx_pinctrl_probe_dt() ignores the return value of
> imx_pinctrl_parse_functions().  If a device tree group node is malformed
> or a memory allocation fails, partially initialised group descriptors
> with NULL data pointers remain registered in the radix tree and cause a
> NULL pointer dereference when the pinctrl core or debugfs accesses the
> group.
>
> Parse each group before inserting it into pctl->pin_group_tree and
> propagate errors from imx_pinctrl_parse_groups() and
> imx_pinctrl_parse_functions().  Return 0 when a function node has no
> groups so boards with empty controller nodes continue to probe as
> before.
>
> Fixes: e566fc11ea76 ("pinctrl: imx: use generic pinctrl helpers for managing groups")
> Closes: https://sashiko.dev/#/bug/linux-70c60bc4-5868-4c94-b1bb-7073f7a3316c
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>  drivers/pinctrl/freescale/pinctrl-imx.c | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
> index 0a825f58448f..b1114dce3485 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx.c
> @@ -658,7 +658,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
>  	func->ngroups = of_get_child_count(np);
>  	if (func->ngroups == 0) {
>  		dev_info(ipctl->dev, "no groups defined in %pOF\n", np);
> -		return -EINVAL;
> +		return 0;

I think it is correct to allow empty groups, but need seperate patch for
it.

>  	}
>
>  	group_names = devm_kzalloc_objs(ipctl->dev, *group_names, func->ngroups);
> @@ -679,6 +679,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
>  		if (!grp)
>  			return -ENOMEM;
>
> +		ret = imx_pinctrl_parse_groups(child, grp, ipctl, i++);
> +		if (ret)
> +			return ret;
> +
>  		mutex_lock(&ipctl->mutex);
>  		/*
>  		 * FIXME: This should use pinctrl_generic_add_group() and not
> @@ -687,8 +691,6 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
>  		radix_tree_insert(&pctl->pin_group_tree,
>  				  ipctl->group_index++, grp);
>  		mutex_unlock(&ipctl->mutex);
> -
> -		imx_pinctrl_parse_groups(child, grp, ipctl, i++);
>  	}
>
>  	return 0;
> @@ -718,7 +720,6 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
>  				struct imx_pinctrl *ipctl)
>  {
>  	struct device_node *np = pdev->dev.of_node;
> -	struct device_node *child;
>  	struct pinctrl_dev *pctl = ipctl->pctl;
>  	u32 nfuncs = 0;
>  	u32 i = 0;
> @@ -743,16 +744,21 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
>  		pctl->num_groups = of_get_child_count(np);
>  	} else {
>  		pctl->num_groups = 0;
> -		for_each_child_of_node(np, child)
> +		for_each_child_of_node_scoped(np, child)

This one fix difference problem, need seperate patch to fix it

Frank

>  			pctl->num_groups += of_get_child_count(child);
>  	}
>
>  	if (flat_funcs) {
> -		imx_pinctrl_parse_functions(np, ipctl, 0);
> +		return imx_pinctrl_parse_functions(np, ipctl, 0);
>  	} else {
> +		int ret;
> +
>  		i = 0;
> -		for_each_child_of_node(np, child)
> -			imx_pinctrl_parse_functions(child, ipctl, i++);
> +		for_each_child_of_node_scoped(np, child) {
> +			ret = imx_pinctrl_parse_functions(child, ipctl, i++);
> +			if (ret)
> +				return ret;
> +		}
>  	}
>
>  	return 0;
> --
> 2.56.1.911.g883d8bcb20-goog
>
>

  reply	other threads:[~2026-12-02 17:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:29 [PATCH 00/12] pinctrl: Fix Critical and High issues reported by Sashiko (batch 3) Lee Jones
2026-12-02  9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
2026-12-02 16:13   ` Antonio Borneo
2026-12-02  9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
2026-12-02  9:50   ` sashiko-bot
2026-12-02 17:17   ` Frank Li
2026-12-02  9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
2026-12-02 14:08   ` Bartosz Golaszewski
2026-12-02  9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
2026-12-02 17:20   ` Frank Li [this message]
2026-12-02  9:29 ` [PATCH 05/12] pinctrl: tegra: Require at least one register bank in tegra_pinctrl_probe() Lee Jones
2026-12-02  9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
2026-12-02 17:22   ` Frank Li
2026-12-02  9:30 ` [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs Lee Jones
2026-12-02  9:30 ` [PATCH 08/12] pinctrl: keembay: Check src before calling keembay_find_free_slot() Lee Jones
2026-12-02  9:30 ` [PATCH 09/12] pinctrl: ti: iodelay: Protect generic group addition with pctldev->mutex Lee Jones
2026-12-02  9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
2026-12-02  9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
2026-12-02 15:28   ` Antonio Borneo
2026-12-02  9:30 ` [PATCH 12/12] pinctrl: sx150x: Register threaded IRQ after adding GPIO chip Lee Jones
2026-12-02  9:35   ` Neil Armstrong

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=axBTc8gxNjfjytW-@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@nxp.com \
    --cc=aisheng.dong@nxp.com \
    --cc=festevam@gmail.com \
    --cc=gary.bisson@boundarydevices.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=lee@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mehmet.fide@screeningeagle.com \
    --cc=ping.bai@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=s32@nxp.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