Skip to contentSkip to conversation

ASoC: atmel-i2s: fix clock error handling

PATCH In review [email protected] 2 participants 9 messages Oct 2 – Nov 11

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ASoC: atmel-i2s: fix clock error handling

From: bui duc phuc <[email protected]>

Hi all,

This series fixes clock error handling in the Atmel I2S driver by propagating errors, using optional clock APIs, and simplifying probe error reporting.

Found by manual code inspection.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (5):
ASoC: atmel-i2s: fix MCK generator error handling
ASoC: atmel-i2s: use optional API for muxclk
ASoC: atmel-i2s: use optional API for gclk
ASoC: atmel-i2s: use dev_err_probe() for pclk errors
ASoC: atmel-i2s: remove redundant error message

 sound/soc/atmel/atmel-i2s.c | 54 +++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 29 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 ASoC: atmel-i2s: fix MCK generator error handling

From: bui duc phuc <[email protected]>

Disable the gclk and reset the MCK configuration when an error occurs while enabling the MCK generator.

This prevents the gclk from remaining enabled after a failed clock configuration.

Fixes 73ad0df57290 ("ASoC: atmel-i2s: Remove unnecessary audio PLL clock (aclk)")
---
 sound/soc/atmel/atmel-i2s.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
sound/soc/atmel/atmel-i2s.c +13 -3
index d9ad262ec44d..f28808d980ce 100644
@@ -466,11 +466,21 @@ static int atmel_i2s_switch_mck_generator(struct atmel_i2s_dev *dev,
 	mr |= ATMEL_I2SC_MR_IMCKMODE_I2SMCK;
 	ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr);
 	if (ret)
-		return ret;
+		goto err_disable_gclk;
 
 	/* Finally enable the I2S Master Clock generator. */
-	return regmap_write(dev->regmap, ATMEL_I2SC_CR,
-			    ATMEL_I2SC_CR_CKEN);
+	ret = regmap_write(dev->regmap, ATMEL_I2SC_CR, ATMEL_I2SC_CR_CKEN);
+	if (ret)
+		goto err_reset_mr;
+
+	return 0;
+
+err_reset_mr:
+	regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, 0);
+err_disable_gclk:
+	clk_disable_unprepare(dev->gclk);
+
+	return ret;
 }
 
 static int atmel_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 ASoC: atmel-i2s: use optional API for muxclk

In reply to [email protected]

From: bui duc phuc <[email protected]>

The muxclk is an optional clock according to the device tree binding.

Use devm_clk_get_optional() to handle the optional muxclk instead of handling the missing clock explicitly.

When muxclk is not available, devm_clk_get_optional() returns NULL. clk_set_parent() returns 0 when passed NULL, preserving the existing behavior.

Unlike the existing code, errors other than -EPROBE_DEFER are now returned instead of being silently ignored.

Fixes b543e467d1a9 ("ASoC: atmel-i2s: add driver for the new Atmel I2S controller")
---
 sound/soc/atmel/atmel-i2s.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
sound/soc/atmel/atmel-i2s.c +5 -11
index f28808d980ce..c52d048449f8 100644
@@ -589,21 +589,15 @@ static int atmel_i2s_sama5d2_mck_init(struct atmel_i2s_dev *dev,
 				      struct device_node *np)
 {
 	struct clk *muxclk;
-	int err;
 
 	if (!dev->gclk)
 		return 0;
 
-	/* muxclk is optional, so we return error for probe defer only */
-	muxclk = devm_clk_get(dev->dev, "muxclk");
-	if (IS_ERR(muxclk)) {
-		err = PTR_ERR(muxclk);
-		if (err == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		dev_dbg(dev->dev,
-			"failed to get the I2S clock control: %d\n", err);
-		return 0;
-	}
+	/* muxclk is optional */
+	muxclk = devm_clk_get_optional(dev->dev, "muxclk");
+	if (IS_ERR(muxclk))
+		return dev_err_probe(dev->dev, PTR_ERR(muxclk),
+				     "failed to get the I2S clock control\n");
 
 	return clk_set_parent(muxclk, dev->gclk);
 }
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 ASoC: atmel-i2s: use optional API for gclk

In reply to [email protected]

From: bui duc phuc <[email protected]>

The gclk is an optional clock according to the device tree binding.

Use devm_clk_get_optional() to handle the optional gclk directly.

Unlike the existing code, errors other than -EPROBE_DEFER are now returned instead of being silently ignored.

Fixes 73ad0df57290 ("ASoC: atmel-i2s: Remove unnecessary audio PLL clock (aclk)")
---
 sound/soc/atmel/atmel-i2s.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
sound/soc/atmel/atmel-i2s.c +4 -7
index c52d048449f8..6ca230f8adc8 100644
@@ -670,13 +670,10 @@ static int atmel_i2s_probe(struct platform_device *pdev)
 	}
 
 	/* Get audio clock to generate the I2S Master Clock (I2S_MCK) */
-	dev->gclk = devm_clk_get(&pdev->dev, "gclk");
-	if (IS_ERR(dev->gclk)) {
-		if (PTR_ERR(dev->gclk) == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		/* Master Mode not supported */
-		dev->gclk = NULL;
-	}
+	dev->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
+	if (IS_ERR(dev->gclk))
+		return PTR_ERR(dev->gclk);
+
 	dev->dev = &pdev->dev;
 	dev->regmap = regmap;
 	platform_set_drvdata(pdev, dev);
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 ASoC: atmel-i2s: use dev_err_probe() for pclk errors

In reply to [email protected]

From: bui duc phuc <[email protected]>

Use dev_err_probe() when obtaining clocks to avoid redundant error messages, particularly for probe deferral.

---
 sound/soc/atmel/atmel-i2s.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/soc/atmel/atmel-i2s.c +3 -6
index 6ca230f8adc8..9b651eb4f0a4 100644
@@ -662,12 +662,9 @@ static int atmel_i2s_probe(struct platform_device *pdev)
 
 	/* Get the peripheral clock. */
 	dev->pclk = devm_clk_get(&pdev->dev, "pclk");
-	if (IS_ERR(dev->pclk)) {
-		err = PTR_ERR(dev->pclk);
-		dev_err(&pdev->dev,
-			"failed to get the peripheral clock: %d\n", err);
-		return err;
-	}
+	if (IS_ERR(dev->pclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(dev->pclk),
+				     "failed to get the peripheral clock\n");
 
 	/* Get audio clock to generate the I2S Master Clock (I2S_MCK) */
 	dev->gclk = devm_clk_get_optional(&pdev->dev, "gclk");
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/5 ASoC: atmel-i2s: remove redundant error message

In reply to [email protected]

From: bui duc phuc <[email protected]>

The errors handled here are already reported by the called functions, either directly or deeper in the call chain. Therefore, the additional dev_err() call is redundant and can be removed.

---
 sound/soc/atmel/atmel-i2s.c | 2 --
 1 file changed, 2 deletions(-)
sound/soc/atmel/atmel-i2s.c +0 -2
index 9b651eb4f0a4..e1d8af056234 100644
@@ -699,7 +699,6 @@ static int atmel_i2s_probe(struct platform_device *pdev)
 					      &atmel_i2s_component,
 					      &atmel_i2s_dai, 1);
 	if (err) {
-		dev_err(&pdev->dev, "failed to register DAI: %d\n", err);
 		clk_disable_unprepare(dev->pclk);
 		return err;
 	}
@@ -714,7 +713,6 @@ static int atmel_i2s_probe(struct platform_device *pdev)
 		pcm_flags |= SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX;
 	err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, pcm_flags);
 	if (err) {
-		dev_err(&pdev->dev, "failed to register PCM: %d\n", err);
 		clk_disable_unprepare(dev->pclk);
 		return err;
 	}
Signature · 1 line
2.43.0
maintainer
#6 lore raw
In reply to [email protected]
Quoted 11 lines · On Fri, 02 Oct 2026 11:38:51 +0700, [email protected] wrote:

ASoC: atmel-i2s: fix clock error handling

From: bui duc phuc <[email protected]>

Hi all,

This series fixes clock error handling in the Atmel I2S driver by propagating errors, using optional clock APIs, and simplifying probe error reporting.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/5] ASoC: atmel-i2s: fix MCK generator error handling

      https://git.kernel.org/broonie/misc/c/2e2da92de9bf
[2/5] ASoC: atmel-i2s: use optional API for muxclk
      https://git.kernel.org/broonie/misc/c/be952abd69c1
[3/5] ASoC: atmel-i2s: use optional API for gclk
      https://git.kernel.org/broonie/misc/c/b431a055fb76
[4/5] ASoC: atmel-i2s: use dev_err_probe() for pclk errors
      https://git.kernel.org/broonie/misc/c/5421a0a39d43
[5/5] ASoC: atmel-i2s: remove redundant error message
      https://git.kernel.org/broonie/misc/c/c501f9873aca

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

maintainer
#7 lore raw
In reply to [email protected]
Quoted 7 lines · On Fri, Oct 02, 2026 at 11:38:51AM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

Hi all,

This series fixes clock error handling in the Atmel I2S driver by propagating errors, using optional clock APIs, and simplifying probe error reporting.

This doesn't apply against current code, please check and resend.

#8 lore raw

Hi Mark,

Quoted 2 lines

This doesn't apply against current code, please check and resend.

I believe this series has already been applied to the for-7.4 branch. I've also taken another look at the driver and plan to submit a few more patches for it.

Best regards,
Phuc