EDAC, altera: Simplify calculation of total memory
authorChris Packham <chris.packham@alliedtelesis.co.nz>
Tue, 6 Jun 2017 23:54:59 +0000 (11:54 +1200)
committerBorislav Petkov <bp@suse.de>
Wed, 14 Jun 2017 11:49:25 +0000 (13:49 +0200)
Use of_address_to_resource() and resource_size() instead of manually
parsing the "reg" property from the "memory" node(s).

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Tested-by: Thor Thayer <thor.thayer@linux.intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/20170606235500.22772-3-chris.packham@alliedtelesis.co.nz
Signed-off-by: Borislav Petkov <bp@suse.de>
drivers/edac/altera_edac.c

index 122637530b15eefe383f17a9dc757f986f15b70b..db75d4b614f72372a5551f96181fb0b228db1eda 100644 (file)
@@ -214,24 +214,16 @@ static void altr_sdr_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
 static unsigned long get_total_mem(void)
 {
        struct device_node *np = NULL;
-       const unsigned int *reg, *reg_end;
-       int len, sw, aw;
-       unsigned long start, size, total_mem = 0;
+       struct resource res;
+       int ret;
+       unsigned long total_mem = 0;
 
        for_each_node_by_type(np, "memory") {
-               aw = of_n_addr_cells(np);
-               sw = of_n_size_cells(np);
-               reg = (const unsigned int *)of_get_property(np, "reg", &len);
-               reg_end = reg + (len / sizeof(u32));
-
-               total_mem = 0;
-               do {
-                       start = of_read_number(reg, aw);
-                       reg += aw;
-                       size = of_read_number(reg, sw);
-                       reg += sw;
-                       total_mem += size;
-               } while (reg < reg_end);
+               ret = of_address_to_resource(np, 0, &res);
+               if (ret)
+                       continue;
+
+               total_mem += resource_size(&res);
        }
        edac_dbg(0, "total_mem 0x%lx\n", total_mem);
        return total_mem;