Skip to contentSkip to conversation

ASoC: kirkwood: Improve clock and error handling

PATCH In review [email protected] 2 participants 7 messages Oct 26 – Nov 2

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

cover ASoC: kirkwood: Improve clock and error handling

From: bui duc phuc <[email protected]>

Hi all,

This series improves error handling and clock management in the Kirkwood I2S driver.

It propagates resource mapping and clock enable errors, removes redundant error logging, and ensures that clocks are cleaned up in the correct order on probe failures and device removal.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (5):
ASoC: kirkwood: kirkwood-i2s: Fix error handling for resource mapping
ASoC: kirkwood: kirkwood-i2s: Improve error handling in probe
ASoC: kirkwood: kirkwood-i2s: Check return value of
clk_prepare_enable()
ASoC: kirkwood: kirkwood-i2s: Disable extclk on internal clk error
ASoC: kirkwood: kirkwood-i2s: Disable clocks in reverse order in
remove()

 sound/soc/kirkwood/kirkwood-i2s.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 ASoC: kirkwood: kirkwood-i2s: Fix error handling for resource mapping

From: bui duc phuc <[email protected]>

Return the actual error code from devm_platform_ioremap_resource_byname() instead of always returning -ENOMEM when resource mapping fails.

This preserves the original error code, allowing callers to identify the actual cause of the failure.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +2 -2
index 739a819d8494..cf4327101b96 100644
@@ -59,11 +59,11 @@ static int armada_38x_i2s_init_quirk(struct platform_device *pdev,
 
 	priv->pll_config = devm_platform_ioremap_resource_byname(pdev, "pll_regs");
 	if (IS_ERR(priv->pll_config))
-		return -ENOMEM;
+		return PTR_ERR(priv->pll_config);
 
 	priv->soc_control = devm_platform_ioremap_resource_byname(pdev, "soc_ctrl");
 	if (IS_ERR(priv->soc_control))
-		return -ENOMEM;
+		return PTR_ERR(priv->soc_control);
 
 	/* Select one of exceptive modes: I2S or S/PDIF */
 	reg_val = readl(priv->soc_control);
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 ASoC: kirkwood: kirkwood-i2s: Improve error handling in probe

In reply to [email protected]

From: bui duc phuc <[email protected]>

Use dev_err_probe() to report clock acquisition errors.

Remove the redundant error message when snd_soc_register_component() fails. The errors handled here are already reported deeper in the call chain, so the additional dev_err() call is unnecessary.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +4 -7
index cf4327101b96..29641bd4cc60 100644
@@ -687,10 +687,9 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 	}
 
 	priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL);
-	if (IS_ERR(priv->clk)) {
-		dev_err(&pdev->dev, "no clock\n");
-		return PTR_ERR(priv->clk);
-	}
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk),
+				     "no clock\n");
 
 	priv->extclk = devm_clk_get(&pdev->dev, "extclk");
 	if (IS_ERR(priv->extclk)) {
@@ -726,10 +725,8 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	err = snd_soc_register_component(&pdev->dev, &kirkwood_soc_component,
 					 soc_dai, 2);
-	if (err) {
-		dev_err(&pdev->dev, "snd_soc_register_component failed\n");
+	if (err)
 		goto err_component;
-	}
 
 	kirkwood_i2s_init(priv);
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 ASoC: kirkwood: kirkwood-i2s: Check return value of clk_prepare_enable()

In reply to [email protected]

From: bui duc phuc <[email protected]>

kirkwood_i2s_dev_probe() ignores the return value of clk_prepare_enable() when enabling the external clock.

If enabling the clock fails, the driver still selects the external clock DAI configuration and may later call clk_disable_unprepare() on a clock that was never successfully enabled, triggering an unbalanced disable warning.

Check the return value and fail probe if enabling the clock fails.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/kirkwood/kirkwood-i2s.c +3 -1
index 29641bd4cc60..395790682355 100644
@@ -701,7 +701,9 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 			priv->extclk = ERR_PTR(-EINVAL);
 		} else {
 			dev_info(&pdev->dev, "found external clock\n");
-			clk_prepare_enable(priv->extclk);
+			err = clk_prepare_enable(priv->extclk);
+			if (err < 0)
+				return err;
 			soc_dai = kirkwood_i2s_dai_extclk;
 		}
 	}
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 ASoC: kirkwood: kirkwood-i2s: Disable extclk on internal clk error

In reply to [email protected]

From: bui duc phuc <[email protected]>

kirkwood_i2s_dev_probe() enables the external clock before the internal clock. If enabling the internal clock fails, the probe returns directly, leaving the external clock enabled.

Jump to err_clk to disable the external clock on failure. Also reorder the error path to disable the clocks in reverse order of enabling, allowing the error labels to fall through.

Fixes 4523817d51bc ("ASoC: kirkwood: fix external clock probe defer")
---
 sound/soc/kirkwood/kirkwood-i2s.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +4 -3
index 395790682355..cf6b96054b82 100644
@@ -710,7 +710,7 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	err = clk_prepare_enable(priv->clk);
 	if (err < 0)
-		return err;
+		goto err_clk;
 
 	/* Some sensible defaults - this reflects the powerup values */
 	priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24;
@@ -734,10 +734,11 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	return 0;
 
- err_component:
+err_component:
+	clk_disable_unprepare(priv->clk);
+err_clk:
 	if (!IS_ERR(priv->extclk))
 		clk_disable_unprepare(priv->extclk);
-	clk_disable_unprepare(priv->clk);
 
 	return err;
 }
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/5 ASoC: kirkwood: kirkwood-i2s: Disable clocks in reverse order in remove()

In reply to [email protected]

From: bui duc phuc <[email protected]>

Disable the internal clock before the external one in kirkwood_i2s_dev_remove(), matching the reverse order of enabling and the error path in kirkwood_i2s_dev_probe().

No functional change intended.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/kirkwood/kirkwood-i2s.c +1 -1
index cf6b96054b82..c26326b82c19 100644
@@ -748,9 +748,9 @@ static void kirkwood_i2s_dev_remove(struct platform_device *pdev)
 	struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
 
 	snd_soc_unregister_component(&pdev->dev);
+	clk_disable_unprepare(priv->clk);
 	if (!IS_ERR(priv->extclk))
 		clk_disable_unprepare(priv->extclk);
-	clk_disable_unprepare(priv->clk);
 }
 
 #ifdef CONFIG_OF
Signature · 1 line
2.43.0
maintainer
#6 lore raw
In reply to [email protected]
Quoted 10 lines · On Mon, 26 Oct 2026 17:58:30 +0700, [email protected] wrote:

ASoC: kirkwood: Improve clock and error handling

From: bui duc phuc <[email protected]>

Hi all,

This series improves error handling and clock management in the Kirkwood I2S driver.

[...]

Applied to

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

Thanks!

[1/5] ASoC: kirkwood: kirkwood-i2s: Fix error handling for resource mapping

      https://git.kernel.org/broonie/sound/c/0d376515e842
[2/5] ASoC: kirkwood: kirkwood-i2s: Improve error handling in probe
      https://git.kernel.org/broonie/sound/c/cbe600cecb44
[3/5] ASoC: kirkwood: kirkwood-i2s: Check return value of clk_prepare_enable()
      https://git.kernel.org/broonie/sound/c/1de736925a68
[4/5] ASoC: kirkwood: kirkwood-i2s: Disable extclk on internal clk error
      https://git.kernel.org/broonie/sound/c/9765fd9e107d
[5/5] ASoC: kirkwood: kirkwood-i2s: Disable clocks in reverse order in remove()
      https://git.kernel.org/broonie/sound/c/9a5990047d40

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