[PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt()
Lee Jones
lee at kernel.org
Wed Dec 2 01:29:58 PST 2026
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 at vger.kernel.org
Signed-off-by: Lee Jones <lee at 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
More information about the linux-arm-kernel
mailing list