From: Rosen Penev <rosenp@gmail.com>
To: linux-edac@vger.kernel.org
Cc: Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-kernel@vger.kernel.org (open list),
llvm@lists.linux.dev (open list:CLANG/LLVM BUILD
SUPPORT:Keyword:\b(?i:clang|llvm)\b)
Subject: [PATCH] EDAC/cpc925: manage mci lifetime via devres and simplify ioremap
Date: Sun, 19 Jul 2026 14:35:32 -0700 [thread overview]
Message-ID: <20260719213532.695530-1-rosenp@gmail.com> (raw)
Replace the open-coded platform_get_resource() +
devm_request_mem_region() + devm_ioremap() sequence with the single
helper devm_platform_ioremap_resource(), dropping the redundant -ENOENT
and -EBUSY error paths.
Register an edac_mc_free() callback via devm_add_action_or_reset()
immediately after edac_mc_alloc() so the mem_ctl_info is owned by devres
and freed automatically on both probe failure and device removal. Drop
the explicit edac_mc_free() from the probe error path and
cpc925_remove(); the now-redundant devres group open/release calls are
removed as well.
Built for powerpc (CONFIG_EDAC_CPC925) with LLVM=1;
drivers/edac/cpc925_edac.o compiles cleanly and passes checkpatch
--strict.
Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/edac/cpc925_edac.c | 56 ++++++++++++--------------------------
1 file changed, 17 insertions(+), 39 deletions(-)
diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c
index 9c9e4369c041..e4384ddece08 100644
--- a/drivers/edac/cpc925_edac.c
+++ b/drivers/edac/cpc925_edac.c
@@ -903,6 +903,13 @@ static int cpc925_mc_get_channels(void __iomem *vbase)
return dual;
}
+static void cpc925_edac_free(void *data)
+{
+ struct mem_ctl_info *mci = data;
+
+ edac_mc_free(mci);
+}
+
static int cpc925_probe(struct platform_device *pdev)
{
static int edac_mc_idx;
@@ -910,37 +917,14 @@ static int cpc925_probe(struct platform_device *pdev)
struct edac_mc_layer layers[2];
void __iomem *vbase;
struct cpc925_mc_pdata *pdata;
- struct resource *r;
int res = 0, nr_channels;
edac_dbg(0, "%s platform device found!\n", pdev->name);
- if (!devres_open_group(&pdev->dev, cpc925_probe, GFP_KERNEL)) {
- res = -ENOMEM;
- goto out;
- }
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!r) {
+ vbase = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(vbase)) {
cpc925_printk(KERN_ERR, "Unable to get resource\n");
- res = -ENOENT;
- goto err1;
- }
-
- if (!devm_request_mem_region(&pdev->dev,
- r->start,
- resource_size(r),
- pdev->name)) {
- cpc925_printk(KERN_ERR, "Unable to request mem region\n");
- res = -EBUSY;
- goto err1;
- }
-
- vbase = devm_ioremap(&pdev->dev, r->start, resource_size(r));
- if (!vbase) {
- cpc925_printk(KERN_ERR, "Unable to ioremap device\n");
- res = -ENOMEM;
- goto err2;
+ return PTR_ERR(vbase);
}
nr_channels = cpc925_mc_get_channels(vbase) + 1;
@@ -955,10 +939,12 @@ static int cpc925_probe(struct platform_device *pdev)
sizeof(struct cpc925_mc_pdata));
if (!mci) {
cpc925_printk(KERN_ERR, "No memory for mem_ctl_info\n");
- res = -ENOMEM;
- goto err2;
+ return -ENOMEM;
}
+ if (devm_add_action_or_reset(&pdev->dev, cpc925_edac_free, mci))
+ return -ENOMEM;
+
pdata = mci->pvt_info;
pdata->vbase = vbase;
pdata->edac_idx = edac_mc_idx++;
@@ -988,7 +974,7 @@ static int cpc925_probe(struct platform_device *pdev)
if (edac_mc_add_mc(mci) > 0) {
cpc925_mc_printk(mci, KERN_ERR, "Failed edac_mc_add_mc()\n");
- goto err3;
+ goto err;
}
cpc925_add_edac_devices(vbase);
@@ -996,17 +982,10 @@ static int cpc925_probe(struct platform_device *pdev)
/* get this far and it's successful */
edac_dbg(0, "success\n");
- res = 0;
- goto out;
+ return 0;
-err3:
+err:
cpc925_mc_exit(mci);
- edac_mc_free(mci);
-err2:
- devm_release_mem_region(&pdev->dev, r->start, resource_size(r));
-err1:
- devres_release_group(&pdev->dev, cpc925_probe);
-out:
return res;
}
@@ -1022,7 +1001,6 @@ static void cpc925_remove(struct platform_device *pdev)
cpc925_mc_exit(mci);
edac_mc_del_mc(&pdev->dev);
- edac_mc_free(mci);
}
static struct platform_driver cpc925_edac_driver = {
--
2.55.0
reply other threads:[~2026-07-19 21:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260719213532.695530-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=bp@alien8.de \
--cc=justinstitt@google.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox