Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, 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
Cc: stable@vger.kernel.org
Subject: [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt()
Date: Wed,  2 Dec 2026 09:29:58 +0000	[thread overview]
Message-ID: <de2872a5a06de4bb480cbbc0b284f7327844f397.1796203691.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796203691.git.lee@kernel.org>

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;
 	}
 
 	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)
 			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



  parent reply	other threads:[~2026-12-02  9:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1796203691.git.lee@kernel.org>
2026-12-02  9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
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:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
2026-12-02  9:29 ` Lee Jones [this message]
2026-12-02  9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
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 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

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=de2872a5a06de4bb480cbbc0b284f7327844f397.1796203691.git.lee@kernel.org \
    --to=lee@kernel.org \
    --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=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