Skip to contentSkip to conversation

pinctrl: freescale: imx1: Fix device node leaks in imx1_pinctrl_dt_is_flat_functions()

PATCH In review Md Rabbani 2 participants 2 messages Aug 21

Subsystems (4)
lore
Share & tools
lore

Md Rabbani

author
#0 lore raw

PATCH 1/1 pinctrl: freescale: imx1: Fix device node leaks in imx1_pinctrl_dt_is_flat_functions()

imx1_pinctrl_dt_is_flat_functions() uses for_each_child_of_node() to iterate over child and grandchild nodes. When the function returns early upon finding an "fsl,pins" property, it does not release the acquired device_node references, leaking their reference counts.

Switch to for_each_child_of_node_scoped() to automatically drop the node references on early return and loop exit, matching the pattern used in pinctrl-imx.c and elsewhere in this driver.

---
 drivers/pinctrl/freescale/pinctrl-imx1-core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx1-core.c +2 -5
index b7bd4ef9c0..4a6bdaefa4 100644
@@ -547,14 +547,11 @@ static int imx1_pinctrl_parse_functions(struct device_node *np,
  */
 static bool imx1_pinctrl_dt_is_flat_functions(struct device_node *np)
 {
-	struct device_node *function_np;
-	struct device_node *pinctrl_np;
-
-	for_each_child_of_node(np, function_np) {
+	for_each_child_of_node_scoped(np, function_np) {
 		if (of_property_present(function_np, "fsl,pins"))
 			return true;
 
-		for_each_child_of_node(function_np, pinctrl_np) {
+		for_each_child_of_node_scoped(function_np, pinctrl_np) {
 			if (of_property_present(pinctrl_np, "fsl,pins"))
 				return false;
 		}
Signature · 1 line
2.55.0.windows.3
#1 lore raw
Quoted 7 lines · Md Rabbani

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

imx1_pinctrl_dt_is_flat_functions() uses for_each_child_of_node() to iterate over child and grandchild nodes. When the function returns early upon finding an "fsl,pins" property, it does not release the acquired device_node references, leaking their reference counts.

Quoted 6 lines

Switch to for_each_child_of_node_scoped() to automatically drop the node references on early return and loop exit, matching the pattern used in pinctrl-imx.c and elsewhere in this driver.

---

Manush Prajwal already post the same patch

https://lore.kernel.org/imx/[email protected]/

Frank

Quoted 28 lines
 drivers/pinctrl/freescale/pinctrl-imx1-core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx1-core.c +2 -6
index b7bd4ef9c0..4a6bdaefa4 100644
@@ -547,14 +547,11 @@ static int imx1_pinctrl_parse_functions(struct device_node *np,
  */
 static bool imx1_pinctrl_dt_is_flat_functions(struct device_node *np)
 {
-       struct device_node *function_np;
-       struct device_node *pinctrl_np;
-
-       for_each_child_of_node(np, function_np) {
+       for_each_child_of_node_scoped(np, function_np) {
                if (of_property_present(function_np, "fsl,pins"))
                        return true;
 
-               for_each_child_of_node(function_np, pinctrl_np) {
+               for_each_child_of_node_scoped(function_np, pinctrl_np) {
                        if (of_property_present(pinctrl_np, "fsl,pins"))
                                return false;
                }
--

2.55.0.windows.3