Skip to contentSkip to conversation

Driver: clk-qoriq.c: replace of_node_put with _free improves cleanup

PATCH Superseded David Hunter 2 participants 4 messages Aug 20, 2024 – Aug 28, 2024 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Driver: clk-qoriq.c: replace of_node_put with _free improves cleanup

Use the _free function to have automatic clean up instead of calling another function, of_node_put. This prevents leaking reference counts.

The following commit has information on _free(device_node):

9448e55d032d99af8e23487f51a542d51b2f1a48

The code was able to compile without errors or warnings.

---
 drivers/clk/clk-qoriq.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/clk/clk-qoriq.c +1 -4
index 4dcde305944c..941a0372db4b 100644
@@ -1065,11 +1065,8 @@ static void __init _clockgen_init(struct device_node *np, bool legacy);
 static void __init legacy_init_clockgen(struct device_node *np)
 {
 	if (!clockgen.node) {
-		struct device_node *parent_np;
-
-		parent_np = of_get_parent(np);
+		struct device_node __free(device_node) *parent_np = of_get_parent(np);
 		_clockgen_init(parent_np, true);
-		of_node_put(parent_np);
 	}
 }
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Quoting David Hunter (2024-08-19 18:35:49)

Quoted 1 line

Use the _free function to have automatic clean up instead of calling

How about:

Use __free() to have automatic cleanup instead of calling of_node_put() manually.

Quoted 1 line

another function, of_node_put. This prevents leaking reference counts.

Are there any leaking reference counts? I'd just omit that sentence unless there is one.

Quoted 6 lines

The following commit has information on _free(device_node):

9448e55d032d99af8e23487f51a542d51b2f1a48

The code was able to compile without errors or warnings.

The rest of this can go below the triple dash ---

#2 lore raw

PATCH v2 1/1 Driver: clk-qoriq.c: replace of_node_put with _free improves cleanup

Use _free() to have automatic cleanup instead of calling of_node_put() manually.

Compiled without errors or warnings.

---
The following commit has information on _free(device_node):
9448e55d032d99af8e23487f51a542d51b2f1a48

V1 --> V2
- Improved message body
- Use change log to give more information about _free()

---
 drivers/clk/clk-qoriq.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/clk/clk-qoriq.c +1 -4
index 4dcde305944c..941a0372db4b 100644
@@ -1065,11 +1065,8 @@ static void __init _clockgen_init(struct device_node *np, bool legacy);
 static void __init legacy_init_clockgen(struct device_node *np)
 {
 	if (!clockgen.node) {
-		struct device_node *parent_np;
-
-		parent_np = of_get_parent(np);
+		struct device_node __free(device_node) *parent_np = of_get_parent(np);
 		_clockgen_init(parent_np, true);
-		of_node_put(parent_np);
 	}
 }
 
Signature · 1 line
2.43.0
maintainer
#3 lore raw

The subject should be

clk: clk-qoriq: Replace of_node_put() with __free()

Quoting David Hunter (2024-08-20 18:07:39)

Quoted 1 line

Use _free() to have automatic cleanup instead of calling of_node_put()

__free()

Quoted 4 lines

manually.

Compiled without errors or warnings.

Quoted 8 lines

---
The following commit has information on _free(device_node):
9448e55d032d99af8e23487f51a542d51b2f1a48

V1 --> V2
- Improved message body
- Use change log to give more information about _free()

Please don't send the next version as a reply to the previous patch.

Quoted 9 lines
---
 drivers/clk/clk-qoriq.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/clk/clk-qoriq.c +0 -0
index 4dcde305944c..941a0372db4b 100644

drivers/clk/clk-qoriq.c static void __init _clockgen_init(struct device_node *np, bool legacy); · line 1068

Quoted 7 lines
drivers/clk/clk-qoriq.c +1 -3
@@ -1065,11 +1065,8 @@ static void __init _clockgen_init(struct device_node *np, bool legacy);
 static void __init legacy_init_clockgen(struct device_node *np)
 {
        if (!clockgen.node) {
-               struct device_node *parent_np;
-
-               parent_np = of_get_parent(np);
+               struct device_node __free(device_node) *parent_np = of_get_parent(np);

It seems the __free() comes after the variable name declaration if my grep skills are working today.

Also, please include linux/cleanup.h at the top of the file for __free().

Quoted 4 lines
drivers/clk/clk-qoriq.c +0 -1
                _clockgen_init(parent_np, true);
-               of_node_put(parent_np);
        }
 }