The #address-cells and #size-cells properties need to be accounted for
when dealing with the "memory" device tree node. Use
of_address_to_resource() and resource_size() to retrieve the size of the
memory node which will automatically take the #cells into account.

Signed-off-by: Chris Packham <chris.pack...@alliedtelesis.co.nz>
---
Changes in v2:
- Use of_address_to_resource() instead of manually parsing the reg property.

 drivers/edac/mv64x60_edac.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index 3461db3723cb..93623e704623 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include <linux/edac.h>
 #include <linux/gfp.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/of_device.h>
 
@@ -644,15 +645,19 @@ static irqreturn_t mv64x60_mc_isr(int irq, void *dev_id)
 static void get_total_mem(struct mv64x60_mc_pdata *pdata)
 {
        struct device_node *np = NULL;
-       const unsigned int *reg;
+       struct resource res;
+       int ret;
+       unsigned long total_mem = 0;
 
-       np = of_find_node_by_type(NULL, "memory");
-       if (!np)
-               return;
+       for_each_node_by_type(np, "memory") {
+               ret = of_address_to_resource(np, 0, &res);
+               if (ret)
+                       continue;
 
-       reg = of_get_property(np, "reg", NULL);
+               total_mem += resource_size(&res);
+       }
 
-       pdata->total_mem = reg[1];
+       pdata->total_mem = total_mem;
 }
 
 static void mv64x60_init_csrows(struct mem_ctl_info *mci,
-- 
2.13.0

Reply via email to