From patchwork Mon Jun 24 15:09:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 167623 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4348969ilk; Mon, 24 Jun 2019 08:10:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBd+dO5sjGBr3QET4/CVJQdI3IXlCXHYyQXlWiUBD8OmX9QKx2XIFwuEykKrLhHd9z89NW X-Received: by 2002:a17:90a:35e5:: with SMTP id r92mr25888009pjb.34.1561389035188; Mon, 24 Jun 2019 08:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561389035; cv=none; d=google.com; s=arc-20160816; b=igr9XuE4ee91jlDbEERksfcbriM2S4lgGuGCnL7ud8nYv4evfW4LF13uYaJpKs+/mz 3mWaNAd9CrGjcG6PHUDW+fG+RU+COB3GsHkTubvC1x83NiZSV+2hKSCivWmfW9WvH6AS zGLTGoLAzChjN1vVJcdhpj59b4Q5SU6SFe1W1SxnfRrRtc9cT9Mzl7KS5qN0SspQRb4B dEQ4LQFvdx1KLauCGYpENlie3JICrHXAi++LerFWlbwuC4kZLSDWno0eMncTg73Fv/c/ tCQUQUQGygY72vSgY+IOo/49bvpLyzde8R3nrRAVe+HFA+UY4kVdEcebeEib56catAaI sUhg== 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=4OEMZvb8Lzhd7nbkHxlbYtcKV2x+fbwoOs0MM31fHPM=; b=A+/2cWg3w7YM0loMAFkLHhmucX1Y7aerZE8IrZc6c8MFfFHMi6yUd5Igrp9XQYJyZv 1hZgr1LooD+eXJh1lwiq/dURkfM3hCJrqpZgXTmjAilK6bmmQZipvr0uy2IyhmFckWJ6 Gu/nuy5TVe71LsHV/Qkx88k3+LVcbjqHWoJYTqFL+4NESEQKeBIBC9rxHgbKZjECqnJa tOodxzk++FXqSY/HHNl6n/nWs+n0446kgpXyTMeR+bixur904Kj8sQi/E6yvEHmKaimk ESewHeyjR6B5zgmzdIUg3ysCeZRl7CVvZpPBZg1gVEAMFeG55z+r/HcOJoSwKEysS2Zq iYrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0818 header.b=SzXJc5Iy; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=GXGAiGzu; 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 a14si11359572pfo.37.2019.06.24.08.10.34; Mon, 24 Jun 2019 08:10:35 -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=SzXJc5Iy; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=GXGAiGzu; 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 S1730607AbfFXPJa (ORCPT + 30 others); Mon, 24 Jun 2019 11:09:30 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:32756 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbfFXPJV (ORCPT ); Mon, 24 Jun 2019 11:09:21 -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 x5OF8Eah025899; Mon, 24 Jun 2019 08:09:14 -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=4OEMZvb8Lzhd7nbkHxlbYtcKV2x+fbwoOs0MM31fHPM=; b=SzXJc5Iynt07gSc9jCjzie6sgET9jj6EVDnkqV5mU3vWOWK4oYXA6XLrSWJAXm4hWjBw p689tgpNKMFHNt+i/I0/WDukvES5YsICu/lOOQziirhuoFR55LZCujnKz0dEwi9dnrRp j5rEGio1vbXSsvZtAIij9cSUis+nfWpfphOvdXqb8ScAgwSEoApllE63g5dnYw867ofu vQsYt4RlpYp+Sp2+Eh9auLH7dGq+hCIjy+3L8k0dyO4fiGB9/e7bbt9ZX7jgE0c6YeSX vfXpkiYDOrnuHT9P1z94TChv1TVnhxYo0NDwJneWPdEHAfVfZa1ubRPLKEn7789KbCj6 8w== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2t9kujf7s1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 24 Jun 2019 08:09:14 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 24 Jun 2019 08:09:12 -0700 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (104.47.42.53) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 24 Jun 2019 08:09:12 -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=4OEMZvb8Lzhd7nbkHxlbYtcKV2x+fbwoOs0MM31fHPM=; b=GXGAiGzux6bHrVkHdLxCIhdJyxYx660FfI/skiFAJulxadE32GL7pq3+NiyaVcIMmTVN2/0aErFZE92AAeJTdWSJvH19iaWaniIc54HLZa7sJtmliR/t6w+FLsM7kS9SF0z7r8ApqDkq6SnZeyinVq3P+PqnoD6lZON8fMbEJHo= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.238.217) by MN2PR18MB3197.namprd18.prod.outlook.com (10.255.236.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2008.13; Mon, 24 Jun 2019 15:09:11 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::d3:794c:1b94:cf3]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::d3:794c:1b94:cf3%4]) with mapi id 15.20.2008.014; Mon, 24 Jun 2019 15:09:11 +0000 From: Robert Richter To: Borislav Petkov , James Morse , "Mauro Carvalho Chehab" CC: "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Robert Richter Subject: [PATCH v2 08/24] EDAC: Introduce mci_for_each_dimm() iterator Thread-Topic: [PATCH v2 08/24] EDAC: Introduce mci_for_each_dimm() iterator Thread-Index: AQHVKp7HblTk+aCg90ebZ91+8B0kzw== Date: Mon, 24 Jun 2019 15:09:11 +0000 Message-ID: <20190624150758.6695-9-rrichter@marvell.com> References: <20190624150758.6695-1-rrichter@marvell.com> In-Reply-To: <20190624150758.6695-1-rrichter@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1P190CA0035.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::24) 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: [92.254.182.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6def1f41-8444-4e5d-141c-08d6f8b5e98c x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR18MB3197; x-ms-traffictypediagnostic: MN2PR18MB3197: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:148; x-forefront-prvs: 007814487B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(366004)(136003)(396003)(346002)(376002)(199004)(189003)(36756003)(110136005)(107886003)(54906003)(81156014)(81166006)(68736007)(8676002)(25786009)(5660300002)(8936002)(305945005)(7736002)(4326008)(1076003)(186003)(6116002)(14454004)(476003)(486006)(2616005)(11346002)(256004)(14444005)(446003)(3846002)(50226002)(26005)(2906002)(52116002)(76176011)(71200400001)(71190400001)(99286004)(386003)(6506007)(102836004)(478600001)(316002)(86362001)(6512007)(66066001)(53936002)(6486002)(73956011)(66946007)(66476007)(66556008)(64756008)(66446008)(6436002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB3197; H:MN2PR18MB3408.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: /I/q1yPT92DWSX6kTI8GN+lZkxGmIAcurMoZh9rszKiY1puH+FLCw9ymDEq2uCUBEFS6YcjUHwDwp/376OKA5zznMZxVo3mNNBjLsXJcs3MoQR/IsbaJMyXDFKhaI0a/3JpRIesnRZHXf/RdnU1DjUBUiPvWdMPrTD5SoC9gqg7mMy9X0Vext2b7BrLSeRDzOQ1/EDCVeMmjno70JR6J4eVmSeppn2F0j309Cv4a89hGByQdalbXYFH4USazIPpQzYGUMAQ95kxlqFpPxxVuyjOlGu2T7/KAFz53DJdlL/yfTeNfNan46PNu5hFX0v/DknL/JjAltoc+Hz1IhajkeUNNxE8E2G3swmrNasqA7pCB+R6ePAU3S9M6QFJpUH/OGpx4sKvXx6lohdMKZWMNhKn31qhJmM+Ue4CdYQQbSU4= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 6def1f41-8444-4e5d-141c-08d6f8b5e98c X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2019 15:09:11.6011 (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: MN2PR18MB3197 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-24_10:, , 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 c44bc83e8502..27277ca46ab3 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); @@ -1104,6 +1107,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 }; @@ -1163,9 +1167,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 a69e99206a6f..4d15c88a52cd 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -623,8 +623,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; @@ -634,9 +633,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); @@ -910,7 +909,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; @@ -933,14 +933,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++) @@ -950,9 +949,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; } } @@ -967,12 +967,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); @@ -984,7 +981,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"); @@ -995,8 +992,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 8050f9577fe6..72e75ea5526c 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -81,11 +81,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