diff mbox series

ASoC: ak4642: Return of_clk_add_provider to transfer the error

Message ID 20240717114024.3441163-1-make24@iscas.ac.cn (mailing list archive)
State New, archived
Headers show
Series ASoC: ak4642: Return of_clk_add_provider to transfer the error | expand

Commit Message

Ma Ke July 17, 2024, 11:40 a.m. UTC
Return of_clk_add_provider() in order to transfer the error if it fails due
to insufficient memory allocation or failure to set clock defaults.

Fixes: 171a0138ab75 ("ASoC: ak4642: enable to use MCKO as fixed rate output pin on DT")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 sound/soc/codecs/ak4642.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Mark Brown July 17, 2024, 12:56 p.m. UTC | #1
On Wed, Jul 17, 2024 at 07:40:24PM +0800, Ma Ke wrote:

>  	clk = clk_register_fixed_rate(dev, clk_name, parent_clk_name, 0, rate);
> -	if (!IS_ERR(clk))
> -		of_clk_add_provider(np, of_clk_src_simple_get, clk);
> +	if (!IS_ERR(clk)) {
> +		ret = of_clk_add_provider(np, of_clk_src_simple_get, clk);
> +		if (ret)
> +			return ERR_PTR(ret);
> +	}

This will leak clk if adding the provider fails.
diff mbox series

Patch

diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index fe035d2fc913..2f1b295bca98 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -609,6 +609,7 @@  static struct clk *ak4642_of_parse_mcko(struct device *dev)
 	const char *clk_name = np->name;
 	const char *parent_clk_name = NULL;
 	u32 rate;
+	int ret;
 
 	if (of_property_read_u32(np, "clock-frequency", &rate))
 		return NULL;
@@ -619,8 +620,11 @@  static struct clk *ak4642_of_parse_mcko(struct device *dev)
 	of_property_read_string(np, "clock-output-names", &clk_name);
 
 	clk = clk_register_fixed_rate(dev, clk_name, parent_clk_name, 0, rate);
-	if (!IS_ERR(clk))
-		of_clk_add_provider(np, of_clk_src_simple_get, clk);
+	if (!IS_ERR(clk)) {
+		ret = of_clk_add_provider(np, of_clk_src_simple_get, clk);
+		if (ret)
+			return ERR_PTR(ret);
+	}
 
 	return clk;
 }