Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796203920; b=PvEP+clzy36MF0c8dsB+OVTDfDo4lugGuGYpTx6MjtOPmcVdUBmtM6BkByOp6THiUxyD j8tOGHuvBU9LDi2zMluhGiQprk/+r3OQ/q0JsU5rzDepr+83gafwpR5Q++58zk6yt+zkR c9BwWzjOH2uvKuL7MFuMAH8J1/71kCtL6PQFzkljiOuG2Xet4MME1yzxewyYE7dCGrfAO s5MfoHZUrnTvLZCWxK5Kemjib1IJugaNhMnHzdkvMl/zS+SvCtPFPx6YGnOGRTp4FHyYm iGUfo6HRo4XnamhVJjk/jBAcFzpDymxYuVCXEQ/tzOC5f4l50M7MYY0lz+PH7a8RkiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796203920; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=0DfBa23iKlYdmEl3SiSgnN+fa2V4amzQsI/+rrvTCgQ=; b=E8g1rYU4qniBgJ8mzFQ7hslL8ytAYqAtK9F7zsOMwwSuY1aFZp0OA8xbz11wzN9szCUB sjjPc6vY4Z0iN3ecrvxc9FKxP7GOMBBi/m7ut3vjiwKhjoWqbqnmUhLZe7BstbFqBMJv6 +7wDcu7Dr1n6MvRCF0EzVozQ6lMFNPOBg6ZnANu4LU/DGd1Uu5e0ryoMmRNvYl44CkSM/ lIyHX6qaNlElp/kyN82Pu8M1qBPLJVmoDFHOgPcfuk9L/4OsqfOIn1qIH3EAa31DKWWzr DooOGRi16s0HhZrpzE3q1tcF0ZXviGEauUP39bwIT6Ce1VD5dp60X6qdosd/RyAV3sw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NCMOhCuR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B0BE606A332; Wed, 2 Dec 2026 09:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NCMOhCuR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 441CA1F00927; Wed, 2 Dec 2026 09:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796203919; bh=0DfBa23iKlYdmEl3SiSgnN+fa2V4amzQsI/+rrvTCgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NCMOhCuRHD2v18H5xu4hQyCZJbBi5OO3tN6GaFUnqp9tVYXjdPWaowOcN3rQ4zpWb 9ItQsjvDgjy1T8LZs7amcpntQcx9JaTqqLrqb8IDllNigFKq16TYOfAnDSQqKeDGG5 p0SL1C9S1dle64xe+oT0zM0DPjOfJtSjF0NxEMnMRQm+iHlw7I8dLGRbAyRbWSyCEB FDDa74TOb+eXKcMzOcBRnahsYCKuUpAmvORTtbg+R+otDF7jJQWH3yklNtTKtafAOR +b3mmSKk0VHA6daQqB8PS5qGpPClcxsdx+7kPwhMQDyRRpp4xKE5LLEXml3koNzOmf JdxiuSchgm/Pw== From: Lee Jones To: lee@kernel.org, Dong Aisheng , Fabio Estevam , Frank Li , Jacky Bai , Pengutronix Kernel Team , NXP S32 Linux Team , Linus Walleij , Sascha Hauer , Mehmet Fide , Gary Bisson , 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 Message-ID: X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: imx@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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