diff mbox series

[1/2] thermal/drivers/qoriq: Use dev_err_probe() simplify the code

Message ID 20241206225624.3744880-1-Frank.Li@nxp.com (mailing list archive)
State Superseded, archived
Headers show
Series [1/2] thermal/drivers/qoriq: Use dev_err_probe() simplify the code | expand

Commit Message

Frank Li Dec. 6, 2024, 10:56 p.m. UTC
Use dev_err_probe() and devm_clk_get_optional_enabled() to simplify the
code.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/thermal/qoriq_thermal.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

Comments

Christophe JAILLET Dec. 6, 2024, 11:18 p.m. UTC | #1
Le 06/12/2024 à 23:56, Frank Li a écrit :
> Use dev_err_probe() and devm_clk_get_optional_enabled() to simplify the
> code.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>   drivers/thermal/qoriq_thermal.c | 33 ++++++++++-----------------------
>   1 file changed, 10 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 52e26be8c53df..baf1b75b97cbe 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -296,38 +296,27 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
>   
>   	base = devm_platform_ioremap_resource(pdev, 0);
>   	ret = PTR_ERR_OR_ZERO(base);
> -	if (ret) {
> -		dev_err(dev, "Failed to get memory region\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to get memory region\n");
>   
>   	data->regmap = devm_regmap_init_mmio(dev, base, &regmap_config);
>   	ret = PTR_ERR_OR_ZERO(data->regmap);
> -	if (ret) {
> -		dev_err(dev, "Failed to init regmap (%d)\n", ret);
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to init regmap\n");
>   
> -	data->clk = devm_clk_get_optional(dev, NULL);
> +	data->clk = devm_clk_get_optional_enabled(dev, NULL);
>   	if (IS_ERR(data->clk))
>   		return PTR_ERR(data->clk);
>   
> -	ret = clk_prepare_enable(data->clk);
> -	if (ret) {
> -		dev_err(dev, "Failed to enable clock\n");
> -		return ret;
> -	}
> -
>   	ret = devm_add_action_or_reset(dev, qoriq_tmu_action, data);

clk_disable_unprepare() in qoriq_tmu_action() should be removed as-well.

>   	if (ret)
>   		return ret;
>   
>   	/* version register offset at: 0xbf8 on both v1 and v2 */
>   	ret = regmap_read(data->regmap, REGS_IPBRR(0), &ver);
> -	if (ret) {
> -		dev_err(&pdev->dev, "Failed to read IP block version\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret,  "Failed to read IP block version\n");
> +
>   	data->ver = (ver >> 8) & 0xff;
>   
>   	qoriq_tmu_init_device(data);	/* TMU initialization */
> @@ -337,10 +326,8 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
>   		return ret;
>   
>   	ret = qoriq_tmu_register_tmu_zone(dev, data);
> -	if (ret < 0) {
> -		dev_err(dev, "Failed to register sensors\n");
> -		return ret;
> -	}
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "Failed to register sensors\n");
>   
>   	platform_set_drvdata(pdev, data);
>
diff mbox series

Patch

diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 52e26be8c53df..baf1b75b97cbe 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -296,38 +296,27 @@  static int qoriq_tmu_probe(struct platform_device *pdev)
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	ret = PTR_ERR_OR_ZERO(base);
-	if (ret) {
-		dev_err(dev, "Failed to get memory region\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get memory region\n");
 
 	data->regmap = devm_regmap_init_mmio(dev, base, &regmap_config);
 	ret = PTR_ERR_OR_ZERO(data->regmap);
-	if (ret) {
-		dev_err(dev, "Failed to init regmap (%d)\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to init regmap\n");
 
-	data->clk = devm_clk_get_optional(dev, NULL);
+	data->clk = devm_clk_get_optional_enabled(dev, NULL);
 	if (IS_ERR(data->clk))
 		return PTR_ERR(data->clk);
 
-	ret = clk_prepare_enable(data->clk);
-	if (ret) {
-		dev_err(dev, "Failed to enable clock\n");
-		return ret;
-	}
-
 	ret = devm_add_action_or_reset(dev, qoriq_tmu_action, data);
 	if (ret)
 		return ret;
 
 	/* version register offset at: 0xbf8 on both v1 and v2 */
 	ret = regmap_read(data->regmap, REGS_IPBRR(0), &ver);
-	if (ret) {
-		dev_err(&pdev->dev, "Failed to read IP block version\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret,  "Failed to read IP block version\n");
+
 	data->ver = (ver >> 8) & 0xff;
 
 	qoriq_tmu_init_device(data);	/* TMU initialization */
@@ -337,10 +326,8 @@  static int qoriq_tmu_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = qoriq_tmu_register_tmu_zone(dev, data);
-	if (ret < 0) {
-		dev_err(dev, "Failed to register sensors\n");
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to register sensors\n");
 
 	platform_set_drvdata(pdev, data);