linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: bp@alien8.de, linux-edac@vger.kernel.org
Cc: mchehab@kernel.org, mpe@ellerman.id.au,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH v2 1/3] EDAC: mv64x60: calculate memory size correctly
Date: Wed,  7 Jun 2017 11:54:58 +1200	[thread overview]
Message-ID: <20170606235500.22772-2-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20170606235500.22772-1-chris.packham@alliedtelesis.co.nz>

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.packham@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	other threads:[~2017-06-06 23:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-06 23:54 EDAC: simplify total memory calculation Chris Packham
2017-06-06 23:54 ` Chris Packham [this message]
2017-06-06 23:54 ` [PATCH v2 2/3] EDAC: altera: simplify calculation of total memory Chris Packham
2017-06-12 18:34   ` Thor Thayer
2017-06-14 11:50     ` Borislav Petkov
2017-06-06 23:55 ` [PATCH v2 3/3] EDAC: cpc925: " Chris Packham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170606235500.22772-2-chris.packham@alliedtelesis.co.nz \
    --to=chris.packham@alliedtelesis.co.nz \
    --cc=bp@alien8.de \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mchehab@kernel.org \
    --cc=mpe@ellerman.id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).