Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+19 -35
+5 -15
arch/powerpc/platforms/powermac/feature.c
··· 2805 2805 /* Enable GMAC for now for PCI probing. It will be disabled 2806 2806 * later on after PCI probe 2807 2807 */ 2808 - np = of_find_node_by_name(NULL, "ethernet"); 2809 - while(np) { 2808 + for_each_node_by_name(np, "ethernet") 2810 2809 if (of_device_is_compatible(np, "K2-GMAC")) 2811 2810 g5_gmac_enable(np, 0, 1); 2812 - np = of_find_node_by_name(np, "ethernet"); 2813 - } 2814 2811 2815 2812 /* Enable FW before PCI probe. Will be disabled later on 2816 2813 * Note: We should have a batter way to check that we are 2817 2814 * dealing with uninorth internal cell and not a PCI cell 2818 2815 * on the external PCI. The code below works though. 2819 2816 */ 2820 - np = of_find_node_by_name(NULL, "firewire"); 2821 - while(np) { 2817 + for_each_node_by_name(np, "firewire") { 2822 2818 if (of_device_is_compatible(np, "pci106b,5811")) { 2823 2819 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; 2824 2820 g5_fw_enable(np, 0, 1); 2825 2821 } 2826 - np = of_find_node_by_name(np, "firewire"); 2827 2822 } 2828 2823 } 2829 2824 #else /* CONFIG_POWER4 */ ··· 2829 2834 /* Enable GMAC for now for PCI probing. It will be disabled 2830 2835 * later on after PCI probe 2831 2836 */ 2832 - np = of_find_node_by_name(NULL, "ethernet"); 2833 - while(np) { 2837 + for_each_node_by_name(np, "ethernet") { 2834 2838 if (np->parent 2835 2839 && of_device_is_compatible(np->parent, "uni-north") 2836 2840 && of_device_is_compatible(np, "gmac")) 2837 2841 core99_gmac_enable(np, 0, 1); 2838 - np = of_find_node_by_name(np, "ethernet"); 2839 2842 } 2840 2843 2841 2844 /* Enable FW before PCI probe. Will be disabled later on ··· 2841 2848 * dealing with uninorth internal cell and not a PCI cell 2842 2849 * on the external PCI. The code below works though. 2843 2850 */ 2844 - np = of_find_node_by_name(NULL, "firewire"); 2845 - while(np) { 2851 + for_each_node_by_name(np, "firewire") { 2846 2852 if (np->parent 2847 2853 && of_device_is_compatible(np->parent, "uni-north") 2848 2854 && (of_device_is_compatible(np, "pci106b,18") || ··· 2850 2858 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED; 2851 2859 core99_firewire_enable(np, 0, 1); 2852 2860 } 2853 - np = of_find_node_by_name(np, "firewire"); 2854 2861 } 2855 2862 2856 2863 /* Enable ATA-100 before PCI probe. */ 2857 2864 np = of_find_node_by_name(NULL, "ata-6"); 2858 - while(np) { 2865 + for_each_node_by_name(np, "ata-6") { 2859 2866 if (np->parent 2860 2867 && of_device_is_compatible(np->parent, "uni-north") 2861 2868 && of_device_is_compatible(np, "kauai-ata")) { 2862 2869 core99_ata100_enable(np, 1); 2863 2870 } 2864 - np = of_find_node_by_name(np, "ata-6"); 2865 2871 } 2866 2872 2867 2873 /* Switch airport off */
+1 -1
arch/powerpc/platforms/powermac/pci.c
··· 698 698 { 699 699 struct device_node *nec; 700 700 701 - for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) { 701 + for_each_node_by_name(nec, "usb") { 702 702 struct pci_controller *hose; 703 703 u32 data; 704 704 const u32 *prop;
+1 -1
arch/powerpc/platforms/powermac/smp.c
··· 577 577 int ok; 578 578 579 579 /* 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") { 581 581 p = of_get_parent(cc); 582 582 ok = p && of_device_is_compatible(p, "uni-n-i2c"); 583 583 of_node_put(p);
+1 -1
arch/powerpc/platforms/powermac/udbg_adb.c
··· 191 191 * of type "adb". If not, we return a failure, but we keep the 192 192 * bext output set for now 193 193 */ 194 - for (np = NULL; (np = of_find_node_by_name(np, "keyboard")) != NULL;) { 194 + for_each_node_by_name(np, "keyboard") { 195 195 struct device_node *parent = of_get_parent(np); 196 196 int found = (parent && strcmp(parent->type, "adb") == 0); 197 197 of_node_put(parent);
+1 -2
arch/powerpc/platforms/pseries/setup.c
··· 232 232 struct device_node *np; 233 233 const char *typep; 234 234 235 - for (np = NULL; (np = of_find_node_by_name(np, 236 - "interrupt-controller"));) { 235 + for_each_node_by_name(np, "interrupt-controller") { 237 236 typep = of_get_property(np, "compatible", NULL); 238 237 if (strstr(typep, "open-pic")) { 239 238 pSeries_mpic_node = of_node_get(np);
+1 -2
drivers/cpufreq/pmac64-cpufreq.c
··· 499 499 } 500 500 501 501 /* 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") { 504 503 const char *loc = of_get_property(hwclock, 505 504 "hwctrl-location", NULL); 506 505 if (loc == NULL)
+1 -2
drivers/edac/cell_edac.c
··· 134 134 int j; 135 135 u32 nr_pages; 136 136 137 - for (np = NULL; 138 - (np = of_find_node_by_name(np, "memory")) != NULL;) { 137 + for_each_node_by_name(np, "memory") { 139 138 struct resource r; 140 139 141 140 /* We "know" that the Cell firmware only creates one entry
+2 -2
drivers/pci/hotplug/rpaphp_core.c
··· 375 375 376 376 static int __init rpaphp_init(void) 377 377 { 378 - struct device_node *dn = NULL; 378 + struct device_node *dn; 379 379 380 380 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 381 381 382 - while ((dn = of_find_node_by_name(dn, "pci"))) 382 + for_each_node_by_name(dn, "pci") 383 383 rpaphp_add_slot(dn); 384 384 385 385 return 0;
+3 -6
drivers/tty/serial/pmac_zilog.c
··· 1650 1650 /* 1651 1651 * Find all escc chips in the system 1652 1652 */ 1653 - node_p = of_find_node_by_name(NULL, "escc"); 1654 - while (node_p) { 1653 + for_each_node_by_name(node_p, "escc") { 1655 1654 /* 1656 1655 * First get channel A/B node pointers 1657 1656 * ··· 1668 1669 of_node_put(node_b); 1669 1670 printk(KERN_ERR "pmac_zilog: missing node %c for escc %s\n", 1670 1671 (!node_a) ? 'a' : 'b', node_p->full_name); 1671 - goto next; 1672 + continue; 1672 1673 } 1673 1674 1674 1675 /* ··· 1695 1696 of_node_put(node_b); 1696 1697 memset(&pmz_ports[count], 0, sizeof(struct uart_pmac_port)); 1697 1698 memset(&pmz_ports[count+1], 0, sizeof(struct uart_pmac_port)); 1698 - goto next; 1699 + continue; 1699 1700 } 1700 1701 count += 2; 1701 - next: 1702 - node_p = of_find_node_by_name(node_p, "escc"); 1703 1702 } 1704 1703 pmz_ports_count = count; 1705 1704
+3 -3
sound/ppc/pmac.c
··· 992 992 return -ENODEV; 993 993 994 994 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; 998 998 } 999 999 if (! sound) { 1000 1000 of_node_put(chip->node);