* [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it
@ 2017-02-01 1:54 Dmitry Torokhov
2017-02-01 1:54 ` [PATCH 2/2] powerpc: make use of for_each_node_by_type() " Dmitry Torokhov
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2017-02-01 1:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras
Cc: Michael Ellerman, Scott Wood, Kumar Gala, Arnd Bergmann,
linuxppc-dev, linux-kernel
Instead of manually coding the loop with of_find_node_by_name(), let's
switch to the standard macro for iterating over nodes with given name.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
arch/powerpc/platforms/83xx/mpc832x_mds.c | 2 +-
arch/powerpc/platforms/83xx/mpc832x_rdb.c | 2 +-
arch/powerpc/platforms/83xx/mpc836x_mds.c | 2 +-
arch/powerpc/platforms/cell/interrupt.c | 3 +--
arch/powerpc/platforms/cell/setup.c | 3 +--
arch/powerpc/platforms/cell/spider-pic.c | 3 +--
arch/powerpc/platforms/powermac/feature.c | 2 +-
7 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/83xx/mpc832x_mds.c b/arch/powerpc/platforms/83xx/mpc832x_mds.c
index bb7b25acf26f..1e92f806ee60 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_mds.c
@@ -75,7 +75,7 @@ static void __init mpc832x_sys_setup_arch(void)
par_io_init(np);
of_node_put(np);
- for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
+ for_each_node_by_name(np. "ucc")
par_io_of_config(np);
}
diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
index d7c9b186954d..3dcbe06cf36c 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
@@ -204,7 +204,7 @@ static void __init mpc832x_rdb_setup_arch(void)
par_io_init(np);
of_node_put(np);
- for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
+ for_each_node_by_name(np, "ucc")
par_io_of_config(np);
}
#endif /* CONFIG_QUICC_ENGINE */
diff --git a/arch/powerpc/platforms/83xx/mpc836x_mds.c b/arch/powerpc/platforms/83xx/mpc836x_mds.c
index 4fc3051c2b2e..fd44dd03e1f3 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_mds.c
@@ -83,7 +83,7 @@ static void __init mpc836x_mds_setup_arch(void)
par_io_init(np);
of_node_put(np);
- for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
+ for_each_node_by_name(np, "ucc")
par_io_of_config(np);
#ifdef CONFIG_QE_USB
/* Must fixup Par IO before QE GPIO chips are registered. */
diff --git a/arch/powerpc/platforms/cell/interrupt.c b/arch/powerpc/platforms/cell/interrupt.c
index a6bbbaba14a3..477a1fdd3ee1 100644
--- a/arch/powerpc/platforms/cell/interrupt.c
+++ b/arch/powerpc/platforms/cell/interrupt.c
@@ -315,8 +315,7 @@ static int __init setup_iic(void)
struct cbe_iic_regs __iomem *node_iic;
const u32 *np;
- for (dn = NULL;
- (dn = of_find_node_by_name(dn,"interrupt-controller")) != NULL;) {
+ for_each_node_by_name(dn, "interrupt-controller") {
if (!of_device_is_compatible(dn,
"IBM,CBEA-Internal-Interrupt-Controller"))
continue;
diff --git a/arch/powerpc/platforms/cell/setup.c b/arch/powerpc/platforms/cell/setup.c
index d3543e68efe8..7d31b8d14661 100644
--- a/arch/powerpc/platforms/cell/setup.c
+++ b/arch/powerpc/platforms/cell/setup.c
@@ -192,8 +192,7 @@ static void __init mpic_init_IRQ(void)
struct device_node *dn;
struct mpic *mpic;
- for (dn = NULL;
- (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
+ for_each_node_by_name(dn, "interrupt-controller") {
if (!of_device_is_compatible(dn, "CBEA,platform-open-pic"))
continue;
diff --git a/arch/powerpc/platforms/cell/spider-pic.c b/arch/powerpc/platforms/cell/spider-pic.c
index ff924af00e78..a0454b031e6f 100644
--- a/arch/powerpc/platforms/cell/spider-pic.c
+++ b/arch/powerpc/platforms/cell/spider-pic.c
@@ -343,8 +343,7 @@ void __init spider_init_IRQ(void)
* device-tree is bogus anyway) so all we can do is pray or maybe test
* the address and deduce the node-id
*/
- for (dn = NULL;
- (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
+ for_each_node_by_name(dn, "interrupt-controller") {
if (of_device_is_compatible(dn, "CBEA,platform-spider-pic")) {
if (of_address_to_resource(dn, 0, &r)) {
printk(KERN_WARNING "spider-pic: Failed\n");
diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platforms/powermac/feature.c
index 730e48111848..86ce02f15593 100644
--- a/arch/powerpc/platforms/powermac/feature.c
+++ b/arch/powerpc/platforms/powermac/feature.c
@@ -2641,7 +2641,7 @@ static void __init probe_one_macio(const char *name, const char *compat, int typ
phys_addr_t addr;
u64 size;
- for (node = NULL; (node = of_find_node_by_name(node, name)) != NULL;) {
+ for_each_node_by_name(node, name) {
if (!compat)
break;
if (of_device_is_compatible(node, compat))
--
2.11.0.483.g087da7b7c-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] powerpc: make use of for_each_node_by_type() instead of open-coding it
2017-02-01 1:54 [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it Dmitry Torokhov
@ 2017-02-01 1:54 ` Dmitry Torokhov
2018-01-17 13:29 ` [2/2] " Michael Ellerman
2017-02-01 2:20 ` [PATCH 1/2] powerpc: make use of for_each_node_by_name() " Dmitry Torokhov
2017-12-12 11:39 ` [1/2] " Michael Ellerman
2 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2017-02-01 1:54 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras
Cc: Michael Ellerman, Scott Wood, Kumar Gala, Arnd Bergmann,
linuxppc-dev, linux-kernel
Instead of manually coding the loop with of_find_node_by_type(), let's
switch to the standard macro for iterating over nodes with given type.
Also fixed a couple of refcount leaks in the aforementioned loops.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
arch/powerpc/kernel/setup-common.c | 9 +++++++--
arch/powerpc/platforms/cell/spu_manage.c | 4 ++--
arch/powerpc/platforms/powermac/pic.c | 7 ++++---
arch/powerpc/platforms/powermac/smp.c | 4 ++--
arch/powerpc/platforms/pseries/lparcfg.c | 4 ++--
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index f516ac508ae3..4a36360c0a67 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -452,13 +452,13 @@ static void __init cpu_init_thread_core_maps(int tpc)
*/
void __init smp_setup_cpu_maps(void)
{
- struct device_node *dn = NULL;
+ struct device_node *dn;
int cpu = 0;
int nthreads = 1;
DBG("smp_setup_cpu_maps()\n");
- while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < nr_cpu_ids) {
+ for_each_node_by_type(dn, "cpu") {
const __be32 *intserv;
__be32 cpu_be;
int j, len;
@@ -498,6 +498,11 @@ void __init smp_setup_cpu_maps(void)
set_cpu_possible(cpu, true);
cpu++;
}
+
+ if (cpu >= nr_cpu_ids) {
+ of_node_put(dn);
+ break;
+ }
}
/* If no SMT supported, nthreads is forced to 1 */
diff --git a/arch/powerpc/platforms/cell/spu_manage.c b/arch/powerpc/platforms/cell/spu_manage.c
index 672d310dcf14..4a28d647911c 100644
--- a/arch/powerpc/platforms/cell/spu_manage.c
+++ b/arch/powerpc/platforms/cell/spu_manage.c
@@ -292,12 +292,12 @@ static int __init of_enumerate_spus(int (*fn)(void *data))
unsigned int n = 0;
ret = -ENODEV;
- for (node = of_find_node_by_type(NULL, "spe");
- node; node = of_find_node_by_type(node, "spe")) {
+ for_each_node_by_type(node, "spe") {
ret = fn(node);
if (ret) {
printk(KERN_WARNING "%s: Error initializing %s\n",
__func__, node->name);
+ of_node_put(node);
break;
}
n++;
diff --git a/arch/powerpc/platforms/powermac/pic.c b/arch/powerpc/platforms/powermac/pic.c
index f5f9ad7c3398..057c0c4003ae 100644
--- a/arch/powerpc/platforms/powermac/pic.c
+++ b/arch/powerpc/platforms/powermac/pic.c
@@ -486,15 +486,16 @@ static int __init pmac_pic_probe_mpic(void)
struct device_node *np, *master = NULL, *slave = NULL;
/* We can have up to 2 MPICs cascaded */
- for (np = NULL; (np = of_find_node_by_type(np, "open-pic"))
- != NULL;) {
+ for_each_node_by_type(np, "open-pic") {
if (master == NULL &&
of_get_property(np, "interrupts", NULL) == NULL)
master = of_node_get(np);
else if (slave == NULL)
slave = of_node_get(np);
- if (master && slave)
+ if (master && slave) {
+ of_node_put(np);
break;
+ }
}
/* Check for bogus setups */
diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
index c9eb7d6540ea..1109850d12bd 100644
--- a/arch/powerpc/platforms/powermac/smp.c
+++ b/arch/powerpc/platforms/powermac/smp.c
@@ -772,8 +772,8 @@ static void __init smp_core99_probe(void)
if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
/* Count CPUs in the device-tree */
- for (cpus = NULL; (cpus = of_find_node_by_type(cpus, "cpu")) != NULL;)
- ++ncpus;
+ for_each_node_by_type(cpus, "cpu")
+ ++ncpus;
printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
index 779fc2a1c8f7..1c1668c6b8c7 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -370,10 +370,10 @@ static void parse_system_parameter_string(struct seq_file *m)
*/
static int lparcfg_count_active_processors(void)
{
- struct device_node *cpus_dn = NULL;
+ struct device_node *cpus_dn;
int count = 0;
- while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
+ for_each_node_by_type(cpus_dn, "cpu") {
#ifdef LPARCFG_DEBUG
printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
#endif
--
2.11.0.483.g087da7b7c-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it
2017-02-01 1:54 [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it Dmitry Torokhov
2017-02-01 1:54 ` [PATCH 2/2] powerpc: make use of for_each_node_by_type() " Dmitry Torokhov
@ 2017-02-01 2:20 ` Dmitry Torokhov
2017-12-12 11:39 ` [1/2] " Michael Ellerman
2 siblings, 0 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2017-02-01 2:20 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras
Cc: Michael Ellerman, Scott Wood, Kumar Gala, Arnd Bergmann,
linuxppc-dev, linux-kernel
On Tue, Jan 31, 2017 at 05:54:37PM -0800, Dmitry Torokhov wrote:
> Instead of manually coding the loop with of_find_node_by_name(), let's
> switch to the standard macro for iterating over nodes with given name.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> arch/powerpc/platforms/83xx/mpc832x_mds.c | 2 +-
> arch/powerpc/platforms/83xx/mpc832x_rdb.c | 2 +-
> arch/powerpc/platforms/83xx/mpc836x_mds.c | 2 +-
> arch/powerpc/platforms/cell/interrupt.c | 3 +--
> arch/powerpc/platforms/cell/setup.c | 3 +--
> arch/powerpc/platforms/cell/spider-pic.c | 3 +--
> arch/powerpc/platforms/powermac/feature.c | 2 +-
> 7 files changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/arch/powerpc/platforms/83xx/mpc832x_mds.c b/arch/powerpc/platforms/83xx/mpc832x_mds.c
> index bb7b25acf26f..1e92f806ee60 100644
> --- a/arch/powerpc/platforms/83xx/mpc832x_mds.c
> +++ b/arch/powerpc/platforms/83xx/mpc832x_mds.c
> @@ -75,7 +75,7 @@ static void __init mpc832x_sys_setup_arch(void)
> par_io_init(np);
> of_node_put(np);
>
> - for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)
> + for_each_node_by_name(np. "ucc")
Gah, kbuild robot even told me about this typo and I missed it. Please
let me know if you can fix up or if I should resend (or drop). I'd
rather it not get dropped as I want to convert of_find_node_by_name() to
stop dropping reference to the starting node, as half of the users do
not expect it.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it
2017-02-01 1:54 [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it Dmitry Torokhov
2017-02-01 1:54 ` [PATCH 2/2] powerpc: make use of for_each_node_by_type() " Dmitry Torokhov
2017-02-01 2:20 ` [PATCH 1/2] powerpc: make use of for_each_node_by_name() " Dmitry Torokhov
@ 2017-12-12 11:39 ` Michael Ellerman
2 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2017-12-12 11:39 UTC (permalink / raw)
To: Dmitry Torokhov, Benjamin Herrenschmidt, Paul Mackerras
Cc: Arnd Bergmann, linux-kernel, Scott Wood, linuxppc-dev
On Wed, 2017-02-01 at 01:54:37 UTC, Dmitry Torokhov wrote:
> Instead of manually coding the loop with of_find_node_by_name(), let's
> switch to the standard macro for iterating over nodes with given name.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/0aa8ff9b76282300d16e0a1403b115
cheers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [2/2] powerpc: make use of for_each_node_by_type() instead of open-coding it
2017-02-01 1:54 ` [PATCH 2/2] powerpc: make use of for_each_node_by_type() " Dmitry Torokhov
@ 2018-01-17 13:29 ` Michael Ellerman
0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-01-17 13:29 UTC (permalink / raw)
To: Dmitry Torokhov, Benjamin Herrenschmidt, Paul Mackerras
Cc: Arnd Bergmann, linux-kernel, Scott Wood, linuxppc-dev
On Wed, 2017-02-01 at 01:54:38 UTC, Dmitry Torokhov wrote:
> Instead of manually coding the loop with of_find_node_by_type(), let's
> switch to the standard macro for iterating over nodes with given type.
>
> Also fixed a couple of refcount leaks in the aforementioned loops.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/9625e69a3818cc00fd85632719b4c6
cheers
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-01-17 13:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-01 1:54 [PATCH 1/2] powerpc: make use of for_each_node_by_name() instead of open-coding it Dmitry Torokhov
2017-02-01 1:54 ` [PATCH 2/2] powerpc: make use of for_each_node_by_type() " Dmitry Torokhov
2018-01-17 13:29 ` [2/2] " Michael Ellerman
2017-02-01 2:20 ` [PATCH 1/2] powerpc: make use of for_each_node_by_name() " Dmitry Torokhov
2017-12-12 11:39 ` [1/2] " Michael Ellerman
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).