Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
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/mpc85xx: manage controller info lifetime via devres
Date: Sun, 19 Jul 2026 13:15:58 -0700	[thread overview]
Message-ID: <20260719201558.310738-1-rosenp@gmail.com> (raw)

mpc85xx_pci_err_probe() and mpc85xx_l2_err_probe() request their shared
interrupt with devm_request_irq(), passing the allocated control info
(pci / edac_dev) as the handler context. At removal the driver frees
that control info explicitly via edac_pci_free_ctl_info() /
edac_device_free_ctl_info() before devres tears down the IRQ, leaving a
use-after-free window in which a peer device on the shared line can fire
and the ISR dereferences the freed structure.

Register a free callback via devm_add_action_or_reset() immediately after
allocation so the control info is owned by devres and freed only after
the devm IRQ is released (devres runs actions in LIFO order). Drop the
explicit frees from both the probe error paths and the remove callbacks,
and remove the now-redundant devres group open/release/remove calls.

Built for powerpc (CONFIG_EDAC_MPC85XX) with LLVM=1;
drivers/edac/mpc85xx_edac.o compiles cleanly and passes checkpatch
--strict.

Assisted-by: opencode:hy3-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/edac/mpc85xx_edac.c | 42 +++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 7bb13f85ce57..13c88600f7b5 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -141,6 +141,13 @@ static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void mpc85xx_pci_edac_free(void *data)
+{
+	struct edac_pci_ctl_info *pci = data;
+
+	edac_pci_free_ctl_info(pci);
+}
+
 static int mpc85xx_pci_err_probe(struct platform_device *op)
 {
 	struct edac_pci_ctl_info *pci;
@@ -150,13 +157,14 @@ static int mpc85xx_pci_err_probe(struct platform_device *op)
 	struct resource r;
 	int res = 0;
 
-	if (!devres_open_group(&op->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
-		return -ENOMEM;
-
 	pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
 	if (!pci)
 		return -ENOMEM;
 
+	res = devm_add_action_or_reset(&op->dev, mpc85xx_pci_edac_free, pci);
+	if (res)
+		return res;
+
 	/* make sure error reporting method is sane */
 	switch (edac_op_state) {
 	case EDAC_OPSTATE_POLL:
@@ -285,7 +293,6 @@ static int mpc85xx_pci_err_probe(struct platform_device *op)
 			 | PEX_ERR_ICCAD_DISR_BIT);
 	}
 
-	devres_remove_group(&op->dev, mpc85xx_pci_err_probe);
 	edac_dbg(3, "success\n");
 	pr_info(EDAC_MOD_STR " PCI err registered\n");
 
@@ -294,8 +301,6 @@ static int mpc85xx_pci_err_probe(struct platform_device *op)
 err2:
 	edac_pci_del_device(&op->dev);
 err:
-	edac_pci_free_ctl_info(pci);
-	devres_release_group(&op->dev, mpc85xx_pci_err_probe);
 	return res;
 }
 
@@ -310,7 +315,6 @@ static void mpc85xx_pci_err_remove(struct platform_device *op)
 	out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, orig_pci_err_en);
 
 	edac_pci_del_device(&op->dev);
-	edac_pci_free_ctl_info(pci);
 }
 
 static const struct platform_device_id mpc85xx_pci_err_match[] = {
@@ -484,6 +488,13 @@ static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void mpc85xx_l2_edac_free(void *data)
+{
+	struct edac_device_ctl_info *edac_dev = data;
+
+	edac_device_free_ctl_info(edac_dev);
+}
+
 static int mpc85xx_l2_err_probe(struct platform_device *op)
 {
 	struct edac_device_ctl_info *edac_dev;
@@ -491,16 +502,16 @@ static int mpc85xx_l2_err_probe(struct platform_device *op)
 	struct resource r;
 	int res;
 
-	if (!devres_open_group(&op->dev, mpc85xx_l2_err_probe, GFP_KERNEL))
-		return -ENOMEM;
-
 	edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
 					      "cpu", 1, "L", 1, 2,
 					      edac_dev_idx);
-	if (!edac_dev) {
-		devres_release_group(&op->dev, mpc85xx_l2_err_probe);
+	if (!edac_dev)
 		return -ENOMEM;
-	}
+
+	res = devm_add_action_or_reset(&op->dev, mpc85xx_l2_edac_free,
+				       edac_dev);
+	if (res)
+		return res;
 
 	pdata = edac_dev->pvt_info;
 	pdata->name = "mpc85xx_l2_err";
@@ -573,8 +584,6 @@ static int mpc85xx_l2_err_probe(struct platform_device *op)
 		out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, L2_EIE_MASK);
 	}
 
-	devres_remove_group(&op->dev, mpc85xx_l2_err_probe);
-
 	edac_dbg(3, "success\n");
 	pr_info(EDAC_MOD_STR " L2 err registered\n");
 
@@ -583,8 +592,6 @@ static int mpc85xx_l2_err_probe(struct platform_device *op)
 err2:
 	edac_device_del_device(&op->dev);
 err:
-	devres_release_group(&op->dev, mpc85xx_l2_err_probe);
-	edac_device_free_ctl_info(edac_dev);
 	return res;
 }
 
@@ -602,7 +609,6 @@ static void mpc85xx_l2_err_remove(struct platform_device *op)
 
 	out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, orig_l2_err_disable);
 	edac_device_del_device(&op->dev);
-	edac_device_free_ctl_info(edac_dev);
 }
 
 static const struct of_device_id mpc85xx_l2_err_of_match[] = {
-- 
2.55.0


                 reply	other threads:[~2026-07-19 20:16 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=20260719201558.310738-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