Commit 9625e69a authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Michael Ellerman

powerpc: make use of for_each_node_by_type() instead of open-coding it

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: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 94d3084a
...@@ -470,13 +470,13 @@ static void __init cpu_init_thread_core_maps(int tpc) ...@@ -470,13 +470,13 @@ static void __init cpu_init_thread_core_maps(int tpc)
*/ */
void __init smp_setup_cpu_maps(void) void __init smp_setup_cpu_maps(void)
{ {
struct device_node *dn = NULL; struct device_node *dn;
int cpu = 0; int cpu = 0;
int nthreads = 1; int nthreads = 1;
DBG("smp_setup_cpu_maps()\n"); 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; const __be32 *intserv;
__be32 cpu_be; __be32 cpu_be;
int j, len; int j, len;
...@@ -516,6 +516,11 @@ void __init smp_setup_cpu_maps(void) ...@@ -516,6 +516,11 @@ void __init smp_setup_cpu_maps(void)
set_cpu_possible(cpu, true); set_cpu_possible(cpu, true);
cpu++; cpu++;
} }
if (cpu >= nr_cpu_ids) {
of_node_put(dn);
break;
}
} }
/* If no SMT supported, nthreads is forced to 1 */ /* If no SMT supported, nthreads is forced to 1 */
......
...@@ -292,12 +292,12 @@ static int __init of_enumerate_spus(int (*fn)(void *data)) ...@@ -292,12 +292,12 @@ static int __init of_enumerate_spus(int (*fn)(void *data))
unsigned int n = 0; unsigned int n = 0;
ret = -ENODEV; ret = -ENODEV;
for (node = of_find_node_by_type(NULL, "spe"); for_each_node_by_type(node, "spe") {
node; node = of_find_node_by_type(node, "spe")) {
ret = fn(node); ret = fn(node);
if (ret) { if (ret) {
printk(KERN_WARNING "%s: Error initializing %s\n", printk(KERN_WARNING "%s: Error initializing %s\n",
__func__, node->name); __func__, node->name);
of_node_put(node);
break; break;
} }
n++; n++;
......
...@@ -486,15 +486,16 @@ static int __init pmac_pic_probe_mpic(void) ...@@ -486,15 +486,16 @@ static int __init pmac_pic_probe_mpic(void)
struct device_node *np, *master = NULL, *slave = NULL; struct device_node *np, *master = NULL, *slave = NULL;
/* We can have up to 2 MPICs cascaded */ /* We can have up to 2 MPICs cascaded */
for (np = NULL; (np = of_find_node_by_type(np, "open-pic")) for_each_node_by_type(np, "open-pic") {
!= NULL;) {
if (master == NULL && if (master == NULL &&
of_get_property(np, "interrupts", NULL) == NULL) of_get_property(np, "interrupts", NULL) == NULL)
master = of_node_get(np); master = of_node_get(np);
else if (slave == NULL) else if (slave == NULL)
slave = of_node_get(np); slave = of_node_get(np);
if (master && slave) if (master && slave) {
of_node_put(np);
break; break;
}
} }
/* Check for bogus setups */ /* Check for bogus setups */
......
...@@ -774,8 +774,8 @@ static void __init smp_core99_probe(void) ...@@ -774,8 +774,8 @@ static void __init smp_core99_probe(void)
if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345); if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
/* Count CPUs in the device-tree */ /* Count CPUs in the device-tree */
for (cpus = NULL; (cpus = of_find_node_by_type(cpus, "cpu")) != NULL;) for_each_node_by_type(cpus, "cpu")
++ncpus; ++ncpus;
printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus); printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
......
...@@ -370,10 +370,10 @@ static void parse_system_parameter_string(struct seq_file *m) ...@@ -370,10 +370,10 @@ static void parse_system_parameter_string(struct seq_file *m)
*/ */
static int lparcfg_count_active_processors(void) static int lparcfg_count_active_processors(void)
{ {
struct device_node *cpus_dn = NULL; struct device_node *cpus_dn;
int count = 0; 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 #ifdef LPARCFG_DEBUG
printk(KERN_ERR "cpus_dn %p\n", cpus_dn); printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment