powerpc: Make device tree accesses in VIO subsystem endian safe
authorAnton Blanchard <anton@samba.org>
Tue, 6 Aug 2013 16:01:40 +0000 (02:01 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 14 Aug 2013 05:33:29 +0000 (15:33 +1000)
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/kernel/vio.c

index 31875a6002b783a199fbb2af1cbb913117d7fc84..78a350670de32b4ba7013ea8fefe2ab5c0d5d626 100644 (file)
@@ -1312,8 +1312,7 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
 {
        struct vio_dev *viodev;
        struct device_node *parent_node;
-       const unsigned int *unit_address;
-       const unsigned int *pfo_resid = NULL;
+       const __be32 *prop;
        enum vio_dev_family family;
        const char *of_node_name = of_node->name ? of_node->name : "<unknown>";
 
@@ -1360,6 +1359,8 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
        /* we need the 'device_type' property, in order to match with drivers */
        viodev->family = family;
        if (viodev->family == VDEVICE) {
+               unsigned int unit_address;
+
                if (of_node->type != NULL)
                        viodev->type = of_node->type;
                else {
@@ -1368,24 +1369,24 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
                        goto out;
                }
 
-               unit_address = of_get_property(of_node, "reg", NULL);
-               if (unit_address == NULL) {
+               prop = of_get_property(of_node, "reg", NULL);
+               if (prop == NULL) {
                        pr_warn("%s: node %s missing 'reg'\n",
                                        __func__, of_node_name);
                        goto out;
                }
-               dev_set_name(&viodev->dev, "%x", *unit_address);
+               unit_address = of_read_number(prop, 1);
+               dev_set_name(&viodev->dev, "%x", unit_address);
                viodev->irq = irq_of_parse_and_map(of_node, 0);
-               viodev->unit_address = *unit_address;
+               viodev->unit_address = unit_address;
        } else {
                /* PFO devices need their resource_id for submitting COP_OPs
                 * This is an optional field for devices, but is required when
                 * performing synchronous ops */
-               pfo_resid = of_get_property(of_node, "ibm,resource-id", NULL);
-               if (pfo_resid != NULL)
-                       viodev->resource_id = *pfo_resid;
+               prop = of_get_property(of_node, "ibm,resource-id", NULL);
+               if (prop != NULL)
+                       viodev->resource_id = of_read_number(prop, 1);
 
-               unit_address = NULL;
                dev_set_name(&viodev->dev, "%s", of_node_name);
                viodev->type = of_node_name;
                viodev->irq = 0;
@@ -1622,7 +1623,6 @@ static struct vio_dev *vio_find_name(const char *name)
  */
 struct vio_dev *vio_find_node(struct device_node *vnode)
 {
-       const uint32_t *unit_address;
        char kobj_name[20];
        struct device_node *vnode_parent;
        const char *dev_type;
@@ -1638,10 +1638,13 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
 
        /* construct the kobject name from the device node */
        if (!strcmp(dev_type, "vdevice")) {
-               unit_address = of_get_property(vnode, "reg", NULL);
-               if (!unit_address)
+               const __be32 *prop;
+               
+               prop = of_get_property(vnode, "reg", NULL);
+               if (!prop)
                        return NULL;
-               snprintf(kobj_name, sizeof(kobj_name), "%x", *unit_address);
+               snprintf(kobj_name, sizeof(kobj_name), "%x",
+                        (uint32_t)of_read_number(prop, 1));
        } else if (!strcmp(dev_type, "ibm,platform-facilities"))
                snprintf(kobj_name, sizeof(kobj_name), "%s", vnode->name);
        else