public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: kirkwood: Fix clock error handling in probe
@ 2026-03-24 20:55 Jihed Chaibi
  2026-03-26  9:56 ` Jihed Chaibi
  0 siblings, 1 reply; 2+ messages in thread
From: Jihed Chaibi @ 2026-03-24 20:55 UTC (permalink / raw)
  To: linux-sound
  Cc: lgirdwood, broonie, perex, tiwai, linux-kernel, jihed.chaibi.dev

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


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

* Re: [PATCH] ASoC: kirkwood: Fix clock error handling in probe
  2026-03-24 20:55 [PATCH] ASoC: kirkwood: Fix clock error handling in probe Jihed Chaibi
@ 2026-03-26  9:56 ` Jihed Chaibi
  0 siblings, 0 replies; 2+ messages in thread
From: Jihed Chaibi @ 2026-03-26  9:56 UTC (permalink / raw)
  To: linux-sound; +Cc: lgirdwood, broonie, perex, tiwai, linux-kernel

On Tue, Mar 24, 2026 at 9:56 PM Jihed Chaibi <jihed.chaibi.dev@gmail.com> wrote:
>
> 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@gmail.com>
> ---
>  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
>

Adding the missing Fixes tag:
Fixes: d8d11ba56676 ("ASoC: kirkwood-i2s: better handling of
play/record control registers")

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

end of thread, other threads:[~2026-03-26  9:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 20:55 [PATCH] ASoC: kirkwood: Fix clock error handling in probe Jihed Chaibi
2026-03-26  9:56 ` Jihed Chaibi

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