of/mdio: Fix some endianness problems.
authorDavid Daney <ddaney@caviumnetworks.com>
Thu, 28 Oct 2010 01:03:47 +0000 (18:03 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Fri, 24 Dec 2010 08:25:54 +0000 (01:25 -0700)
In of_mdiobus_register(), the __be32 *addr variable is dereferenced.
This will not work on little-endian targets.  Also since it is
unsigned, checking for less than zero is redundant.

Fix these two issues.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
[grant.likely@secretlab.ca: removed goto]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
drivers/of/of_mdio.c

index 1fce00eb421bfc68ae531136a240680b66db4635..dcd7857784f24373f673ca2d027cc6a4a06be590 100644 (file)
@@ -52,27 +52,35 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 
        /* Loop over the child nodes and register a phy_device for each one */
        for_each_child_of_node(np, child) {
-               const __be32 *addr;
+               const __be32 *paddr;
+               u32 addr;
                int len;
 
                /* A PHY must have a reg property in the range [0-31] */
-               addr = of_get_property(child, "reg", &len);
-               if (!addr || len < sizeof(*addr) || *addr >= 32 || *addr < 0) {
+               paddr = of_get_property(child, "reg", &len);
+               if (!paddr || len < sizeof(*paddr)) {
                        dev_err(&mdio->dev, "%s has invalid PHY address\n",
                                child->full_name);
                        continue;
                }
 
+               addr = be32_to_cpup(paddr);
+               if (addr >= 32) {
+                       dev_err(&mdio->dev, "%s PHY address %i is too large\n",
+                               child->full_name, addr);
+                       continue;
+               }
+
                if (mdio->irq) {
-                       mdio->irq[*addr] = irq_of_parse_and_map(child, 0);
-                       if (!mdio->irq[*addr])
-                               mdio->irq[*addr] = PHY_POLL;
+                       mdio->irq[addr] = irq_of_parse_and_map(child, 0);
+                       if (!mdio->irq[addr])
+                               mdio->irq[addr] = PHY_POLL;
                }
 
-               phy = get_phy_device(mdio, be32_to_cpup(addr));
+               phy = get_phy_device(mdio, addr);
                if (!phy || IS_ERR(phy)) {
                        dev_err(&mdio->dev, "error probing PHY at address %i\n",
-                               *addr);
+                               addr);
                        continue;
                }
                phy_scan_fixups(phy);
@@ -91,7 +99,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
                }
 
                dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
-                       child->name, *addr);
+                       child->name, addr);
        }
 
        return 0;