[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200422115814.22205-11-rrichter@marvell.com>
Date: Wed, 22 Apr 2020 13:58:14 +0200
From: Robert Richter <rrichter@...vell.com>
To: Borislav Petkov <bp@...en8.de>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Tony Luck <tony.luck@...el.com>
CC: James Morse <james.morse@....com>,
Aristeu Rozanski <aris@...hat.com>,
Robert Richter <rrichter@...vell.com>,
Matthias Brugger <mbrugger@...e.com>,
<linux-edac@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v2 10/10] EDAC/ghes: Carve out code into ghes_edac_register_{one,fake}()
Factor out code to register a memory controller including DIMMs. Do
this for standard and fake memory controller in the two functions
ghes_edac_register_one() and ghes_edac_register_fake().
Function ghes_edac_register_one() could be reused to register multiple
*mci structs.
Signed-off-by: Robert Richter <rrichter@...vell.com>
---
drivers/edac/ghes_edac.c | 80 ++++++++++++++++++++++------------------
1 file changed, 44 insertions(+), 36 deletions(-)
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index af72da156696..ee1e95e9b59b 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -610,11 +610,50 @@ static void ghes_mc_free(void)
edac_mc_free(mci);
}
-int ghes_edac_register(struct ghes *ghes, struct device *dev)
+static int ghes_edac_register_fake(struct device *dev)
+{
+ struct mem_ctl_info *mci;
+ struct dimm_info *dimm;
+ LIST_HEAD(empty);
+
+ mci = ghes_mc_create(dev, 0, 1);
+ if (!mci)
+ return -ENOMEM;
+
+ dimm = edac_get_dimm_by_index(mci, 0);
+
+ dimm->nr_pages = 1;
+ dimm->grain = 128;
+ dimm->mtype = MEM_UNKNOWN;
+ dimm->dtype = DEV_UNKNOWN;
+ dimm->edac_mode = EDAC_SECDED;
+
+ snprintf(dimm->label, sizeof(dimm->label), "unknown memory");
+
+ return ghes_mc_add_or_free(mci, &empty);
+}
+
+static int ghes_edac_register_one(struct device *dev, int mc_idx, int num_dimm)
{
struct dimm_fill dimm_fill;
- int rc = 0, num_dimm = 0;
struct mem_ctl_info *mci;
+
+ mci = ghes_mc_create(dev, mc_idx, num_dimm);
+ if (!mci)
+ return -ENOMEM;
+
+ dimm_fill.index = 0;
+ dimm_fill.mci = mci;
+ INIT_LIST_HEAD(&dimm_fill.dimms);
+
+ dmi_walk(ghes_edac_dmidecode, &dimm_fill);
+
+ return ghes_mc_add_or_free(mci, &dimm_fill.dimms);
+}
+
+int ghes_edac_register(struct ghes *ghes, struct device *dev)
+{
+ int rc = 0, num_dimm = 0;
int idx;
if (IS_ENABLED(CONFIG_X86)) {
@@ -648,27 +687,8 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev)
* with only one DIMM for the whole address range to
* catch all errros.
*/
- struct dimm_info *dimm;
- LIST_HEAD(empty);
-
- mci = ghes_mc_create(dev, 0, 1);
- if (!mci) {
- rc = -ENOMEM;
- goto unlock;
- }
-
- dimm = edac_get_dimm_by_index(mci, 0);
-
- dimm->nr_pages = 1;
- dimm->grain = 128;
- dimm->mtype = MEM_UNKNOWN;
- dimm->dtype = DEV_UNKNOWN;
- dimm->edac_mode = EDAC_SECDED;
-
- snprintf(dimm->label, sizeof(dimm->label), "unknown memory");
-
- rc = ghes_mc_add_or_free(mci, &empty);
- if (rc)
+ rc = ghes_edac_register_fake(dev);
+ if (rc < 0)
goto unlock;
pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n");
@@ -687,19 +707,7 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev)
pr_info("This system has %d DIMM sockets.\n", num_dimm);
}
- mci = ghes_mc_create(dev, 0, num_dimm);
- if (!mci) {
- rc = -ENOMEM;
- goto unlock;
- }
-
- dimm_fill.index = 0;
- dimm_fill.mci = mci;
- INIT_LIST_HEAD(&dimm_fill.dimms);
-
- dmi_walk(ghes_edac_dmidecode, &dimm_fill);
-
- rc = ghes_mc_add_or_free(mci, &dimm_fill.dimms);
+ rc = ghes_edac_register_one(dev, 0, num_dimm);
if (rc < 0)
goto unlock;
--
2.20.1
Powered by blists - more mailing lists