diff mbox series

ASoC: fsi: Add check for clk_enable

Message ID 20220301073949.3678707-1-jiasheng@iscas.ac.cn (mailing list archive)
State Superseded
Headers show
Series ASoC: fsi: Add check for clk_enable | expand

Commit Message

Jiasheng Jiang March 1, 2022, 7:39 a.m. UTC
As the potential failure of the clk_enable(),
it should be better to check it and return error
if fails.

Fixes: ab6f6d85210c ("ASoC: fsi: add master clock control functions")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 sound/soc/sh/fsi.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Mark Brown March 1, 2022, 12:44 p.m. UTC | #1
On Tue, Mar 01, 2022 at 03:39:49PM +0800, Jiasheng Jiang wrote:
> As the potential failure of the clk_enable(),
> it should be better to check it and return error
> if fails.

> -		clk_enable(clock->xck);
> -		clk_enable(clock->ick);
> -		clk_enable(clock->div);
> +		ret = clk_enable(clock->xck);
> +		if (ret)
> +			goto err;
> +		ret = clk_enable(clock->ick);
> +		if (ret)
> +			goto err;
> +		ret = clk_enable(clock->div);
> +		if (ret)
> +			goto err;
>  
>  		clock->count++;
>  	}
>  
>  	return ret;
> +
> +err:
> +	clk_disable(clock->xck);
> +	clk_disable(clock->ick);
> +	clk_disable(clock->div);

You need separate labels for each enable so that we don't end up
disabling clocks we didn't enable, that would also be a bug.
diff mbox series

Patch

diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index cdf3b7f69ba7..93cfa77b8b54 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -816,14 +816,26 @@  static int fsi_clk_enable(struct device *dev,
 			return ret;
 		}
 
-		clk_enable(clock->xck);
-		clk_enable(clock->ick);
-		clk_enable(clock->div);
+		ret = clk_enable(clock->xck);
+		if (ret)
+			goto err;
+		ret = clk_enable(clock->ick);
+		if (ret)
+			goto err;
+		ret = clk_enable(clock->div);
+		if (ret)
+			goto err;
 
 		clock->count++;
 	}
 
 	return ret;
+
+err:
+	clk_disable(clock->xck);
+	clk_disable(clock->ick);
+	clk_disable(clock->div);
+	return ret;
 }
 
 static int fsi_clk_disable(struct device *dev,