Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Olivier MOYSAN <olivier.moysan@foss.st.com>
To: <phucduc.bui@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	<linux-sound@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>
Subject: Re: [PATCH 1/3] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback
Date: Tue, 1 Dec 2026 09:52:25 +0100	[thread overview]
Message-ID: <ea11a98e-8dd3-4fce-bd29-b5cc387f78a7@foss.st.com> (raw)
In-Reply-To: <20261127092345.12383-2-phucduc.bui@gmail.com>

Hi,

On 11/27/26 10:23, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
> 
> Use devm helpers to manage the DMA channel, DMA buffer, runtime PM,
> PCM and component registration.
> 
> This allows removing the remove callback and simplifies error
> handling in the probe function.
> 
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
>   sound/soc/stm/stm32_spdifrx.c | 67 +++++++++--------------------------
>   1 file changed, 16 insertions(+), 51 deletions(-)
> 
> diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c
> index f6f7d4aaa94d..467c3c583a00 100644
> --- a/sound/soc/stm/stm32_spdifrx.c
> +++ b/sound/soc/stm/stm32_spdifrx.c
> @@ -396,24 +396,16 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev,
>   {
>   	int ret;
>   
> -	spdifrx->ctrl_chan = dma_request_chan(dev, "rx-ctrl");
> +	spdifrx->ctrl_chan = devm_dma_request_chan(dev, "rx-ctrl");
>   	if (IS_ERR(spdifrx->ctrl_chan))
>   		return dev_err_probe(dev, PTR_ERR(spdifrx->ctrl_chan),
>   				     "dma_request_chan error\n");
>   
> -	spdifrx->dmab = devm_kzalloc_obj(dev, struct snd_dma_buffer);
> +	spdifrx->dmab = snd_devm_alloc_pages(dev, SNDRV_DMA_TYPE_DEV_IRAM,
> +					     SPDIFRX_CSR_BUF_LENGTH);
>   	if (!spdifrx->dmab)
>   		return -ENOMEM;
>   
> -	spdifrx->dmab->dev.type = SNDRV_DMA_TYPE_DEV_IRAM;
> -	spdifrx->dmab->dev.dev = dev;
> -	ret = snd_dma_alloc_pages(spdifrx->dmab->dev.type, dev,
> -				  SPDIFRX_CSR_BUF_LENGTH, spdifrx->dmab);
> -	if (ret < 0) {
> -		dev_err(dev, "snd_dma_alloc_pages returned error %d\n", ret);
> -		return ret;
> -	}
> -
>   	spdifrx->slave_config.direction = DMA_DEV_TO_MEM;
>   	spdifrx->slave_config.src_addr = (dma_addr_t)(spdifrx->phys_addr +
>   					 STM32_SPDIFRX_CSR);
> @@ -919,26 +911,10 @@ static int stm32_spdifrx_parse_of(struct platform_device *pdev,
>   	return 0;
>   }
>   
> -static void stm32_spdifrx_remove(struct platform_device *pdev)
> -{
> -	struct stm32_spdifrx_data *spdifrx = platform_get_drvdata(pdev);
> -
> -	if (!IS_ERR(spdifrx->ctrl_chan))
> -		dma_release_channel(spdifrx->ctrl_chan);
> -
> -	if (spdifrx->dmab)
> -		snd_dma_free_pages(spdifrx->dmab);
> -
> -	snd_dmaengine_pcm_unregister(&pdev->dev);
> -	snd_soc_unregister_component(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
> -}
> -
>   static int stm32_spdifrx_probe(struct platform_device *pdev)
>   {
>   	struct stm32_spdifrx_data *spdifrx;
>   	struct reset_control *rst;
> -	const struct snd_dmaengine_pcm_config *pcm_config = NULL;
>   	u32 ver, idr;
>   	int ret;
>   
> @@ -978,46 +954,36 @@ static int stm32_spdifrx_probe(struct platform_device *pdev)
>   	udelay(2);
>   	reset_control_deassert(rst);
>   
> -	pcm_config = &stm32_spdifrx_pcm_config;
> -	ret = snd_dmaengine_pcm_register(&pdev->dev, pcm_config, 0);
> -	if (ret)
> -		return ret;
> -
> -	ret = snd_soc_register_component(&pdev->dev,
> -					 &stm32_spdifrx_component,
> -					 stm32_spdifrx_dai,
> -					 ARRAY_SIZE(stm32_spdifrx_dai));
> -	if (ret) {
> -		snd_dmaengine_pcm_unregister(&pdev->dev);
> -		return ret;
> -	}
> -
>   	ret = stm32_spdifrx_dma_ctrl_register(&pdev->dev, spdifrx);
>   	if (ret)
> -		goto error;
> +		return ret;
>   
>   	ret = regmap_read(spdifrx->regmap, STM32_SPDIFRX_IDR, &idr);
>   	if (ret)
> -		goto error;
> +		return ret;
>   
>   	if (idr == SPDIFRX_IPIDR_NUMBER) {
>   		ret = regmap_read(spdifrx->regmap, STM32_SPDIFRX_VERR, &ver);
>   		if (ret)
> -			goto error;
> +			return ret;
>   
>   		dev_dbg(&pdev->dev, "SPDIFRX version: %lu.%lu registered\n",
>   			FIELD_GET(SPDIFRX_VERR_MAJ_MASK, ver),
>   			FIELD_GET(SPDIFRX_VERR_MIN_MASK, ver));
>   	}
>   
> -	pm_runtime_enable(&pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
> +	if (ret)
> +		return ret;
>   
> -	return ret;
> +	ret = devm_snd_dmaengine_pcm_register(&pdev->dev, &stm32_spdifrx_pcm_config, 0);
> +	if (ret)
> +		return ret;
>   
> -error:
> -	stm32_spdifrx_remove(pdev);
> -
> -	return ret;
> +	return devm_snd_soc_register_component(&pdev->dev,
> +					       &stm32_spdifrx_component,
> +					       stm32_spdifrx_dai,
> +					       ARRAY_SIZE(stm32_spdifrx_dai));
>   }
>   
>   MODULE_DEVICE_TABLE(of, stm32_spdifrx_ids);
> @@ -1052,7 +1018,6 @@ static struct platform_driver stm32_spdifrx_driver = {
>   		.pm = pm_ptr(&stm32_spdifrx_pm_ops),
>   	},
>   	.probe = stm32_spdifrx_probe,
> -	.remove = stm32_spdifrx_remove,
>   };
>   
>   module_platform_driver(stm32_spdifrx_driver);

Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com>

Best regards
Olivier



  reply	other threads:[~2026-12-01  8:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  9:23 [PATCH 0/3] ASoC: stm32: spdifrx: Fix resource handling and startup phucduc.bui
2026-11-27  9:23 ` [PATCH 1/3] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback phucduc.bui
2026-12-01  8:52   ` Olivier MOYSAN [this message]
2026-11-27  9:23 ` [PATCH 2/3] ASoC: stm32: spdifrx: Fix refcount on sync failure phucduc.bui
2026-11-30 17:18   ` Olivier MOYSAN
2026-12-01  8:35     ` Bui Duc Phuc
2026-11-27  9:23 ` [PATCH 3/3] ASoC: stm32: spdifrx: Enable clock before setting substream phucduc.bui

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=ea11a98e-8dd3-4fce-bd29-b5cc387f78a7@foss.st.com \
    --to=olivier.moysan@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=arnaud.pouliquen@foss.st.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=perex@perex.cz \
    --cc=phucduc.bui@gmail.com \
    --cc=tiwai@suse.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