Skip to contentSkip to conversation

sh: make use of for_each_node_by_type()

PATCH RESEND In review Dmitry Torokhov 2 participants 2 messages Jun 24, 2018 – Jun 25, 2018 SuperH

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sh: make use of for_each_node_by_type()

Instead of open-coding the loop, let's use canned macro.

Also make sure we are not leaking "cpus" node reference.

---

 arch/sh/boards/of-generic.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/sh/boards/of-generic.c +4 -3
index 46b2481eec903..26789ad281936 100644
@@ -56,15 +56,15 @@ const struct of_cpu_method __cpu_method_of_table_sentinel
 
 static void sh_of_smp_probe(void)
 {
-	struct device_node *np = 0;
-	const char *method = 0;
+	struct device_node *np;
+	const char *method = NULL;
 	const struct of_cpu_method *m = __cpu_method_of_table;
 
 	pr_info("SH generic board support: scanning for cpus\n");
 
 	init_cpu_possible(cpumask_of(0));
 
-	while ((np = of_find_node_by_type(np, "cpu"))) {
+	for_each_node_by_type(np, "cpu") {
 		const __be32 *cell = of_get_property(np, "reg", NULL);
 		u64 id = -1;
 		if (cell) id = of_read_number(cell, of_n_addr_cells(np));
@@ -80,6 +80,7 @@ static void sh_of_smp_probe(void)
 	if (!method) {
 		np = of_find_node_by_name(NULL, "cpus");
 		of_property_read_string(np, "enable-method", &method);
+		of_node_put(np);
 	}
 
 	pr_info("CPU enable method: %s\n", method);
Signature · 5 lines
2.18.0.rc2.346.g013aa6912e-goog


-- 
Dmitry
#1 lore raw

Hello!

Quoted 5 lines · Dmitry Torokhov

Instead of open-coding the loop, let's use canned macro.

Also make sure we are not leaking "cpus" node reference.

Sounds/looks like a material for 2 separate patches.

Quoted 29 lines

---

  arch/sh/boards/of-generic.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
arch/sh/boards/of-generic.c +3 -3
index 46b2481eec903..26789ad281936 100644
@@ -56,15 +56,15 @@ const struct of_cpu_method __cpu_method_of_table_sentinel
 
  static void sh_of_smp_probe(void)
  {
-	struct device_node *np = 0;
-	const char *method = 0;
+	struct device_node *np;
+	const char *method = NULL;
  	const struct of_cpu_method *m = __cpu_method_of_table;
 
  	pr_info("SH generic board support: scanning for cpus\n");
 
  	init_cpu_possible(cpumask_of(0));
 
-	while ((np = of_find_node_by_type(np, "cpu"))) {
+	for_each_node_by_type(np, "cpu") {
  		const __be32 *cell = of_get_property(np, "reg", NULL);
  		u64 id = -1;
  		if (cell) id = of_read_number(cell, of_n_addr_cells(np));

arch/sh/boards/of-generic.c static void sh_of_smp_probe(void) · line 86

Quoted 7 lines
arch/sh/boards/of-generic.c +1 -0
@@ -80,6 +80,7 @@ static void sh_of_smp_probe(void)
  	if (!method) {
  		np = of_find_node_by_name(NULL, "cpus");
  		of_property_read_string(np, "enable-method", &method);
+		of_node_put(np);
  	}
 
  	pr_info("CPU enable method: %s\n", method);

MBR, Sergei