[PATCH 07/10] mailbox: sun6i-msgbox: Free IRQ before disabling clock on teardown

From
Lee Jones <lee@kernel.org>
Date
2026-12-03 08:28:29
Also in
linux-sunxi, lkml, stable
Reply to
Lee Jones, 2026-12-03
sun6i_msgbox_probe() requests the interrupt using devm_request_irq()
before initialising mbox->controller and mbox->lock, while
sun6i_msgbox_remove() manually calls mbox_controller_unregister() and
clk_disable_unprepare() before devres frees the IRQ.  An interrupt
arriving during probe failure or device removal can access unclocked
MMIO registers or freed controller data in sun6i_msgbox_irq().

Retrieve the IRQ via platform_get_irq() and register it with
request_irq() after initialising mbox->controller and mbox->lock, then
explicitly call free_irq() before disabling the clock in both the probe
error path and sun6i_msgbox_remove().

Fixes: 25831c44b0b7 ("mailbox: sun6i-msgbox: Add a new mailbox driver")
Closes: https://sashiko.dev/#/bug/linux-b10c9846-995f-40c3-a18c-97b9cb0d0611
Cc: <redacted>
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Chen-Yu Tsai <wens@kernel.org>
Cc: Jassi Brar <jassisinghbrar@gmail.com>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Cc: <redacted>
Cc: <redacted>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Samuel Holland <samuel@sholland.org>

 drivers/mailbox/sun6i-msgbox.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/mailbox/sun6i-msgbox.c b/drivers/mailbox/sun6i-msgbox.c
index 1cbc4d478beb..4c5669035420 100644
--- a/drivers/mailbox/sun6i-msgbox.c
+++ b/drivers/mailbox/sun6i-msgbox.c
@@ -12,7 +12,6 @@
 #include <linux/mailbox_controller.h>
 #include <linux/module.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
 #include <linux/spinlock.h>
@@ -48,6 +47,7 @@ struct sun6i_msgbox {
 	struct clk *clk;
 	spinlock_t lock;
 	void __iomem *regs;
+	int irq;
 };
 
 static bool sun6i_msgbox_last_tx_done(struct mbox_chan *chan);
@@ -255,11 +255,6 @@ static int sun6i_msgbox_probe(struct platform_device *pdev)
 	/* Disable all IRQs for this end of the msgbox. */
 	writel(0, mbox->regs + LOCAL_IRQ_EN_REG);
 
-	ret = devm_request_irq(dev, irq_of_parse_and_map(dev->of_node, 0),
-			       sun6i_msgbox_irq, 0, dev_name(dev), mbox);
-	if (ret)
-		goto err_disable_unprepare;
-
 	mbox->controller.dev           = dev;
 	mbox->controller.ops           = &sun6i_msgbox_chan_ops;
 	mbox->controller.chans         = chans;
@@ -271,14 +266,26 @@ static int sun6i_msgbox_probe(struct platform_device *pdev)
 	spin_lock_init(&mbox->lock);
 	platform_set_drvdata(pdev, mbox);
 
+	mbox->irq = platform_get_irq(pdev, 0);
+	if (mbox->irq < 0) {
+		ret = mbox->irq;
+		goto err_disable_unprepare;
+	}
+
+	ret = request_irq(mbox->irq, sun6i_msgbox_irq, 0, dev_name(dev), mbox);
+	if (ret)
+		goto err_disable_unprepare;
+
 	ret = mbox_controller_register(&mbox->controller);
 	if (ret) {
 		dev_err(dev, "Failed to register controller: %d\n", ret);
-		goto err_disable_unprepare;
+		goto err_free_irq;
 	}
 
 	return 0;
 
+err_free_irq:
+	free_irq(mbox->irq, mbox);
 err_disable_unprepare:
 	clk_disable_unprepare(mbox->clk);
 
@@ -290,6 +297,7 @@ static void sun6i_msgbox_remove(struct platform_device *pdev)
 	struct sun6i_msgbox *mbox = platform_get_drvdata(pdev);
 
 	mbox_controller_unregister(&mbox->controller);
+	free_irq(mbox->irq, mbox);
 	/* See the comment in sun6i_msgbox_probe about the reset line. */
 	clk_disable_unprepare(mbox->clk);
 }
-- 
2.56.1.911.g883d8bcb20-goog

Thread (5 messages) 5 messages, 2 authors, last reply 16h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help