Skip to content

Commit ccdb8ed

Browse files
committed
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: Grant 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>
1 parent a752ee5 commit ccdb8ed

10 files changed

Lines changed: 19 additions & 35 deletions

File tree

‎arch/powerpc/platforms/powermac/feature.c‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,25 +2805,20 @@ set_initial_features(void)
28052805
/* Enable GMAC for now for PCI probing. It will be disabled
28062806
* later on after PCI probe
28072807
*/
2808-
np = of_find_node_by_name(NULL, "ethernet");
2809-
while(np) {
2808+
for_each_node_by_name(np, "ethernet")
28102809
if (of_device_is_compatible(np, "K2-GMAC"))
28112810
g5_gmac_enable(np, 0, 1);
2812-
np = of_find_node_by_name(np, "ethernet");
2813-
}
28142811

28152812
/* Enable FW before PCI probe. Will be disabled later on
28162813
* Note: We should have a batter way to check that we are
28172814
* dealing with uninorth internal cell and not a PCI cell
28182815
* on the external PCI. The code below works though.
28192816
*/
2820-
np = of_find_node_by_name(NULL, "firewire");
2821-
while(np) {
2817+
for_each_node_by_name(np, "firewire") {
28222818
if (of_device_is_compatible(np, "pci106b,5811")) {
28232819
macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
28242820
g5_fw_enable(np, 0, 1);
28252821
}
2826-
np = of_find_node_by_name(np, "firewire");
28272822
}
28282823
}
28292824
#else /* CONFIG_POWER4 */
@@ -2834,22 +2829,19 @@ set_initial_features(void)
28342829
/* Enable GMAC for now for PCI probing. It will be disabled
28352830
* later on after PCI probe
28362831
*/
2837-
np = of_find_node_by_name(NULL, "ethernet");
2838-
while(np) {
2832+
for_each_node_by_name(np, "ethernet") {
28392833
if (np->parent
28402834
&& of_device_is_compatible(np->parent, "uni-north")
28412835
&& of_device_is_compatible(np, "gmac"))
28422836
core99_gmac_enable(np, 0, 1);
2843-
np = of_find_node_by_name(np, "ethernet");
28442837
}
28452838

28462839
/* Enable FW before PCI probe. Will be disabled later on
28472840
* Note: We should have a batter way to check that we are
28482841
* dealing with uninorth internal cell and not a PCI cell
28492842
* on the external PCI. The code below works though.
28502843
*/
2851-
np = of_find_node_by_name(NULL, "firewire");
2852-
while(np) {
2844+
for_each_node_by_name(np, "firewire") {
28532845
if (np->parent
28542846
&& of_device_is_compatible(np->parent, "uni-north")
28552847
&& (of_device_is_compatible(np, "pci106b,18") ||
@@ -2858,18 +2850,16 @@ set_initial_features(void)
28582850
macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
28592851
core99_firewire_enable(np, 0, 1);
28602852
}
2861-
np = of_find_node_by_name(np, "firewire");
28622853
}
28632854

28642855
/* Enable ATA-100 before PCI probe. */
28652856
np = of_find_node_by_name(NULL, "ata-6");
2866-
while(np) {
2857+
for_each_node_by_name(np, "ata-6") {
28672858
if (np->parent
28682859
&& of_device_is_compatible(np->parent, "uni-north")
28692860
&& of_device_is_compatible(np, "kauai-ata")) {
28702861
core99_ata100_enable(np, 1);
28712862
}
2872-
np = of_find_node_by_name(np, "ata-6");
28732863
}
28742864

28752865
/* Switch airport off */

‎arch/powerpc/platforms/powermac/pci.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static void __init fixup_nec_usb2(void)
698698
{
699699
struct device_node *nec;
700700

701-
for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
701+
for_each_node_by_name(nec, "usb") {
702702
struct pci_controller *hose;
703703
u32 data;
704704
const u32 *prop;

‎arch/powerpc/platforms/powermac/smp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static void __init smp_core99_setup_i2c_hwsync(int ncpus)
577577
int ok;
578578

579579
/* Look for the clock chip */
580-
while ((cc = of_find_node_by_name(cc, "i2c-hwclock")) != NULL) {
580+
for_each_node_by_name(cc, "i2c-hwclock") {
581581
p = of_get_parent(cc);
582582
ok = p && of_device_is_compatible(p, "uni-n-i2c");
583583
of_node_put(p);

‎arch/powerpc/platforms/powermac/udbg_adb.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int __init udbg_adb_init(int force_btext)
191191
* of type "adb". If not, we return a failure, but we keep the
192192
* bext output set for now
193193
*/
194-
for (np = NULL; (np = of_find_node_by_name(np, "keyboard")) != NULL;) {
194+
for_each_node_by_name(np, "keyboard") {
195195
struct device_node *parent = of_get_parent(np);
196196
int found = (parent && strcmp(parent->type, "adb") == 0);
197197
of_node_put(parent);

‎arch/powerpc/platforms/pseries/setup.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ static void __init pseries_discover_pic(void)
232232
struct device_node *np;
233233
const char *typep;
234234

235-
for (np = NULL; (np = of_find_node_by_name(np,
236-
"interrupt-controller"));) {
235+
for_each_node_by_name(np, "interrupt-controller") {
237236
typep = of_get_property(np, "compatible", NULL);
238237
if (strstr(typep, "open-pic")) {
239238
pSeries_mpic_node = of_node_get(np);

‎drivers/cpufreq/pmac64-cpufreq.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ static int __init g5_pm72_cpufreq_init(struct device_node *cpunode)
499499
}
500500

501501
/* Lookup the i2c hwclock */
502-
for (hwclock = NULL;
503-
(hwclock = of_find_node_by_name(hwclock, "i2c-hwclock")) != NULL;){
502+
for_each_node_by_name(hwclock, "i2c-hwclock") {
504503
const char *loc = of_get_property(hwclock,
505504
"hwctrl-location", NULL);
506505
if (loc == NULL)

‎drivers/edac/cell_edac.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ static void cell_edac_init_csrows(struct mem_ctl_info *mci)
134134
int j;
135135
u32 nr_pages;
136136

137-
for (np = NULL;
138-
(np = of_find_node_by_name(np, "memory")) != NULL;) {
137+
for_each_node_by_name(np, "memory") {
139138
struct resource r;
140139

141140
/* We "know" that the Cell firmware only creates one entry

‎drivers/pci/hotplug/rpaphp_core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,11 @@ static void __exit cleanup_slots(void)
375375

376376
static int __init rpaphp_init(void)
377377
{
378-
struct device_node *dn = NULL;
378+
struct device_node *dn;
379379

380380
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
381381

382-
while ((dn = of_find_node_by_name(dn, "pci")))
382+
for_each_node_by_name(dn, "pci")
383383
rpaphp_add_slot(dn);
384384

385385
return 0;

‎drivers/tty/serial/pmac_zilog.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,8 +1650,7 @@ static int __init pmz_probe(void)
16501650
/*
16511651
* Find all escc chips in the system
16521652
*/
1653-
node_p = of_find_node_by_name(NULL, "escc");
1654-
while (node_p) {
1653+
for_each_node_by_name(node_p, "escc") {
16551654
/*
16561655
* First get channel A/B node pointers
16571656
*
@@ -1669,7 +1668,7 @@ static int __init pmz_probe(void)
16691668
of_node_put(node_b);
16701669
printk(KERN_ERR "pmac_zilog: missing node %c for escc %s\n",
16711670
(!node_a) ? 'a' : 'b', node_p->full_name);
1672-
goto next;
1671+
continue;
16731672
}
16741673

16751674
/*
@@ -1696,11 +1695,9 @@ static int __init pmz_probe(void)
16961695
of_node_put(node_b);
16971696
memset(&pmz_ports[count], 0, sizeof(struct uart_pmac_port));
16981697
memset(&pmz_ports[count+1], 0, sizeof(struct uart_pmac_port));
1699-
goto next;
1698+
continue;
17001699
}
17011700
count += 2;
1702-
next:
1703-
node_p = of_find_node_by_name(node_p, "escc");
17041701
}
17051702
pmz_ports_count = count;
17061703

‎sound/ppc/pmac.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@ static int snd_pmac_detect(struct snd_pmac *chip)
992992
return -ENODEV;
993993

994994
if (!sound) {
995-
sound = of_find_node_by_name(NULL, "sound");
996-
while (sound && sound->parent != chip->node)
997-
sound = of_find_node_by_name(sound, "sound");
995+
for_each_node_by_name(sound, "sound")
996+
if (sound->parent == chip->node)
997+
break;
998998
}
999999
if (! sound) {
10001000
of_node_put(chip->node);

0 commit comments

Comments
 (0)