Skip to contentSkip to conversation

pinctrl: imx1-core: fix device_node refcount leak

PATCH In review manushprajwal 3 participants 3 messages Aug 14 – Aug 24

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pinctrl: imx1-core: fix device_node refcount leak

From: Manush Prajwal <[email protected]>

imx1_pinctrl_dt_is_flat_functions() iterated child and grandchild device nodes with for_each_child_of_node() but returned early from inside both loops without dropping the reference the iterator held on the current node.

Rework both loops around for_each_child_of_node_scoped() instead of adding manual of_node_put() calls, matching the sibling helper in pinctrl-imx.c and imx1_pinctrl_parse_dt() in this same file, which already use the scoped variant.

---
v2: Use for_each_child_of_node_scoped() instead of manual of_node_put()
calls, per Frank Li's review.

 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..fa8f6a7e03 100644
@@ -547,14 +547,11 @@
  */
 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.46.2.windows.1

Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · manushprajwal

From: Manush Prajwal <[email protected]>

imx1_pinctrl_dt_is_flat_functions() iterated child and grandchild device nodes with for_each_child_of_node() but returned early from inside both loops without dropping the reference the iterator held on the current node.

Quoted 7 lines

Rework both loops around for_each_child_of_node_scoped() instead of adding manual of_node_put() calls, matching the sibling helper in pinctrl-imx.c and imx1_pinctrl_parse_dt() in this same file, which already use the scoped variant.

---

Quoted 29 lines

v2: Use for_each_child_of_node_scoped() instead of manual of_node_put()
calls, per Frank Li's review.

 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..fa8f6a7e03 100644
@@ -547,14 +547,11 @@
  */
 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.46.2.windows.1

#2 lore raw
In reply to manushprajwal

…

Quoted 4 lines

Rework both loops around for_each_child_of_node_scoped() instead of adding manual of_node_put() calls, matching the sibling helper in pinctrl-imx.c and imx1_pinctrl_parse_dt() in this same file, which already use the scoped variant.

How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

See also:
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2#n145
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v7.2#n34

Regards,
Markus