linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] sh: make use of for_each_node_by_type()
@ 2018-06-24 22:42 Dmitry Torokhov
  2018-06-25  9:23 ` Sergei Shtylyov
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2018-06-24 22:42 UTC (permalink / raw)
  To: Rich Felker; +Cc: Yoshinori Sato, linux-sh, linux-kernel

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

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

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 arch/sh/boards/of-generic.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
index 46b2481eec903..26789ad281936 100644
--- a/arch/sh/boards/of-generic.c
+++ b/arch/sh/boards/of-generic.c
@@ -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);
-- 
2.18.0.rc2.346.g013aa6912e-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH] sh: make use of for_each_node_by_type()
  2018-06-24 22:42 [RESEND PATCH] sh: make use of for_each_node_by_type() Dmitry Torokhov
@ 2018-06-25  9:23 ` Sergei Shtylyov
  0 siblings, 0 replies; 2+ messages in thread
From: Sergei Shtylyov @ 2018-06-25  9:23 UTC (permalink / raw)
  To: Dmitry Torokhov, Rich Felker; +Cc: Yoshinori Sato, linux-sh, linux-kernel

Hello!

On 6/25/2018 1:42 AM, Dmitry Torokhov wrote:

> Instead of open-coding the loop, let's use canned macro.
> 
> Also make sure we are not leaking "cpus" node reference.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

    Sounds/looks like a material for 2 separate patches.

> ---
> 
>   arch/sh/boards/of-generic.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
> index 46b2481eec903..26789ad281936 100644
> --- a/arch/sh/boards/of-generic.c
> +++ b/arch/sh/boards/of-generic.c
> @@ -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);

MBR, Sergei

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-25  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-24 22:42 [RESEND PATCH] sh: make use of for_each_node_by_type() Dmitry Torokhov
2018-06-25  9:23 ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).