Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1658318

[PATCH] EDAC: mv64x60 calculate memory size correctly

From Chris Packham <chris.packham@alliedtelesis.co.nz>
Newsgroups linux.kernel
Subject [PATCH] EDAC: mv64x60 calculate memory size correctly
Date 2017-06-06 04:50 +0200
Message-ID <tPcJc-2P3-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


The #address-cells and #size-cells properties need to be accounted for
when dealing with the "memory" device tree node.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 drivers/edac/mv64x60_edac.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index 43efb086c0b4..09abb963688f 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -644,15 +644,27 @@ 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;
-
-	np = of_find_node_by_type(NULL, "memory");
-	if (!np)
-		return;
-
-	reg = of_get_property(np, "reg", NULL);
-
-	pdata->total_mem = reg[1];
+	const unsigned int *reg, *reg_end;
+	int len, sw, aw;
+	unsigned long start, size, total_mem = 0;
+
+	for_each_node_by_type(np, "memory") {
+		aw = of_n_addr_cells(np);
+		sw = of_n_size_cells(np);
+		reg = 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);
+	}
+
+	pdata->total_mem = total_mem;
 }
 
 static void mv64x60_init_csrows(struct mem_ctl_info *mci,
-- 
2.13.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] EDAC: mv64x60 calculate memory size correctly Chris Packham <chris.packham@alliedtelesis.co.nz> - 2017-06-06 04:50 +0200
  Re: [PATCH] EDAC: mv64x60 calculate memory size correctly Chris Packham <Chris.Packham@alliedtelesis.co.nz> - 2017-06-06 05:10 +0200
    Re: [PATCH] EDAC: mv64x60 calculate memory size correctly Borislav Petkov <bp@alien8.de> - 2017-06-06 19:00 +0200
      Re: [PATCH] EDAC: mv64x60 calculate memory size correctly Chris Packham <Chris.Packham@alliedtelesis.co.nz> - 2017-06-06 23:20 +0200
        Re: [PATCH] EDAC: mv64x60 calculate memory size correctly Borislav Petkov <bp@alien8.de> - 2017-06-07 11:10 +0200

csiph-web