ASoC: stm32: spdifrx: Fix resource handling and startup
Subsystems (4)
v2 cover ASoC: stm32: spdifrx: Fix resource handling and startup
From: bui duc phuc <[email protected]>
Hi all,
This series improves resource management and error handling in the STM32 SPDIFRX driver.
It also ensures the clock is enabled before setting the substream pointer.
Compile-tested only.
Link v1 :
https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Drop "ASoC: stm32: spdifrx: Fix refcount on sync failure" from the series.
- Add Olivier's Reviewed-by tag.
Best regards,
Phuc
bui duc phuc (2):
ASoC: stm32: spdifrx: Use devm helpers and drop remove callback
ASoC: stm32: spdifrx: Enable clock before setting substream
sound/soc/stm/stm32_spdifrx.c | 79 ++++++++++------------------------- 1 file changed, 23 insertions(+), 56 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 ASoC: stm32: spdifrx: Use devm helpers and drop remove callback
From: bui duc phuc <[email protected]>
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.
--- sound/soc/stm/stm32_spdifrx.c | 67 +++++++++-------------------------- 1 file changed, 16 insertions(+), 51 deletions(-)
sound/soc/stm/stm32_spdifrx.c +16 -51
@@ -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);
Signature · 1 line
2.43.0
PATCH v2 2/2 ASoC: stm32: spdifrx: Enable clock before setting substream
In reply to [email protected]From: bui duc phuc <[email protected]>
Enable the clock before assigning the substream to avoid leaving a stale substream pointer if clock enabling fails.
--- sound/soc/stm/stm32_spdifrx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
sound/soc/stm/stm32_spdifrx.c +7 -5
@@ -747,14 +747,16 @@ static int stm32_spdifrx_startup(struct snd_pcm_substream *substream,struct stm32_spdifrx_data *spdifrx =snd_soc_dai_get_drvdata (cpu_dai);int ret; + ret =clk_prepare_enable (spdifrx->kclk); +if (ret) { +dev_err (&spdifrx->pdev->dev,"Enable kclk failed: %d\n" , ret); +return ret; + } +scoped_guard (spinlock_irqsave, &spdifrx->irq_lock) spdifrx->substream = substream; - ret =clk_prepare_enable (spdifrx->kclk); -if (ret) -dev_err (&spdifrx->pdev->dev,"Enable kclk failed: %d\n" , ret); - -return ret; +return 0 ; } static int stm32_spdifrx_hw_params(struct snd_pcm_substream *substream,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ASoC: stm32: spdifrx: missing Fixes trailer on bug-fix commit --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ASoC: stm32: spdifrx: missing Fixes trailer on bug-fix commit --
commit bfd9b8a85edd8cb69232031c9f34500e1b4034f4
Author: bui duc phuc <[email protected]>
Quoted 6 lines
ASoC: stm32: spdifrx: Enable clock before setting substream
Enable the clock before assigning the substream to avoid leaving a stale substream pointer if clock enabling fails.
Signed-off-by bui duc phuc <[email protected]>
[Severity: Low]
This fixes a bug present since the driver was added. Should it include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2