[PATCH 05/10] mailbox: bcm-pdc: Unregister mailbox controller before destroying DMA pools

From: Lee Jones

Date: Thu Dec 03 2026 - 03:28:33 EST


pdc_mb_init() registers the mailbox controller with
devm_mbox_controller_register(), whereas pdc_remove() manually destroys
pdcs->rx_buf_pool and pdcs->ring_pool. Because devres teardown runs
after pdc_remove() returns, mbox_controller_unregister() invokes
pdc_shutdown() and pdc_ring_free() on already-destroyed DMA pools, and
concurrent sends in pdc_rx_list_init() can allocate from the destroyed
rx_buf_pool.

Register the mailbox controller with mbox_controller_register() and
explicitly call mbox_controller_unregister() in pdc_remove() after
disabling the hardware and before destroying the DMA pools.

Fixes: 6267ee6afae0 ("mailbox: bcm-pdc: Use device-managed registration API")
Closes: https://sashiko.dev/#/bug/linux-8e397ec0-b0b5-4a26-b226-828f8b4bad77
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

Cc: Jassi Brar <jassisinghbrar@xxxxxxxxx>
Cc: Pan Chuang <panchuang@xxxxxxxx>
Cc: Rob Rice <rob.rice@xxxxxxxxxxxx>
Cc: Thierry Reding <treding@xxxxxxxxxx>

drivers/mailbox/bcm-pdc-mailbox.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mailbox/bcm-pdc-mailbox.c b/drivers/mailbox/bcm-pdc-mailbox.c
index 6fcc4002ad4f..159c2ab17a9d 100644
--- a/drivers/mailbox/bcm-pdc-mailbox.c
+++ b/drivers/mailbox/bcm-pdc-mailbox.c
@@ -1450,7 +1450,7 @@ static int pdc_mb_init(struct pdc_state *pdcs)
mbc->chans[chan_index].con_priv = pdcs;

/* Register mailbox controller */
- err = devm_mbox_controller_register(dev, mbc);
+ err = mbox_controller_register(mbc);
if (err) {
dev_crit(dev,
"Failed to register PDC mailbox controller. Error %d.",
@@ -1609,6 +1609,8 @@ static void pdc_remove(struct platform_device *pdev)

pdc_hw_disable(pdcs);

+ mbox_controller_unregister(&pdcs->mbc);
+
dma_pool_destroy(pdcs->rx_buf_pool);
dma_pool_destroy(pdcs->ring_pool);
}
--
2.56.1.911.g883d8bcb20-goog