Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ASoC: stm32: spdifrx: Fix resource handling and startup
@ 2026-12-01  9:43 phucduc.bui
  2026-12-01  9:43 ` [PATCH v2 1/2] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback phucduc.bui
  2026-12-01  9:43 ` [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream phucduc.bui
  0 siblings, 2 replies; 4+ messages in thread
From: phucduc.bui @ 2026-12-01  9:43 UTC (permalink / raw)
  To: Mark Brown, Olivier Moysan
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Arnaud Pouliquen,
	Maxime Coquelin, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, Alexandre Torgue, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

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/20261127092345.12383-1-phucduc.bui@gmail.com/
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(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback
  2026-12-01  9:43 [PATCH v2 0/2] ASoC: stm32: spdifrx: Fix resource handling and startup phucduc.bui
@ 2026-12-01  9:43 ` phucduc.bui
  2026-12-01  9:43 ` [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream phucduc.bui
  1 sibling, 0 replies; 4+ messages in thread
From: phucduc.bui @ 2026-12-01  9:43 UTC (permalink / raw)
  To: Mark Brown, Olivier Moysan
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Arnaud Pouliquen,
	Maxime Coquelin, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, Alexandre Torgue, bui duc phuc

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.

Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com>
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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream
  2026-12-01  9:43 [PATCH v2 0/2] ASoC: stm32: spdifrx: Fix resource handling and startup phucduc.bui
  2026-12-01  9:43 ` [PATCH v2 1/2] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback phucduc.bui
@ 2026-12-01  9:43 ` phucduc.bui
  2026-12-01  9:50   ` sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: phucduc.bui @ 2026-12-01  9:43 UTC (permalink / raw)
  To: Mark Brown, Olivier Moysan
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Arnaud Pouliquen,
	Maxime Coquelin, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, Alexandre Torgue, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

Enable the clock before assigning the substream to avoid leaving
a stale substream pointer if clock enabling fails.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/stm/stm32_spdifrx.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c
index 467c3c583a00..f594634c07c4 100644
--- a/sound/soc/stm/stm32_spdifrx.c
+++ b/sound/soc/stm/stm32_spdifrx.c
@@ -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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream
  2026-12-01  9:43 ` [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream phucduc.bui
@ 2026-12-01  9:50   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-01  9:50 UTC (permalink / raw)
  To: phucduc.bui; +Cc: linux-sound

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 <phucduc.bui@gmail.com>

> 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 <phucduc.bui@gmail.com>

[Severity: Low]
This fixes a bug present since the driver was added.  Should it include:

  Fixes: 03e4d5d56fa5 ("ASoC: stm32: Add SPDIFRX support")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201094343.26675-1-phucduc.bui@gmail.com?part=2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-01  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  9:43 [PATCH v2 0/2] ASoC: stm32: spdifrx: Fix resource handling and startup phucduc.bui
2026-12-01  9:43 ` [PATCH v2 1/2] ASoC: stm32: spdifrx: Use devm helpers and drop remove callback phucduc.bui
2026-12-01  9:43 ` [PATCH v2 2/2] ASoC: stm32: spdifrx: Enable clock before setting substream phucduc.bui
2026-12-01  9:50   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox