Re: [PATCH v2 2/2] dmaengine: bcm2835-dma: Convert to managed resources
From: Frank Li
Date: Tue Nov 24 2026 - 15:03:03 EST
On Thu, Nov 19, 2026 at 09:38:30PM +0100, Tomasz Unger wrote:
> bcm2835_dma_probe() registers the OF DMA controller before the DMA
> device. A client probing on another CPU can therefore reach
> bcm2835_dma_xlate() and dma_get_any_slave_channel() while the device
> is not registered yet, and if dma_async_device_register() then fails,
> the driver data is freed while that client may still hold a channel.
>
> Convert the driver to managed resources and register the OF controller
> last, after the DMA device. As devres releases resources in reverse
> order, the OF controller is now also freed first, before the DMA
> device is unregistered, both on remove and on the probe error path.
> This makes bcm2835_dma_remove() and the error labels unnecessary.
>
> Channel teardown and the zero page unmap become two separate devres
> actions. The channels are devm-allocated after the zero page is
> mapped, so a single action registered at that point would run after
> the channel memory has already been freed and walk freed list entries.
> The tasklet teardown is therefore registered after the channels are
> initialized.
Can you keep commit message simple? AI create commit message is redundant.
>
> The bug was found and the fix drafted with the help of an AI coding
> assistant (Claude).
>
> Suggested-by: Frank Li <Frank.Li@xxxxxxxxxx>
> Assisted-by: Claude:claude-opus-5-5
remove Assisted-by
> Signed-off-by: Tomasz Unger <tomasz.unger@xxxxxxxx>
> ---
> drivers/dma/bcm2835-dma.c | 56 +++++++++++++++++++++++------------------------
> 1 file changed, 27 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c
> index cf29d897450e..b2da706d2e16 100644
> --- a/drivers/dma/bcm2835-dma.c
> +++ b/drivers/dma/bcm2835-dma.c
> @@ -822,8 +822,9 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id,
> return 0;
> }
>
> -static void bcm2835_dma_free(struct bcm2835_dmadev *od)
> +static void bcm2835_dma_free(void *data)
> {
> + struct bcm2835_dmadev *od = data;
> struct bcm2835_chan *c, *next;
>
> list_for_each_entry_safe(c, next, &od->ddev.channels,
> @@ -831,6 +832,11 @@ static void bcm2835_dma_free(struct bcm2835_dmadev *od)
> list_del(&c->vc.chan.device_node);
> tasklet_kill(&c->vc.task);
> }
> +}
> +
> +static void bcm2835_dma_unmap_zero_page(void *data)
> +{
> + struct bcm2835_dmadev *od = data;
>
> dma_unmap_page_attrs(od->ddev.dev, od->zero_page, PAGE_SIZE,
> DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
> @@ -944,13 +950,17 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
> return -ENOMEM;
> }
>
> + rc = devm_add_action_or_reset(&pdev->dev, bcm2835_dma_unmap_zero_page,
> + od);
> + if (rc)
> + return rc;
> +
> /* Request DMA channel mask from device tree */
> if (of_property_read_u32(pdev->dev.of_node,
> "brcm,dma-channel-mask",
> &chans_available)) {
> dev_err(&pdev->dev, "Failed to get channel mask\n");
> - rc = -EINVAL;
> - goto err_no_dma;
> + return -EINVAL;
return dev_err_probe(), check below
Frank