Use helper function of_property_read_u32() in place of of_get_property <br>and be32_to_cpup() api's for code optimization.<br><br>Compile tested the changes.<br><br>Signed-off-by: G, Manjunath Kondaiah <<a href="mailto:manjugk@ti.com">manjugk@ti.com</a>><br>
---<br> drivers/of/irq.c     |   37 ++++++++++++++++++++++---------------<br> drivers/of/of_i2c.c  |    8 +++-----<br> drivers/of/of_mdio.c |   16 ++++++----------<br> 3 files changed, 31 insertions(+), 30 deletions(-)<br>
<br>diff --git a/drivers/of/irq.c b/drivers/of/irq.c<br>index 9f689f1..13c02e2 100644<br>--- a/drivers/of/irq.c<br>+++ b/drivers/of/irq.c<br>@@ -59,20 +59,20 @@ EXPORT_SYMBOL_GPL(irq_of_parse_and_map);<br> struct device_node *of_irq_find_parent(struct device_node *child)<br>
 {<br>     struct device_node *p;<br>-    const __be32 *parp;<br>+    u32 *parp = NULL;<br> <br>     if (!of_node_get(child))<br>         return NULL;<br> <br>     do {<br>-        parp = of_get_property(child, "interrupt-parent", NULL);<br>
+        of_property_read_u32(child, "interrupt-parent", parp);<br>         if (parp == NULL)<br>             p = of_get_parent(child);<br>         else {<br>             if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)<br>
                 p = of_node_get(of_irq_dflt_pic);<br>             else<br>-                p = of_find_node_by_phandle(be32_to_cpup(parp));<br>+                p = of_find_node_by_phandle(*parp);<br>         }<br>         of_node_put(child);<br>
         child = p;<br>@@ -100,7 +100,8 @@ int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,<br>            u32 ointsize, const __be32 *addr, struct of_irq *out_irq)<br> {<br>     struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL;<br>
-    const __be32 *tmp, *imap, *imask;<br>+    const __be32 *imap, *imask;<br>+    u32 *tmp;<br>     u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0;<br>     int imaplen, match, i;<br> <br>@@ -115,9 +116,10 @@ int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,<br>
      * is none, we are nice and just walk up the tree<br>      */<br>     do {<br>-        tmp = of_get_property(ipar, "#interrupt-cells", NULL);<br>+        tmp = NULL;<br>+        of_property_read_u32(ipar, "#interrupt-cells", tmp);<br>
         if (tmp != NULL) {<br>-            intsize = be32_to_cpu(*tmp);<br>+            intsize = *tmp;<br>             break;<br>         }<br>         tnode = ipar;<br>@@ -139,14 +141,15 @@ int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,<br>
      */<br>     old = of_node_get(ipar);<br>     do {<br>-        tmp = of_get_property(old, "#address-cells", NULL);<br>+        tmp = NULL;<br>+        of_property_read_u32(old, "#address-cells", tmp);<br>
         tnode = of_get_parent(old);<br>         of_node_put(old);<br>         old = tnode;<br>     } while (old && tmp == NULL);<br>     of_node_put(old);<br>     old = NULL;<br>-    addrsize = (tmp == NULL) ? 2 : be32_to_cpu(*tmp);<br>
+    addrsize = (tmp == NULL) ? 2 : (*tmp);<br> <br>     pr_debug(" -> addrsize=%d\n", addrsize);<br> <br>@@ -225,14 +228,16 @@ int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,<br>             /* Get #interrupt-cells and #address-cells of new<br>
              * parent<br>              */<br>-            tmp = of_get_property(newpar, "#interrupt-cells", NULL);<br>+            tmp = NULL;<br>+            of_property_read_u32(newpar, "#interrupt-cells", tmp);<br>
             if (tmp == NULL) {<br>                 pr_debug(" -> parent lacks #interrupt-cells!\n");<br>                 goto fail;<br>             }<br>-            newintsize = be32_to_cpu(*tmp);<br>-            tmp = of_get_property(newpar, "#address-cells", NULL);<br>
-            newaddrsize = (tmp == NULL) ? 0 : be32_to_cpu(*tmp);<br>+            newintsize = *tmp;<br>+            tmp = NULL;<br>+            of_property_read_u32(newpar, "#address-cells", tmp);<br>+            newaddrsize = (tmp == NULL) ? 0 : (*tmp);<br>
 <br>             pr_debug(" -> newintsize=%d, newaddrsize=%d\n",<br>                 newintsize, newaddrsize);<br>@@ -284,7 +289,8 @@ EXPORT_SYMBOL_GPL(of_irq_map_raw);<br> int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq)<br>
 {<br>     struct device_node *p;<br>-    const __be32 *intspec, *tmp, *addr;<br>+    const __be32 *intspec, *addr;<br>+    u32 *tmp;<br>     u32 intsize, intlen;<br>     int res = -EINVAL;<br> <br>@@ -311,10 +317,11 @@ int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq<br>
         return -EINVAL;<br> <br>     /* Get size of interrupt specifier */<br>-    tmp = of_get_property(p, "#interrupt-cells", NULL);<br>+    tmp = NULL;<br>+    of_get_property(p, "#interrupt-cells", tmp);<br>
     if (tmp == NULL)<br>         goto out;<br>-    intsize = be32_to_cpu(*tmp);<br>+    intsize = *tmp;<br> <br>     pr_debug(" intsize=%d intlen=%d\n", intsize, intlen);<br> <br>diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c<br>
index f37fbeb..7113512 100644<br>--- a/drivers/of/of_i2c.c<br>+++ b/drivers/of/of_i2c.c<br>@@ -32,8 +32,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)<br>     for_each_child_of_node(adap->dev.of_node, node) {<br>
         struct i2c_board_info info = {};<br>         struct dev_archdata dev_ad = {};<br>-        const __be32 *addr;<br>-        int len;<br>+        u32 *addr = NULL;<br> <br>         dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);<br>
 <br>@@ -43,14 +42,13 @@ void of_i2c_register_devices(struct i2c_adapter *adap)<br>             continue;<br>         }<br> <br>-        addr = of_get_property(node, "reg", &len);<br>-        if (!addr || (len < sizeof(int))) {<br>
+        if (of_get_property(node, "reg", addr)) {<br>             dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",<br>                 node->full_name);<br>             continue;<br>         }<br>
 <br>-        info.addr = be32_to_cpup(addr);<br>+        info.addr = *addr;<br>         if (info.addr > (1 << 10) - 1) {<br>             dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",<br>
                 info.addr, node->full_name);<br>diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c<br>index d35e300..d4b6503 100644<br>--- a/drivers/of/of_mdio.c<br>+++ b/drivers/of/of_mdio.c<br>@@ -52,19 +52,17 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)<br>
 <br>     /* Loop over the child nodes and register a phy_device for each one */<br>     for_each_child_of_node(np, child) {<br>-        const __be32 *paddr;<br>         u32 addr;<br>-        int len;<br>+        u32 *paddr = NULL;<br>
 <br>         /* A PHY must have a reg property in the range [0-31] */<br>-        paddr = of_get_property(child, "reg", &len);<br>-        if (!paddr || len < sizeof(*paddr)) {<br>+        if (of_property_read_u32(child, "reg", paddr)) {<br>
             dev_err(&mdio->dev, "%s has invalid PHY address\n",<br>                 child->full_name);<br>             continue;<br>         }<br> <br>-        addr = be32_to_cpup(paddr);<br>+        addr = *paddr;<br>
         if (addr >= 32) {<br>             dev_err(&mdio->dev, "%s PHY address %i is too large\n",<br>                 child->full_name, addr);<br>@@ -169,8 +167,7 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,<br>
     struct device_node *net_np;<br>     char bus_id[MII_BUS_ID_SIZE + 3];<br>     struct phy_device *phy;<br>-    const __be32 *phy_id;<br>-    int sz;<br>+    u32 *phy_id = NULL;<br> <br>     if (!dev->dev.parent)<br>
         return NULL;<br>@@ -179,11 +176,10 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,<br>     if (!net_np)<br>         return NULL;<br> <br>-    phy_id = of_get_property(net_np, "fixed-link", &sz);<br>
-    if (!phy_id || sz < sizeof(*phy_id))<br>+    if (of_property_read_u32(net_np, "fixed-link", phy_id))<br>         return NULL;<br> <br>-    sprintf(bus_id, PHY_ID_FMT, "0", be32_to_cpu(phy_id[0]));<br>
+    sprintf(bus_id, PHY_ID_FMT, "0", phy_id[0]);<br> <br>     phy = phy_connect(dev, bus_id, hndlr, 0, iface);<br>     return IS_ERR(phy) ? NULL : phy;<br>-- <br>1.7.4.1<br><br><br>