powerpc: Use device_type helpers to access the node type
authorRob Herring <robh@kernel.org>
Fri, 16 Nov 2018 22:11:00 +0000 (16:11 -0600)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 26 Nov 2018 11:33:37 +0000 (22:33 +1100)
Remove directly accessing device_node.type pointer and use the
accessors instead. This will eventually allow removing the type
pointer.

Replace the open coded iterating over child nodes with
for_each_child_of_node() while we're here.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
18 files changed:
arch/powerpc/kernel/cacheinfo.c
arch/powerpc/kernel/isa-bridge.c
arch/powerpc/kernel/legacy_serial.c
arch/powerpc/kernel/pci_of_scan.c
arch/powerpc/kernel/setup-common.c
arch/powerpc/mm/numa.c
arch/powerpc/platforms/4xx/pci.c
arch/powerpc/platforms/cell/cbe_regs.c
arch/powerpc/platforms/cell/setup.c
arch/powerpc/platforms/chrp/pci.c
arch/powerpc/platforms/chrp/setup.c
arch/powerpc/platforms/maple/pci.c
arch/powerpc/platforms/powermac/low_i2c.c
arch/powerpc/platforms/powermac/pic.c
arch/powerpc/platforms/powermac/udbg_adb.c
arch/powerpc/platforms/pseries/hotplug-memory.c
arch/powerpc/platforms/pseries/setup.c
arch/powerpc/platforms/pseries/vio.c

index be57bd07596d9cfd1ac2153c4be8650591e9067a..53102764fd2f8f45d82dba2574e07365c3cca745 100644 (file)
@@ -428,7 +428,7 @@ static void link_cache_lists(struct cache *smaller, struct cache *bigger)
 static void do_subsidiary_caches_debugcheck(struct cache *cache)
 {
        WARN_ON_ONCE(cache->level != 1);
-       WARN_ON_ONCE(strcmp(cache->ofnode->type, "cpu"));
+       WARN_ON_ONCE(!of_node_is_type(cache->ofnode, "cpu"));
 }
 
 static void do_subsidiary_caches(struct cache *cache)
index fda3ae48480c8eebe121d602604e5dad5fa0bc92..0e7099da4f25caaf203933295bf6ff600cb43ec0 100644 (file)
@@ -327,8 +327,7 @@ static int isa_bridge_notify(struct notifier_block *nb, unsigned long action,
                /* Check if we have no ISA device, and this happens to be one,
                 * register it as such if it has an OF device
                 */
-               if (!isa_bridge_devnode && devnode && devnode->type &&
-                   !strcmp(devnode->type, "isa"))
+               if (!isa_bridge_devnode && of_node_is_type(devnode, "isa"))
                        isa_bridge_find_late(pdev, devnode);
 
                return 0;
index 33b34a58fc62f50b9d7cb8ad1e82c6eab46bb39f..2a6f339e92cd023c33894a7458e98f21f7ae1c18 100644 (file)
@@ -192,7 +192,7 @@ static int __init add_legacy_soc_port(struct device_node *np,
        /* Add port, irq will be dealt with later. We passed a translated
         * IO port value. It will be fixed up later along with the irq
         */
-       if (tsi && !strcmp(tsi->type, "tsi-bridge"))
+       if (of_node_is_type(tsi, "tsi-bridge"))
                return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
                                       0, legacy_port_flags, 0);
        else
@@ -417,7 +417,8 @@ void __init find_legacy_serial_ports(void)
                        of_node_put(parent);
                        continue;
                }
-               if (strcmp(np->name, "serial") && strcmp(np->type, "serial")) {
+               if (strcmp(np->name, "serial") &&
+                   !of_node_is_type(np, "serial")) {
                        of_node_put(parent);
                        continue;
                }
index 98f04725def75f09dc924f7861d795c986ca98f0..24191ea2d9a78393d9f7ad26da0daabc0eb91ca1 100644 (file)
@@ -125,16 +125,13 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
                                 struct pci_bus *bus, int devfn)
 {
        struct pci_dev *dev;
-       const char *type;
 
        dev = pci_alloc_dev(bus);
        if (!dev)
                return NULL;
-       type = of_get_property(node, "device_type", NULL);
-       if (type == NULL)
-               type = "";
 
-       pr_debug("    create device, devfn: %x, type: %s\n", devfn, type);
+       pr_debug("    create device, devfn: %x, type: %s\n", devfn,
+                of_node_get_device_type(node));
 
        dev->dev.of_node = of_node_get(node);
        dev->dev.parent = bus->bridge;
@@ -167,12 +164,12 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
        /* Early fixups, before probing the BARs */
        pci_fixup_device(pci_fixup_early, dev);
 
-       if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
+       if (of_node_is_type(node, "pci") || of_node_is_type(node, "pciex")) {
                /* a PCI-PCI bridge */
                dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
                dev->rom_base_reg = PCI_ROM_ADDRESS1;
                set_pcie_hotplug_bridge(dev);
-       } else if (!strcmp(type, "cardbus")) {
+       } else if (of_node_is_type(node, "cardbus")) {
                dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
        } else {
                dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
index 93ee3703b42f331e5e0706eefd3a3a0f347d0243..4a6d6e866be7c13d60244cf9797a572d6d54c0d1 100644 (file)
@@ -687,7 +687,7 @@ int check_legacy_ioport(unsigned long base_port)
                return ret;
        parent = of_get_parent(np);
        if (parent) {
-               if (strcmp(parent->type, "isa") == 0)
+               if (of_node_is_type(parent, "isa"))
                        ret = 0;
                of_node_put(parent);
        }
index ce28ae5ca08033ff36ee157e9b83be3a61d44f52..87f0dd004295761b321216adf333f1eab1ca09df 100644 (file)
@@ -1475,7 +1475,7 @@ static int dt_update_callback(struct notifier_block *nb,
 
        switch (action) {
        case OF_RECONFIG_UPDATE_PROPERTY:
-               if (!of_prop_cmp(update->dn->type, "cpu") &&
+               if (of_node_is_type(update->dn, "cpu") &&
                    !of_prop_cmp(update->prop->name, "ibm,associativity")) {
                        u32 core_id;
                        of_property_read_u32(update->dn, "reg", &core_id);
index 5aca523551aed01706cc125947fa6ac84216de7a..d0825f5c5b1bd80eab4f60977773b2b4c1990a57 100644 (file)
@@ -2081,7 +2081,6 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
        const u32 *pval;
        int portno;
        unsigned int dcrs;
-       const char *val;
 
        /* First, proceed to core initialization as we assume there's
         * only one PCIe core in the system
@@ -2127,10 +2126,9 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
         * Resulting from this setup this PCIe port will be configured
         * as root-complex or as endpoint.
         */
-       val = of_get_property(port->node, "device_type", NULL);
-       if (!strcmp(val, "pci-endpoint")) {
+       if (of_node_is_type(port->node, "pci-endpoint")) {
                port->endpoint = 1;
-       } else if (!strcmp(val, "pci")) {
+       } else if (of_node_is_type(port->node, "pci")) {
                port->endpoint = 0;
        } else {
                printk(KERN_ERR "PCIE: missing or incorrect device_type for %pOF\n",
index b926438d73af7deb317d8ccc2a83dec7c75cc7af..27ee65b89099de8c79a8323e310b7acdf3b7acd1 100644 (file)
@@ -53,7 +53,7 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np)
        int i;
        struct device_node *tmp_np;
 
-       if (strcasecmp(np->type, "spe")) {
+       if (!of_node_is_type(np, "spe")) {
                for (i = 0; i < cbe_regs_map_count; i++)
                        if (cbe_regs_maps[i].cpu_node == np ||
                            cbe_regs_maps[i].be_node == np)
@@ -70,8 +70,8 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np)
                tmp_np = tmp_np->parent;
                /* on a correct devicetree we wont get up to root */
                BUG_ON(!tmp_np);
-       } while (strcasecmp(tmp_np->type, "cpu") &&
-                strcasecmp(tmp_np->type, "be"));
+       } while (!of_node_is_type(tmp_np, "cpu") ||
+                !of_node_is_type(tmp_np, "be"));
 
        np->data = cbe_find_map(tmp_np);
 
index 7d31b8d146613e7c0b66919357c9ae9533836a00..902d527d043fb9e4cd0e21647ccf033d9af35893 100644 (file)
@@ -168,8 +168,7 @@ static int __init cell_publish_devices(void)
         * platform devices for the PCI host bridges
         */
        for_each_child_of_node(root, np) {
-               if (np->type == NULL || (strcmp(np->type, "pci") != 0 &&
-                                        strcmp(np->type, "pciex") != 0))
+               if (!of_node_is_type(np, "pci") && !of_node_is_type(np, "pciex"))
                        continue;
                of_platform_device_create(np, NULL, NULL);
        }
index 5ddb57b829214a9b660fa2f06fafb9c89aaa9917..b020c757d2bf219bcbaac81ea234614f474c5c10 100644 (file)
@@ -230,8 +230,8 @@ chrp_find_bridges(void)
                else if (strncmp(machine, "Pegasos", 7) == 0)
                        is_pegasos = 1;
        }
-       for (dev = root->child; dev != NULL; dev = dev->sibling) {
-               if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
+       for_each_child_of_node(root, dev) {
+               if (!of_node_is_type(dev, "pci"))
                        continue;
                ++index;
                /* The GG2 bridge on the LongTrail doesn't have an address */
index d6d8ffc0271eeab29cc1425cf628a8995a3cca2b..3c21f046e20cadce0f262a9d5f7b6a969ac3ad58 100644 (file)
@@ -280,10 +280,7 @@ static __init void chrp_init(void)
        node = of_find_node_by_path(property);
        if (!node)
                return;
-       property = of_get_property(node, "device_type", NULL);
-       if (!property)
-               goto out_put;
-       if (strcmp(property, "serial"))
+       if (!of_node_is_type(node, "serial"))
                goto out_put;
        /*
         * The 9pin connector is either /failsafe
index e3821379e86f38c7799602db8a9211c5afb1d46e..13fba004b7e7f421144f2ecda35c5a239c350ead 100644 (file)
@@ -604,10 +604,8 @@ void __init maple_pci_init(void)
                printk(KERN_CRIT "maple_find_bridges: can't find root of device tree\n");
                return;
        }
-       for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
-               if (!np->type)
-                       continue;
-               if (strcmp(np->type, "pci") && strcmp(np->type, "ht"))
+       for_each_child_of_node(root, np) {
+               if (!of_node_is_type(np, "pci") && !of_node_is_type(np, "ht"))
                        continue;
                if ((of_device_is_compatible(np, "u4-pcie") ||
                     of_device_is_compatible(np, "u3-agp")) &&
index d4d4118205978df0c36ed67e681aa951d16c7ca7..84bace3b546ad6ff7892ea5fdac1250929d983be 100644 (file)
@@ -917,10 +917,9 @@ static void __init smu_i2c_probe(void)
         * type as older device trees mix i2c busses and other things
         * at the same level
         */
-       for (busnode = NULL;
-            (busnode = of_get_next_child(controller, busnode)) != NULL;) {
-               if (strcmp(busnode->type, "i2c") &&
-                   strcmp(busnode->type, "i2c-bus"))
+       for_each_child_of_node(controller, busnode) {
+               if (!of_node_is_type(busnode, "i2c") &&
+                   !of_node_is_type(busnode, "i2c-bus"))
                        continue;
                reg = of_get_property(busnode, "reg", NULL);
                if (reg == NULL)
index 57bbff4659645c8edddc64e95a6674c0a33ac87b..5a71395e535e56a69752be2ab2adb2b5755288f4 100644 (file)
@@ -417,7 +417,7 @@ int of_irq_parse_oldworld(struct device_node *device, int index,
                if (ints != NULL)
                        break;
                device = device->parent;
-               if (device && strcmp(device->type, "pci") != 0)
+               if (!of_node_is_type(device, "pci"))
                        break;
        }
        if (ints == NULL)
index 64f38f0d15ed9842b57bc815e853b1d3624404f3..12158bb4fed703fe7a739bd55d762eae9989be7a 100644 (file)
@@ -194,7 +194,7 @@ int __init udbg_adb_init(int force_btext)
         */
        for_each_node_by_name(np, "keyboard") {
                struct device_node *parent = of_get_parent(np);
-               int found = (parent && strcmp(parent->type, "adb") == 0);
+               int found = of_node_is_type(parent, "adb");
                of_node_put(parent);
                if (found)
                        break;
index 2a983b5a52e1cec3d19a381687c7fd6f52b78acf..3b881ac66d9a2ae112b046032c89b778f571cf6e 100644 (file)
@@ -313,7 +313,6 @@ out:
 
 static int pseries_remove_mem_node(struct device_node *np)
 {
-       const char *type;
        const __be32 *regs;
        unsigned long base;
        unsigned int lmb_size;
@@ -322,8 +321,7 @@ static int pseries_remove_mem_node(struct device_node *np)
        /*
         * Check to see if we are actually removing memory
         */
-       type = of_get_property(np, "device_type", NULL);
-       if (type == NULL || strcmp(type, "memory") != 0)
+       if (!of_node_is_type(np, "memory"))
                return 0;
 
        /*
@@ -936,7 +934,6 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
 
 static int pseries_add_mem_node(struct device_node *np)
 {
-       const char *type;
        const __be32 *regs;
        unsigned long base;
        unsigned int lmb_size;
@@ -945,8 +942,7 @@ static int pseries_add_mem_node(struct device_node *np)
        /*
         * Check to see if we are actually adding memory
         */
-       type = of_get_property(np, "device_type", NULL);
-       if (type == NULL || strcmp(type, "memory") != 0)
+       if (!of_node_is_type(np, "memory"))
                return 0;
 
        /*
index 0f553dcfa5485867b3704b3ca93d64fd951aead9..4078a05fa5c0faeb48c862c5253f498ea211baf6 100644 (file)
@@ -469,8 +469,8 @@ static void __init find_and_init_phbs(void)
        struct device_node *root = of_find_node_by_path("/");
 
        for_each_child_of_node(root, node) {
-               if (node->type == NULL || (strcmp(node->type, "pci") != 0 &&
-                                          strcmp(node->type, "pciex") != 0))
+               if (!of_node_is_type(node, "pci") &&
+                   !of_node_is_type(node, "pciex"))
                        continue;
 
                phb = pcibios_alloc_controller(node);
@@ -978,11 +978,7 @@ static void pseries_power_off(void)
 
 static int __init pSeries_probe(void)
 {
-       const char *dtype = of_get_property(of_root, "device_type", NULL);
-
-       if (dtype == NULL)
-               return 0;
-       if (strcmp(dtype, "chrp"))
+       if (!of_node_is_type(of_root, "chrp"))
                return 0;
 
        /* Cell blades firmware claims to be chrp while it's not. Until this
index 88f1ad1d630950f4ed67c25ef9c849fd62b83ebd..93cc9eec66011b2264d7aff4b0590cb2df2d78d9 100644 (file)
@@ -1356,9 +1356,9 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
         */
        parent_node = of_get_parent(of_node);
        if (parent_node) {
-               if (!strcmp(parent_node->type, "ibm,platform-facilities"))
+               if (of_node_is_type(parent_node, "ibm,platform-facilities"))
                        family = PFO;
-               else if (!strcmp(parent_node->type, "vdevice"))
+               else if (of_node_is_type(parent_node, "vdevice"))
                        family = VDEVICE;
                else {
                        pr_warn("%s: parent(%pOF) of %pOFn not recognized.\n",
@@ -1395,9 +1395,8 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
        if (viodev->family == VDEVICE) {
                unsigned int unit_address;
 
-               if (of_node->type != NULL)
-                       viodev->type = of_node->type;
-               else {
+               viodev->type = of_node_get_device_type(of_node);
+               if (!viodev->type) {
                        pr_warn("%s: node %pOFn is missing the 'device_type' "
                                        "property.\n", __func__, of_node);
                        goto out;
@@ -1672,32 +1671,30 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
 {
        char kobj_name[20];
        struct device_node *vnode_parent;
-       const char *dev_type;
 
        vnode_parent = of_get_parent(vnode);
        if (!vnode_parent)
                return NULL;
 
-       dev_type = of_get_property(vnode_parent, "device_type", NULL);
-       of_node_put(vnode_parent);
-       if (!dev_type)
-               return NULL;
-
        /* construct the kobject name from the device node */
-       if (!strcmp(dev_type, "vdevice")) {
+       if (of_node_is_type(vnode_parent, "vdevice")) {
                const __be32 *prop;
                
                prop = of_get_property(vnode, "reg", NULL);
                if (!prop)
-                       return NULL;
+                       goto out;
                snprintf(kobj_name, sizeof(kobj_name), "%x",
                         (uint32_t)of_read_number(prop, 1));
-       } else if (!strcmp(dev_type, "ibm,platform-facilities"))
+       } else if (of_node_is_type(vnode_parent, "ibm,platform-facilities"))
                snprintf(kobj_name, sizeof(kobj_name), "%pOFn", vnode);
        else
-               return NULL;
+               goto out;
 
+       of_node_put(vnode_parent);
        return vio_find_name(kobj_name);
+out:
+       of_node_put(vnode_parent);
+       return NULL;
 }
 EXPORT_SYMBOL(vio_find_node);