From patchwork Tue Jun 6 23:55:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 772075 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wj7wM1t8rz9s7B for ; Wed, 7 Jun 2017 10:00:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="DxjeGch6"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wj7wM0ly3zDqNb for ; Wed, 7 Jun 2017 10:00:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="DxjeGch6"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [IPv6:2001:df5:b000:5::4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wj7pz272BzDqCv for ; Wed, 7 Jun 2017 09:55:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="DxjeGch6"; dkim-atps=neutral Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 920698448C; Wed, 7 Jun 2017 11:55:18 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1496793318; bh=+OzN2IWi6E+ps+5ngMOjDvvg+m8Kn5O9Z5qY1UyPP1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DxjeGch6NlprTynY/wI5TO4tL/2sZEBuWJXFdiqbjv6L/i7Ike1A42n5dNeuUz8Up M3+e6eUMcKDlbdnsnXeV3mxhedtEe0Ffm1mVGaVWRcDZ49swlkuWUnIcISz5WQZDAw DXFx1R4LkdFkPEH1/Xvh8fHDBpg6Sq9agaq/em38= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 9061) id ; Wed, 07 Jun 2017 11:55:19 +1200 Received: from chrisp-dl.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id 6A40613EFF0; Wed, 7 Jun 2017 11:55:21 +1200 (NZST) Received: by chrisp-dl.atlnz.lc (Postfix, from userid 1030) id 40EFD1E1E3A; Wed, 7 Jun 2017 11:55:18 +1200 (NZST) From: Chris Packham To: bp@alien8.de, linux-edac@vger.kernel.org Subject: [PATCH v2 3/3] EDAC: cpc925: simplify calculation of total memory Date: Wed, 7 Jun 2017 11:55:00 +1200 Message-Id: <20170606235500.22772-4-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170606235500.22772-1-chris.packham@alliedtelesis.co.nz> References: <20170606235500.22772-1-chris.packham@alliedtelesis.co.nz> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mchehab@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Chris Packham Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 --- 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 #include #include +#include #include #include @@ -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); }