lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed,  7 Jun 2017 11:55:00 +1200
From:   Chris Packham <chris.packham@...iedtelesis.co.nz>
To:     bp@...en8.de, linux-edac@...r.kernel.org
Cc:     mchehab@...nel.org, mpe@...erman.id.au,
        linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
        Chris Packham <chris.packham@...iedtelesis.co.nz>
Subject: [PATCH v2 3/3] EDAC: cpc925: simplify calculation of total memory

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@...iedtelesis.co.nz>
---
Changes in v2:
- New

 drivers/edac/cpc925_edac.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c
index 837b62c4993d..ea347cd7eb92 100644
--- a/drivers/edac/cpc925_edac.c
+++ b/drivers/edac/cpc925_edac.c
@@ -24,6 +24,7 @@
 #include <linux/io.h>
 #include <linux/edac.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/gfp.h>
 
@@ -296,30 +297,17 @@ struct cpc925_dev_info {
 static void get_total_mem(struct cpc925_mc_pdata *pdata)
 {
 	struct device_node *np = NULL;
-	const unsigned int *reg, *reg_end;
-	int len, sw, aw;
-	unsigned long start, size;
+	struct resource res;
+	int ret;
 
-	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;
+
+		pdata->total_mem += resource_size(&res);
+	}
 
-	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/4;
-
-	pdata->total_mem = 0;
-	do {
-		start = of_read_number(reg, aw);
-		reg += aw;
-		size = of_read_number(reg, sw);
-		reg += sw;
-		edac_dbg(1, "start 0x%lx, size 0x%lx\n", start, size);
-		pdata->total_mem += size;
-	} while (reg < reg_end);
-
-	of_node_put(np);
 	edac_dbg(0, "total_mem 0x%lx\n", pdata->total_mem);
 }
 
-- 
2.13.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ