[PATCH 1/3] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback

Olivier MOYSAN olivier.moysan at foss.st.com
Tue Dec 1 00:52:25 PST 2026


Hi,

On 11/27/26 10:23, phucduc.bui at gmail.com wrote:
> From: bui duc phuc <phucduc.bui at 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 at 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 at foss.st.com>

Best regards
Olivier




More information about the linux-arm-kernel mailing list