[PATCH] ASoC: kirkwood: Fix clock error handling in probe

From: Jihed Chaibi

Date: Tue Mar 24 2026 - 17:02:52 EST


Two problems in the same clock setup block:

1. clk_prepare_enable(priv->extclk) had its return value discarded,
while the immediately following clk_prepare_enable(priv->clk) was
correctly checked. A failure to enable the external clock was
silently ignored.

2. If clk_prepare_enable(priv->clk) failed, priv->extclk was already
enabled but never disabled — the error path returned directly
without cleanup.

Fix both by checking extclk enable and restructuring the error labels
to chain: err_component disables priv->clk then falls through to
err_extclk which disables priv->extclk if present.

Signed-off-by: Jihed Chaibi <jihed.chaibi.dev@xxxxxxxxx>
---
sound/soc/kirkwood/kirkwood-i2s.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c
index 99bd066c7309..ea734bc33dc3 100644
--- a/sound/soc/kirkwood/kirkwood-i2s.c
+++ b/sound/soc/kirkwood/kirkwood-i2s.c
@@ -695,14 +695,16 @@ 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;
}
}

err = clk_prepare_enable(priv->clk);
if (err < 0)
- return err;
+ goto err_extclk;

/* Some sensible defaults - this reflects the powerup values */
priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24;
@@ -729,9 +731,10 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
return 0;

err_component:
+ clk_disable_unprepare(priv->clk);
+ err_extclk:
if (!IS_ERR(priv->extclk))
clk_disable_unprepare(priv->extclk);
- clk_disable_unprepare(priv->clk);

return err;
}
--
2.47.3