Skip to contentSkip to conversation

ASoC: kirkwood: Fix clock error handling in probe

PATCH In review Jihed Chaibi 1 participant 2 messages Mar 24 – Mar 26

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

PATCH 1/1 ASoC: kirkwood: Fix clock error handling in probe

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.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +6 -3
index 99bd066c7309..ea734bc33dc3 100644
@@ -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;
 }
Signature · 1 line
2.47.3
#1 lore raw
Quoted 57 lines · Jihed Chaibi

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.

---
 sound/soc/kirkwood/kirkwood-i2s.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +6 -4
index 99bd066c7309..ea734bc33dc3 100644
@@ -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;
 }
--
Quoted 2 lines

2.47.3

Adding the missing Fixes tag:

Fixes d8d11ba56676 ("ASoC: kirkwood-i2s: better handling of

play/record control registers")