Skip to content

Commit

Permalink
EDAC, altera: Simplify calculation of total memory
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chris Packham authored and Borislav Petkov committed Jun 14, 2017
1 parent 133e445 commit ff0abed
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions drivers/edac/altera_edac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ff0abed

Please sign in to comment.