[-next] media: c8sectpfe: Use the devm_clk_get_enabled() helper function

Message ID 20230818101541.1129209-1-ruanjinjie@huawei.com (mailing list archive)
State Accepted
Delegated to: Hans Verkuil
Headers
Series [-next] media: c8sectpfe: Use the devm_clk_get_enabled() helper function |

Commit Message

Jinjie Ruan Aug. 18, 2023, 10:15 a.m. UTC
  With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
dropped from the error path and the remove callback.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
 .../st/sti/c8sectpfe/c8sectpfe-core.c         | 26 +++++--------------
 1 file changed, 7 insertions(+), 19 deletions(-)
  

Comments

Patrice CHOTARD Aug. 18, 2023, 3:37 p.m. UTC | #1
On 8/18/23 12:15, Ruan Jinjie wrote:
> With devm_clk_get_enabled() the call to clk_disable_unprepare() can be
> dropped from the error path and the remove callback.
> 
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
>  .../st/sti/c8sectpfe/c8sectpfe-core.c         | 26 +++++--------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
> index 5dc1f908b49b..e4cf27b5a072 100644
> --- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
> +++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
> @@ -695,16 +695,10 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, fei);
>  
> -	fei->c8sectpfeclk = devm_clk_get(dev, "c8sectpfe");
> +	fei->c8sectpfeclk = devm_clk_get_enabled(dev, "c8sectpfe");
>  	if (IS_ERR(fei->c8sectpfeclk)) {
> -		dev_err(dev, "c8sectpfe clk not found\n");
> -		return PTR_ERR(fei->c8sectpfeclk);
> -	}
> -
> -	ret = clk_prepare_enable(fei->c8sectpfeclk);
> -	if (ret) {
>  		dev_err(dev, "Failed to enable c8sectpfe clock\n");
> -		return ret;
> +		return PTR_ERR(fei->c8sectpfeclk);
>  	}
>  
>  	/* to save power disable all IP's (on by default) */
> @@ -722,7 +716,7 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  			0, "c8sectpfe-idle-irq", fei);
>  	if (ret) {
>  		dev_err(dev, "Can't register c8sectpfe-idle-irq IRQ.\n");
> -		goto err_clk_disable;
> +		return ret;
>  	}
>  
>  	ret = devm_request_irq(dev, fei->error_irq,
> @@ -730,7 +724,7 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  				"c8sectpfe-error-irq", fei);
>  	if (ret) {
>  		dev_err(dev, "Can't register c8sectpfe-error-irq IRQ.\n");
> -		goto err_clk_disable;
> +		return ret;
>  	}
>  
>  	fei->tsin_count = of_get_child_count(np);
> @@ -739,16 +733,14 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  		fei->tsin_count > fei->hw_stats.num_ib) {
>  
>  		dev_err(dev, "More tsin declared than exist on SoC!\n");
> -		ret = -EINVAL;
> -		goto err_clk_disable;
> +		return -EINVAL;
>  	}
>  
>  	fei->pinctrl = devm_pinctrl_get(dev);
>  
>  	if (IS_ERR(fei->pinctrl)) {
>  		dev_err(dev, "Error getting tsin pins\n");
> -		ret = PTR_ERR(fei->pinctrl);
> -		goto err_clk_disable;
> +		return PTR_ERR(fei->pinctrl);
>  	}
>  
>  	for_each_child_of_node(np, child) {
> @@ -859,7 +851,7 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  	if (ret) {
>  		dev_err(dev, "c8sectpfe_tuner_register_frontend failed (%d)\n",
>  			ret);
> -		goto err_clk_disable;
> +		return ret;
>  	}
>  
>  	c8sectpfe_debugfs_init(fei);
> @@ -868,8 +860,6 @@ static int c8sectpfe_probe(struct platform_device *pdev)
>  
>  err_node_put:
>  	of_node_put(child);
> -err_clk_disable:
> -	clk_disable_unprepare(fei->c8sectpfeclk);
>  	return ret;
>  }
>  
> @@ -903,8 +893,6 @@ static void c8sectpfe_remove(struct platform_device *pdev)
>  
>  	if (readl(fei->io + SYS_OTHER_CLKEN))
>  		writel(0, fei->io + SYS_OTHER_CLKEN);
> -
> -	clk_disable_unprepare(fei->c8sectpfeclk);
>  }
>  
>  

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
  

Patch

diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
index 5dc1f908b49b..e4cf27b5a072 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
+++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
@@ -695,16 +695,10 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, fei);
 
-	fei->c8sectpfeclk = devm_clk_get(dev, "c8sectpfe");
+	fei->c8sectpfeclk = devm_clk_get_enabled(dev, "c8sectpfe");
 	if (IS_ERR(fei->c8sectpfeclk)) {
-		dev_err(dev, "c8sectpfe clk not found\n");
-		return PTR_ERR(fei->c8sectpfeclk);
-	}
-
-	ret = clk_prepare_enable(fei->c8sectpfeclk);
-	if (ret) {
 		dev_err(dev, "Failed to enable c8sectpfe clock\n");
-		return ret;
+		return PTR_ERR(fei->c8sectpfeclk);
 	}
 
 	/* to save power disable all IP's (on by default) */
@@ -722,7 +716,7 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 			0, "c8sectpfe-idle-irq", fei);
 	if (ret) {
 		dev_err(dev, "Can't register c8sectpfe-idle-irq IRQ.\n");
-		goto err_clk_disable;
+		return ret;
 	}
 
 	ret = devm_request_irq(dev, fei->error_irq,
@@ -730,7 +724,7 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 				"c8sectpfe-error-irq", fei);
 	if (ret) {
 		dev_err(dev, "Can't register c8sectpfe-error-irq IRQ.\n");
-		goto err_clk_disable;
+		return ret;
 	}
 
 	fei->tsin_count = of_get_child_count(np);
@@ -739,16 +733,14 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 		fei->tsin_count > fei->hw_stats.num_ib) {
 
 		dev_err(dev, "More tsin declared than exist on SoC!\n");
-		ret = -EINVAL;
-		goto err_clk_disable;
+		return -EINVAL;
 	}
 
 	fei->pinctrl = devm_pinctrl_get(dev);
 
 	if (IS_ERR(fei->pinctrl)) {
 		dev_err(dev, "Error getting tsin pins\n");
-		ret = PTR_ERR(fei->pinctrl);
-		goto err_clk_disable;
+		return PTR_ERR(fei->pinctrl);
 	}
 
 	for_each_child_of_node(np, child) {
@@ -859,7 +851,7 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(dev, "c8sectpfe_tuner_register_frontend failed (%d)\n",
 			ret);
-		goto err_clk_disable;
+		return ret;
 	}
 
 	c8sectpfe_debugfs_init(fei);
@@ -868,8 +860,6 @@  static int c8sectpfe_probe(struct platform_device *pdev)
 
 err_node_put:
 	of_node_put(child);
-err_clk_disable:
-	clk_disable_unprepare(fei->c8sectpfeclk);
 	return ret;
 }
 
@@ -903,8 +893,6 @@  static void c8sectpfe_remove(struct platform_device *pdev)
 
 	if (readl(fei->io + SYS_OTHER_CLKEN))
 		writel(0, fei->io + SYS_OTHER_CLKEN);
-
-	clk_disable_unprepare(fei->c8sectpfeclk);
 }