Thread (2 messages) flat view 2 messages, 2 authors, 10d ago
COOLING10d

[PATCH] pinctrl: imx1-core: fix device_node refcount leak

From: Manush Prajwal <hidden>
Date: 2026-08-13 11:09:59
Also in: imx
Subsystem: pin control subsystem, pin controller - freescale, the rest · Maintainers: Linus Walleij, Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai, Linus Torvalds

imx1_pinctrl_dt_is_flat_functions() iterates child and grandchild
device nodes with for_each_child_of_node() but returns early from
inside both loops without dropping the reference the iterator holds
on the current node. Since the function returns a bool rather than a
node, there is no legitimate reason to keep the reference: call
of_node_put() on both loop variables before the early returns.

Found by inspection; the sibling helper in pinctrl-imx.c avoids this
by using for_each_child_of_node_scoped() instead.

Signed-off-by: Manush Prajwal <redacted>
---
 drivers/pinctrl/freescale/pinctrl-imx1-core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx1-core.c b/drivers/pinctrl/freescale/pinctrl-imx1-core.c
index b7bd4ef9c0..fa8f6a7e03 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx1-core.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx1-core.c
@@ -551,12 +551,17 @@ static bool imx1_pinctrl_dt_is_flat_functions(struct device_node *np)
 	struct device_node *pinctrl_np;
 
 	for_each_child_of_node(np, function_np) {
-		if (of_property_present(function_np, "fsl,pins"))
+		if (of_property_present(function_np, "fsl,pins")) {
+			of_node_put(function_np);
 			return true;
+		}
 
 		for_each_child_of_node(function_np, pinctrl_np) {
-			if (of_property_present(pinctrl_np, "fsl,pins"))
+			if (of_property_present(pinctrl_np, "fsl,pins")) {
+				of_node_put(pinctrl_np);
+				of_node_put(function_np);
 				return false;
+			}
 		}
 	}
 
-- 
2.46.2.windows.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help