Commit ccdb8ed3 authored by Grant Likely's avatar Grant Likely

of: Migrate of_find_node_by_name() users to for_each_node_by_name()

There are a bunch of users open coding the for_each_node_by_name() by
calling of_find_node_by_name() directly instead of using the macro. This
is getting in the way of some cleanups, and the possibility of removing
of_find_node_by_name() entirely. Clean it up so that all the users are
consistent.
Signed-off-by: default avatarGrant Likely <grant.likely@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Takashi Iwai <tiwai@suse.de>
parent a752ee56
...@@ -2805,25 +2805,20 @@ set_initial_features(void) ...@@ -2805,25 +2805,20 @@ set_initial_features(void)
/* Enable GMAC for now for PCI probing. It will be disabled /* Enable GMAC for now for PCI probing. It will be disabled
* later on after PCI probe * later on after PCI probe
*/ */
np = of_find_node_by_name(NULL, "ethernet"); for_each_node_by_name(np, "ethernet")
while(np) {
if (of_device_is_compatible(np, "K2-GMAC")) if (of_device_is_compatible(np, "K2-GMAC"))
g5_gmac_enable(np, 0, 1); g5_gmac_enable(np, 0, 1);
np = of_find_node_by_name(np, "ethernet");
}
/* Enable FW before PCI probe. Will be disabled later on /* Enable FW before PCI probe. Will be disabled later on
* Note: We should have a batter way to check that we are * Note: We should have a batter way to check that we are
* dealing with uninorth internal cell and not a PCI cell * dealing with uninorth internal cell and not a PCI cell
* on the external PCI. The code below works though. * on the external PCI. The code below works though.
*/ */
np = of_find_node_by_name(NULL, "firewire"); for_each_node_by_name(np, "firewire") {
while(np) {
if (of_device_is_compatible(np, "pci106b,5811")) { if (of_device_is_compatible(np, "pci106b,5811")) {
macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
g5_fw_enable(np, 0, 1); g5_fw_enable(np, 0, 1);
} }
np = of_find_node_by_name(np, "firewire");
} }
} }
#else /* CONFIG_POWER4 */ #else /* CONFIG_POWER4 */
...@@ -2834,13 +2829,11 @@ set_initial_features(void) ...@@ -2834,13 +2829,11 @@ set_initial_features(void)
/* Enable GMAC for now for PCI probing. It will be disabled /* Enable GMAC for now for PCI probing. It will be disabled
* later on after PCI probe * later on after PCI probe
*/ */
np = of_find_node_by_name(NULL, "ethernet"); for_each_node_by_name(np, "ethernet") {
while(np) {
if (np->parent if (np->parent
&& of_device_is_compatible(np->parent, "uni-north") && of_device_is_compatible(np->parent, "uni-north")
&& of_device_is_compatible(np, "gmac")) && of_device_is_compatible(np, "gmac"))
core99_gmac_enable(np, 0, 1); core99_gmac_enable(np, 0, 1);
np = of_find_node_by_name(np, "ethernet");
} }
/* Enable FW before PCI probe. Will be disabled later on /* Enable FW before PCI probe. Will be disabled later on
...@@ -2848,8 +2841,7 @@ set_initial_features(void) ...@@ -2848,8 +2841,7 @@ set_initial_features(void)
* dealing with uninorth internal cell and not a PCI cell * dealing with uninorth internal cell and not a PCI cell
* on the external PCI. The code below works though. * on the external PCI. The code below works though.
*/ */
np = of_find_node_by_name(NULL, "firewire"); for_each_node_by_name(np, "firewire") {
while(np) {
if (np->parent if (np->parent
&& of_device_is_compatible(np->parent, "uni-north") && of_device_is_compatible(np->parent, "uni-north")
&& (of_device_is_compatible(np, "pci106b,18") || && (of_device_is_compatible(np, "pci106b,18") ||
...@@ -2858,18 +2850,16 @@ set_initial_features(void) ...@@ -2858,18 +2850,16 @@ set_initial_features(void)
macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
core99_firewire_enable(np, 0, 1); core99_firewire_enable(np, 0, 1);
} }
np = of_find_node_by_name(np, "firewire");
} }
/* Enable ATA-100 before PCI probe. */ /* Enable ATA-100 before PCI probe. */
np = of_find_node_by_name(NULL, "ata-6"); np = of_find_node_by_name(NULL, "ata-6");
while(np) { for_each_node_by_name(np, "ata-6") {
if (np->parent if (np->parent
&& of_device_is_compatible(np->parent, "uni-north") && of_device_is_compatible(np->parent, "uni-north")
&& of_device_is_compatible(np, "kauai-ata")) { && of_device_is_compatible(np, "kauai-ata")) {
core99_ata100_enable(np, 1); core99_ata100_enable(np, 1);
} }
np = of_find_node_by_name(np, "ata-6");
} }
/* Switch airport off */ /* Switch airport off */
......
...@@ -698,7 +698,7 @@ static void __init fixup_nec_usb2(void) ...@@ -698,7 +698,7 @@ static void __init fixup_nec_usb2(void)
{ {
struct device_node *nec; struct device_node *nec;
for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) { for_each_node_by_name(nec, "usb") {
struct pci_controller *hose; struct pci_controller *hose;
u32 data; u32 data;
const u32 *prop; const u32 *prop;
......
...@@ -577,7 +577,7 @@ static void __init smp_core99_setup_i2c_hwsync(int ncpus) ...@@ -577,7 +577,7 @@ static void __init smp_core99_setup_i2c_hwsync(int ncpus)
int ok; int ok;
/* Look for the clock chip */ /* Look for the clock chip */
while ((cc = of_find_node_by_name(cc, "i2c-hwclock")) != NULL) { for_each_node_by_name(cc, "i2c-hwclock") {
p = of_get_parent(cc); p = of_get_parent(cc);
ok = p && of_device_is_compatible(p, "uni-n-i2c"); ok = p && of_device_is_compatible(p, "uni-n-i2c");
of_node_put(p); of_node_put(p);
......
...@@ -191,7 +191,7 @@ int __init udbg_adb_init(int force_btext) ...@@ -191,7 +191,7 @@ int __init udbg_adb_init(int force_btext)
* of type "adb". If not, we return a failure, but we keep the * of type "adb". If not, we return a failure, but we keep the
* bext output set for now * bext output set for now
*/ */
for (np = NULL; (np = of_find_node_by_name(np, "keyboard")) != NULL;) { for_each_node_by_name(np, "keyboard") {
struct device_node *parent = of_get_parent(np); struct device_node *parent = of_get_parent(np);
int found = (parent && strcmp(parent->type, "adb") == 0); int found = (parent && strcmp(parent->type, "adb") == 0);
of_node_put(parent); of_node_put(parent);
......
...@@ -232,8 +232,7 @@ static void __init pseries_discover_pic(void) ...@@ -232,8 +232,7 @@ static void __init pseries_discover_pic(void)
struct device_node *np; struct device_node *np;
const char *typep; const char *typep;
for (np = NULL; (np = of_find_node_by_name(np, for_each_node_by_name(np, "interrupt-controller") {
"interrupt-controller"));) {
typep = of_get_property(np, "compatible", NULL); typep = of_get_property(np, "compatible", NULL);
if (strstr(typep, "open-pic")) { if (strstr(typep, "open-pic")) {
pSeries_mpic_node = of_node_get(np); pSeries_mpic_node = of_node_get(np);
......
...@@ -499,8 +499,7 @@ static int __init g5_pm72_cpufreq_init(struct device_node *cpunode) ...@@ -499,8 +499,7 @@ static int __init g5_pm72_cpufreq_init(struct device_node *cpunode)
} }
/* Lookup the i2c hwclock */ /* Lookup the i2c hwclock */
for (hwclock = NULL; for_each_node_by_name(hwclock, "i2c-hwclock") {
(hwclock = of_find_node_by_name(hwclock, "i2c-hwclock")) != NULL;){
const char *loc = of_get_property(hwclock, const char *loc = of_get_property(hwclock,
"hwctrl-location", NULL); "hwctrl-location", NULL);
if (loc == NULL) if (loc == NULL)
......
...@@ -134,8 +134,7 @@ static void cell_edac_init_csrows(struct mem_ctl_info *mci) ...@@ -134,8 +134,7 @@ static void cell_edac_init_csrows(struct mem_ctl_info *mci)
int j; int j;
u32 nr_pages; u32 nr_pages;
for (np = NULL; for_each_node_by_name(np, "memory") {
(np = of_find_node_by_name(np, "memory")) != NULL;) {
struct resource r; struct resource r;
/* We "know" that the Cell firmware only creates one entry /* We "know" that the Cell firmware only creates one entry
......
...@@ -375,11 +375,11 @@ static void __exit cleanup_slots(void) ...@@ -375,11 +375,11 @@ static void __exit cleanup_slots(void)
static int __init rpaphp_init(void) static int __init rpaphp_init(void)
{ {
struct device_node *dn = NULL; struct device_node *dn;
info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
while ((dn = of_find_node_by_name(dn, "pci"))) for_each_node_by_name(dn, "pci")
rpaphp_add_slot(dn); rpaphp_add_slot(dn);
return 0; return 0;
......
...@@ -1650,8 +1650,7 @@ static int __init pmz_probe(void) ...@@ -1650,8 +1650,7 @@ static int __init pmz_probe(void)
/* /*
* Find all escc chips in the system * Find all escc chips in the system
*/ */
node_p = of_find_node_by_name(NULL, "escc"); for_each_node_by_name(node_p, "escc") {
while (node_p) {
/* /*
* First get channel A/B node pointers * First get channel A/B node pointers
* *
...@@ -1669,7 +1668,7 @@ static int __init pmz_probe(void) ...@@ -1669,7 +1668,7 @@ static int __init pmz_probe(void)
of_node_put(node_b); of_node_put(node_b);
printk(KERN_ERR "pmac_zilog: missing node %c for escc %s\n", printk(KERN_ERR "pmac_zilog: missing node %c for escc %s\n",
(!node_a) ? 'a' : 'b', node_p->full_name); (!node_a) ? 'a' : 'b', node_p->full_name);
goto next; continue;
} }
/* /*
...@@ -1696,11 +1695,9 @@ static int __init pmz_probe(void) ...@@ -1696,11 +1695,9 @@ static int __init pmz_probe(void)
of_node_put(node_b); of_node_put(node_b);
memset(&pmz_ports[count], 0, sizeof(struct uart_pmac_port)); memset(&pmz_ports[count], 0, sizeof(struct uart_pmac_port));
memset(&pmz_ports[count+1], 0, sizeof(struct uart_pmac_port)); memset(&pmz_ports[count+1], 0, sizeof(struct uart_pmac_port));
goto next; continue;
} }
count += 2; count += 2;
next:
node_p = of_find_node_by_name(node_p, "escc");
} }
pmz_ports_count = count; pmz_ports_count = count;
......
...@@ -992,9 +992,9 @@ static int snd_pmac_detect(struct snd_pmac *chip) ...@@ -992,9 +992,9 @@ static int snd_pmac_detect(struct snd_pmac *chip)
return -ENODEV; return -ENODEV;
if (!sound) { if (!sound) {
sound = of_find_node_by_name(NULL, "sound"); for_each_node_by_name(sound, "sound")
while (sound && sound->parent != chip->node) if (sound->parent == chip->node)
sound = of_find_node_by_name(sound, "sound"); break;
} }
if (! sound) { if (! sound) {
of_node_put(chip->node); of_node_put(chip->node);
......
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