Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: tomasz.unger@yahoo.pl
Cc: Vinod Koul <vkoul@kernel.org>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Frank Li <Frank.Li@kernel.org>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>,
	dmaengine@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] dmaengine: bcm2835-dma: Convert to managed resources
Date: Tue, 1 Dec 2026 14:26:16 -0600	[thread overview]
Message-ID: <aw8taNaJH-ECLWfe@SMW015318> (raw)
In-Reply-To: <20261129-bcm2835-dma-of-dma-free-v3-2-cdb1c9a32b55@yahoo.pl>

On Sun, Nov 29, 2026 at 09:01:45PM +0100, tomasz.unger@yahoo.pl wrote:
> From: Tomasz Unger <tomasz.unger@yahoo.pl>
>
> bcm2835_dma_probe() registers the OF DMA controller before the DMA
> device, so a client can request a channel from a device that is not
> registered yet.
>
> Convert the driver to managed resources and register the OF controller
> last, so that devres frees it first. This removes bcm2835_dma_remove()
> and the error labels. Use dev_err_probe() for the error messages in
> probe.
>
> Suggested-by: Frank Li <Frank.Li@kernel.org>
> Signed-off-by: Tomasz Unger <tomasz.unger@yahoo.pl>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/dma/bcm2835-dma.c | 80 +++++++++++++++++++++--------------------------
>  1 file changed, 36 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c
> index cf29d897450e..b3870c444a14 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);
> @@ -894,10 +900,9 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
>  		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
>
>  	rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> -	if (rc) {
> -		dev_err(&pdev->dev, "Unable to set DMA mask\n");
> -		return rc;
> -	}
> +	if (rc)
> +		return dev_err_probe(&pdev->dev, rc,
> +				     "Unable to set DMA mask\n");
>
>  	od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
>  	if (!od)
> @@ -939,19 +944,21 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
>  	od->zero_page = dma_map_page_attrs(od->ddev.dev, ZERO_PAGE(0), 0,
>  					   PAGE_SIZE, DMA_TO_DEVICE,
>  					   DMA_ATTR_SKIP_CPU_SYNC);
> -	if (dma_mapping_error(od->ddev.dev, od->zero_page)) {
> -		dev_err(&pdev->dev, "Failed to map zero page\n");
> -		return -ENOMEM;
> -	}
> +	if (dma_mapping_error(od->ddev.dev, od->zero_page))
> +		return dev_err_probe(&pdev->dev, -ENOMEM,
> +				     "Failed to map zero page\n");
> +
> +	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;
> -	}
> +			&chans_available))
> +		return dev_err_probe(&pdev->dev, -EINVAL,
> +				     "Failed to get channel mask\n");
>
>  	/* get irqs for each channel that we support */
>  	for (i = 0; i <= BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED; i++) {
> @@ -994,49 +1001,34 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
>  		/* initialize the channel */
>  		rc = bcm2835_dma_chan_init(od, i, irq[i], irq_flags);
>  		if (rc)
> -			goto err_no_dma;
> +			return rc;
>  	}
>
>  	dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i);
>
> -	/* Device-tree DMA controller registration */
> -	rc = of_dma_controller_register(pdev->dev.of_node,
> -			bcm2835_dma_xlate, od);
> -	if (rc) {
> -		dev_err(&pdev->dev, "Failed to register DMA controller\n");
> -		goto err_no_dma;
> -	}
> +	rc = devm_add_action_or_reset(&pdev->dev, bcm2835_dma_free, od);
> +	if (rc)
> +		return rc;
>
> -	rc = dma_async_device_register(&od->ddev);
> -	if (rc) {
> -		dev_err(&pdev->dev,
> -			"Failed to register slave DMA engine device: %d\n", rc);
> -		goto err_of_dma;
> -	}
> +	rc = dmaenginem_async_device_register(&od->ddev);
> +	if (rc)
> +		return dev_err_probe(&pdev->dev, rc,
> +				     "Failed to register slave DMA engine device\n");
> +
> +	/* Device-tree DMA controller registration */
> +	rc = devm_of_dma_controller_register(&pdev->dev, pdev->dev.of_node,
> +					     bcm2835_dma_xlate, od);
> +	if (rc)
> +		return dev_err_probe(&pdev->dev, rc,
> +				     "Failed to register DMA controller\n");
>
>  	dev_dbg(&pdev->dev, "Load BCM2835 DMA engine driver\n");
>
>  	return 0;
> -
> -err_of_dma:
> -	of_dma_controller_free(pdev->dev.of_node);
> -err_no_dma:
> -	bcm2835_dma_free(od);
> -	return rc;
> -}
> -
> -static void bcm2835_dma_remove(struct platform_device *pdev)
> -{
> -	struct bcm2835_dmadev *od = platform_get_drvdata(pdev);
> -
> -	of_dma_controller_free(pdev->dev.of_node);
> -	dma_async_device_unregister(&od->ddev);
> -	bcm2835_dma_free(od);
>  }
>
>  static struct platform_driver bcm2835_dma_driver = {
>  	.probe	= bcm2835_dma_probe,
> -	.remove = bcm2835_dma_remove,
>  	.driver = {
>  		.name = "bcm2835-dma",
>  		.of_match_table = of_match_ptr(bcm2835_dma_of_match),
>
> --
> 2.56.1
>


      reply	other threads:[~2026-12-01 20:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261129-bcm2835-dma-of-dma-free-v3-0-cdb1c9a32b55.ref@yahoo.pl>
2026-11-29 20:01 ` [PATCH v3 0/2] dmaengine: bcm2835-dma: Fix OF DMA controller lifetime tomasz.unger
2026-11-29 20:01   ` [PATCH v3 1/2] dmaengine: bcm2835-dma: Add missing of_dma_controller_free() tomasz.unger
2026-12-01 20:22     ` Frank Li
2026-11-29 20:01   ` [PATCH v3 2/2] dmaengine: bcm2835-dma: Convert to managed resources tomasz.unger
2026-12-01 20:26     ` Frank Li [this message]

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=aw8taNaJH-ECLWfe@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=tomasz.unger@yahoo.pl \
    --cc=vkoul@kernel.org \
    /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