From patchwork Wed May 29 08:44:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 165349 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp9580993ili; Wed, 29 May 2019 01:45:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrij3SyyrRIwYhZ8SPPu90u01KgycCaYVV6UWqLCfVhm1h2mGyBC15sXqh9bSeVIuc0k+O X-Received: by 2002:a17:902:2a68:: with SMTP id i95mr2668220plb.167.1559119552479; Wed, 29 May 2019 01:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559119552; cv=none; d=google.com; s=arc-20160816; b=RzLnkrDaJE3oGfQb92QHq1TdOQdLTGMbU3FkMmuLZT4srZ4CJHsJYoXcpx1gr9/iot /K5n3HmLz2D1mtuHpcrbR23yXn2truljfzSvEK/nv0S5Q63X24AL6U0qLBaioZiPLsPd bnz6TBChhcuQLxiIRgZs21rlfWZbMvGvx9IdaRcM3xTDaYuBWpg65IIiFPzahYrkOcSH GDj6If5lzUej0rJvhZSZ4nZYgzA2Hj3lhH+gn24/VBYdw1lL+OIYZIpV5qKMFVx68Etw /klcxVdOmu3iRvsE/YorwythTlucr669grK5say+phQ/yejrrAaxKk1imUJyzKEWAVOa CpCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature; bh=wzWksusEaTyX0Xqg/yKi2uWhEhxqWz63CbuF6f9E0Qk=; b=TQNJ7sAz9GC7RsWgXGBw1555S5ik5jcJfEcEFsfb4tdw3rB+vOZSWPmPEiD1iq+xgy U2hLUH9Xjn/H0HX8glXn6557AmZzOcxyyuUY+CUWnWt7szHPel+sD9beX8PN9VE9WxIJ XKM5VjIN/t+0CK0htEsf3I81E8CbI5m5y8FNHpS0e9t5nHN490AZPnKyjboBS12hkEuX Bq2iAMiMmu4xoxr38d49SXeZcNkUDQMomr3VHy/VZgVaW2nRx43i7Pwrc88oXsaoCFUT yyZnsqF9oBHk/1kzv90I0Mg7yxXa2gJ3UpcSS+YQ9MH2ThnUVrpWzaejmciI/ki5WD3Y FxYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0818 header.b=PeclCnA6; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=HQhogKUj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1si26711438pgj.147.2019.05.29.01.45.52; Wed, 29 May 2019 01:45:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0818 header.b=PeclCnA6; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=HQhogKUj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfE2Iod (ORCPT + 30 others); Wed, 29 May 2019 04:44:33 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:49482 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfE2Io3 (ORCPT ); Wed, 29 May 2019 04:44:29 -0400 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4T8dpBF017806; Wed, 29 May 2019 01:44:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=wzWksusEaTyX0Xqg/yKi2uWhEhxqWz63CbuF6f9E0Qk=; b=PeclCnA6+pFzsa+zH4bB1fGAKk5ZgZ1pWjiUaboYtN6lhmId/njb+4IA7RQS4NuSTZdh 9dFSnxK4DHxzvZ25BlKQ3D84LR1kJOdr+13YLoFjaxJK0aX1LWDqcuPDaoyUS6GlsPGY IBd9Ib077b+M5DLWbFnjK6+EifMlDMfOLQnGF1f7injmiNdWTnU463NH/a6RxCeoGwsh lAci4PpMfBCZBAE8A/tyld/DXkChgl+49KFhcyRDoHiVt4wGl1RFe3mHs7KWVZQw3YQP YLiMMrEVL8rZO5wf+rpT6DSnxZ67OOvdFVCFaTbd4I9WOGdhFrO4ssWyMrX9rs6fKBqC mw== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2sskp88p4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 29 May 2019 01:44:18 -0700 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 29 May 2019 01:44:17 -0700 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (104.47.40.59) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Wed, 29 May 2019 01:44:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector2-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wzWksusEaTyX0Xqg/yKi2uWhEhxqWz63CbuF6f9E0Qk=; b=HQhogKUjY+mr+uaNLIVZ5gH1uDzxZoQCYoH0dc5L/pFC2TX1/hYgUB0gkA26ebuE3cPPzyiDmW7nYxY4KSHMNsT8OipYQMnaeFbskMsJSo2iNGSLkb5/vFApvMD7G687uQlJ6jrRw4/uR7/tfZvxD71RX3z/TxHe+n5LG461hkU= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.238.217) by MN2PR18MB3437.namprd18.prod.outlook.com (10.255.239.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.20; Wed, 29 May 2019 08:44:15 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::7c9a:f3bf:fe2e:fe4a]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::7c9a:f3bf:fe2e:fe4a%4]) with mapi id 15.20.1922.021; Wed, 29 May 2019 08:44:15 +0000 From: Robert Richter To: Borislav Petkov , Tony Luck , "James Morse" , Mauro Carvalho Chehab CC: "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Robert Richter Subject: [PATCH 05/21] EDAC: Introduce mci_for_each_dimm() iterator Thread-Topic: [PATCH 05/21] EDAC: Introduce mci_for_each_dimm() iterator Thread-Index: AQHVFfqyZ42X6bVw40qQR+81APMGEQ== Date: Wed, 29 May 2019 08:44:15 +0000 Message-ID: <20190529084344.28562-6-rrichter@marvell.com> References: <20190529084344.28562-1-rrichter@marvell.com> In-Reply-To: <20190529084344.28562-1-rrichter@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR01CA0046.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::23) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:16c::25) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [78.54.13.57] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6d80d6cc-c981-41cc-d3ab-08d6e411d489 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR18MB3437; x-ms-traffictypediagnostic: MN2PR18MB3437: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:148; x-forefront-prvs: 0052308DC6 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(346002)(396003)(376002)(39860400002)(136003)(189003)(199004)(8936002)(4326008)(53936002)(50226002)(110136005)(107886003)(68736007)(36756003)(5660300002)(54906003)(11346002)(26005)(186003)(52116002)(2906002)(2616005)(476003)(446003)(6506007)(14454004)(66476007)(25786009)(478600001)(386003)(86362001)(486006)(81166006)(81156014)(8676002)(305945005)(316002)(7736002)(14444005)(256004)(99286004)(76176011)(6512007)(6436002)(73956011)(64756008)(66446008)(66556008)(66066001)(3846002)(66946007)(1076003)(6486002)(102836004)(71190400001)(71200400001)(6116002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB3437; H:MN2PR18MB3408.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: YtrkEShsXDpods6VL7CkS3LZzfiT0tv7nBxNTChJTaq7LqLc4D/hSZIlLfHD4OaeBugr3kBuQitKN3eGvYC1cB30+maqYmNOJUQ0s02LhoRrcNI1IapgjZKL/KOJAI+OjAQvABdaOT84BQ2wIfQEgxeSNHCmjwJKgJBc8lZ+w3QlMqDJBD1V9cRESP0x64lw+9US8dBSTtLy/dswkp8n8B6eKGCDUOAMM/PIkTkSLKubVzEDzsv9ISzWOEHRhToLFMHgyQRXZjnDniDs8G3KG3g63vOolglB3FHknzkKU/VBuzzeIrAmJ8r+bV6bjltMOaGe1PqHHwZdVodq7F5OoX+PLDtAegYHGI9lrh/Dv7aMsUGkDobFjgd8VOMhff/0PgodBaj/hR1woRaexK0QJQc46l6JyrLgm4IaW80HCl4= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 6d80d6cc-c981-41cc-d3ab-08d6e411d489 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 May 2019 08:44:15.5446 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rrichter@marvell.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3437 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-05-29_05:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make code more readable by introducing a mci_for_each_dimm() iterator. Now, we just get a pointer to a struct dimm_info. Direct array access using an index is no longer needed to iterate. Signed-off-by: Robert Richter --- drivers/edac/edac_mc.c | 18 ++++++++++-------- drivers/edac/edac_mc_sysfs.c | 34 +++++++++++++++------------------- drivers/edac/ghes_edac.c | 8 ++++---- drivers/edac/i5100_edac.c | 11 +++++------ include/linux/edac.h | 7 +++++++ 5 files changed, 41 insertions(+), 37 deletions(-) -- 2.20.1 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 07edbd80af07..a6b34ccce3d4 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -145,15 +145,18 @@ static void edac_mc_dump_channel(struct rank_info *chan) edac_dbg(4, " channel->dimm = %p\n", chan->dimm); } -static void edac_mc_dump_dimm(struct dimm_info *dimm, int number) +static void edac_mc_dump_dimm(struct dimm_info *dimm) { char location[80]; + if (!dimm->nr_pages) + return; + edac_dimm_info_location(dimm, location, sizeof(location)); edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n", dimm->mci->csbased ? "rank" : "dimm", - number, location, dimm->csrow, dimm->cschannel); + dimm->idx, location, dimm->csrow, dimm->cschannel); edac_dbg(4, " dimm = %p\n", dimm); edac_dbg(4, " dimm->label = '%s'\n", dimm->label); edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages); @@ -703,6 +706,7 @@ EXPORT_SYMBOL_GPL(edac_get_owner); int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, const struct attribute_group **groups) { + struct dimm_info *dimm; int ret = -EINVAL; edac_dbg(0, "\n"); @@ -727,9 +731,8 @@ int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci, if (csrow->channels[j]->dimm->nr_pages) edac_mc_dump_channel(csrow->channels[j]); } - for (i = 0; i < mci->tot_dimms; i++) - if (mci->dimms[i]->nr_pages) - edac_mc_dump_dimm(mci->dimms[i], i); + mci_for_each_dimm(mci, dimm) + edac_mc_dump_dimm(dimm); } #endif mutex_lock(&mem_ctls_mutex); @@ -1087,6 +1090,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, const char *msg, const char *other_detail) { + struct dimm_info *dimm; char *p; int row = -1, chan = -1; int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer }; @@ -1147,9 +1151,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, p = e->label; *p = '\0'; - for (i = 0; i < mci->tot_dimms; i++) { - struct dimm_info *dimm = mci->dimms[i]; - + mci_for_each_dimm(mci, dimm) { if (top_layer >= 0 && top_layer != dimm->location[0]) continue; if (mid_layer >= 0 && mid_layer != dimm->location[1]) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 8beefa699a49..75cba0812a16 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -622,8 +622,7 @@ static const struct device_type dimm_attr_type = { /* Create a DIMM object under specifed memory controller device */ static int edac_create_dimm_object(struct mem_ctl_info *mci, - struct dimm_info *dimm, - int index) + struct dimm_info *dimm) { int err; dimm->mci = mci; @@ -633,9 +632,9 @@ static int edac_create_dimm_object(struct mem_ctl_info *mci, dimm->dev.parent = &mci->dev; if (mci->csbased) - dev_set_name(&dimm->dev, "rank%d", index); + dev_set_name(&dimm->dev, "rank%d", dimm->idx); else - dev_set_name(&dimm->dev, "dimm%d", index); + dev_set_name(&dimm->dev, "dimm%d", dimm->idx); dev_set_drvdata(&dimm->dev, dimm); pm_runtime_forbid(&mci->dev); @@ -909,7 +908,8 @@ static const struct device_type mci_attr_type = { int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, const struct attribute_group **groups) { - int i, err; + struct dimm_info *dimm; + int err; /* get the /sys/devices/system/edac subsys reference */ mci->dev.type = &mci_attr_type; @@ -932,14 +932,13 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, /* * Create the dimm/rank devices */ - for (i = 0; i < mci->tot_dimms; i++) { - struct dimm_info *dimm = mci->dimms[i]; + mci_for_each_dimm(mci, dimm) { /* Only expose populated DIMMs */ if (!dimm->nr_pages) continue; #ifdef CONFIG_EDAC_DEBUG - edac_dbg(1, "creating dimm%d, located at ", i); + edac_dbg(1, "creating dimm%d, located at ", dimm->idx); if (edac_debug_level >= 1) { int lay; for (lay = 0; lay < mci->n_layers; lay++) @@ -949,9 +948,10 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, printk(KERN_CONT "\n"); } #endif - err = edac_create_dimm_object(mci, dimm, i); + err = edac_create_dimm_object(mci, dimm); if (err) { - edac_dbg(1, "failure: create dimm %d obj\n", i); + edac_dbg(1, "failure: create dimm %d obj\n", + dimm->idx); goto fail_unregister_dimm; } } @@ -966,12 +966,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, return 0; fail_unregister_dimm: - for (i--; i >= 0; i--) { - struct dimm_info *dimm = mci->dimms[i]; - if (!dimm->nr_pages) - continue; - - device_unregister(&dimm->dev); + mci_for_each_dimm(mci, dimm) { + if (device_is_registered(&dimm->dev)) + device_unregister(&dimm->dev); } device_unregister(&mci->dev); @@ -983,7 +980,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, */ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) { - int i; + struct dimm_info *dimm; edac_dbg(0, "\n"); @@ -994,8 +991,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) edac_delete_csrow_objects(mci); #endif - for (i = 0; i < mci->tot_dimms; i++) { - struct dimm_info *dimm = mci->dimms[i]; + mci_for_each_dimm(mci, dimm) { if (dimm->nr_pages == 0) continue; edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev)); diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c index 42afa2604db3..fe45392f0c3e 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -84,11 +84,11 @@ static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg) static int get_dimm_smbios_index(u16 handle) { struct mem_ctl_info *mci = ghes_pvt->mci; - int i; + struct dimm_info *dimm; - for (i = 0; i < mci->tot_dimms; i++) { - if (mci->dimms[i]->smbios_handle == handle) - return i; + mci_for_each_dimm(mci, dimm) { + if (dimm->smbios_handle == handle) + return dimm->idx; } return -1; } diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c index 39ba7f2414ae..7ec42b26a716 100644 --- a/drivers/edac/i5100_edac.c +++ b/drivers/edac/i5100_edac.c @@ -846,14 +846,13 @@ static void i5100_init_interleaving(struct pci_dev *pdev, static void i5100_init_csrows(struct mem_ctl_info *mci) { - int i; struct i5100_priv *priv = mci->pvt_info; + struct dimm_info *dimm; - for (i = 0; i < mci->tot_dimms; i++) { - struct dimm_info *dimm; - const unsigned long npages = i5100_npages(mci, i); - const unsigned chan = i5100_csrow_to_chan(mci, i); - const unsigned rank = i5100_csrow_to_rank(mci, i); + mci_for_each_dimm(mci, dimm) { + const unsigned long npages = i5100_npages(mci, dimm->idx); + const unsigned chan = i5100_csrow_to_chan(mci, dimm->idx); + const unsigned rank = i5100_csrow_to_rank(mci, dimm->idx); if (!npages) continue; diff --git a/include/linux/edac.h b/include/linux/edac.h index 2ee9b8598ae0..20a04f48616c 100644 --- a/include/linux/edac.h +++ b/include/linux/edac.h @@ -599,6 +599,13 @@ struct mem_ctl_info { u16 fake_inject_count; }; +#define mci_for_each_dimm(mci, dimm) \ + for ((dimm) = (mci)->dimms[0]; \ + (dimm); \ + (dimm) = (dimm)->idx < (mci)->tot_dimms \ + ? (mci)->dimms[(dimm)->idx + 1] \ + : NULL) + /** * edac_get_dimm_by_index - Get DIMM info from a memory controller * given by an index