diff mbox series

[3/4] dmaengine: ste_dma40: Remove unneeded ERROR and NULL check in ste_dma40

Message ID 20220516084139.8864-4-wanjiabing@vivo.com (mailing list archive)
State New
Headers show
Series dmaengine: Remove unneeded ERROR checks before clk_xxx | expand

Commit Message

Jiabing Wan May 16, 2022, 8:41 a.m. UTC
clk_put() already checks ERROR by using IS_ERR.
clk_disable_unprepare() already checks NULL by using IS_ERR_OR_NULL.
Remove unneeded NULL check for clk_ret and ERROR check for clk.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 drivers/dma/ste_dma40.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Krzysztof Kozlowski May 18, 2022, 7:15 a.m. UTC | #1
On 16/05/2022 10:41, Wan Jiabing wrote:
> clk_put() already checks ERROR by using IS_ERR.
> clk_disable_unprepare() already checks NULL by using IS_ERR_OR_NULL.
> Remove unneeded NULL check for clk_ret and ERROR check for clk.
> 
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> ---
>  drivers/dma/ste_dma40.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
> index e1827393143f..7d1bf4ae4495 100644
> --- a/drivers/dma/ste_dma40.c
> +++ b/drivers/dma/ste_dma40.c
> @@ -3119,7 +3119,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
>  	clk = clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(clk)) {
>  		d40_err(&pdev->dev, "No matching clock found\n");
> -		goto check_prepare_enabled;
> +		goto disable_unprepare;

This should be rather return PTR_ERR. No need to jump to labels which
are not relevant (even if harmless) for this case. It's a confusing code.

>  	}
>  
>  	clk_ret = clk_prepare_enable(clk);
> @@ -3305,12 +3305,10 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
>  	iounmap(virtbase);
>   release_region:
>  	release_mem_region(res->start, resource_size(res));
> - check_prepare_enabled:
> -	if (!clk_ret)
>   disable_unprepare:
> -		clk_disable_unprepare(clk);
> -	if (!IS_ERR(clk))
> -		clk_put(clk);
> +	clk_disable_unprepare(clk);
> +	clk_put(clk);
> +
>  	return NULL;
>  }
>  


Best regards,
Krzysztof
Jiabing Wan May 19, 2022, 6:34 a.m. UTC | #2
On 2022/5/18 15:15, Krzysztof Kozlowski wrote:
> On 16/05/2022 10:41, Wan Jiabing wrote:
>> clk_put() already checks ERROR by using IS_ERR.
>> clk_disable_unprepare() already checks NULL by using IS_ERR_OR_NULL.
>> Remove unneeded NULL check for clk_ret and ERROR check for clk.
>>
>> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
>> ---
>>   drivers/dma/ste_dma40.c | 10 ++++------
>>   1 file changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
>> index e1827393143f..7d1bf4ae4495 100644
>> --- a/drivers/dma/ste_dma40.c
>> +++ b/drivers/dma/ste_dma40.c
>> @@ -3119,7 +3119,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
>>   	clk = clk_get(&pdev->dev, NULL);
>>   	if (IS_ERR(clk)) {
>>   		d40_err(&pdev->dev, "No matching clock found\n");
>> -		goto check_prepare_enabled;
>> +		goto disable_unprepare;
> This should be rather return PTR_ERR. No need to jump to labels which
> are not relevant (even if harmless) for this case. It's a confusing code.
OK, I'll fix it.
>>   	}
>>   
>>   	clk_ret = clk_prepare_enable(clk);
>> @@ -3305,12 +3305,10 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
>>   	iounmap(virtbase);
>>    release_region:
>>   	release_mem_region(res->start, resource_size(res));
>> - check_prepare_enabled:
>> -	if (!clk_ret)
>>    disable_unprepare:
>> -		clk_disable_unprepare(clk);
>> -	if (!IS_ERR(clk))
>> -		clk_put(clk);

So this IS_ERR(clk) is also better than WARN_ON_ONCE(IS_ERR(clk)) in 
clk_put().

IS_ERR(clk) before  clk_put(clk) is needed for avoiding the unexpected warning.

>> +	clk_disable_unprepare(clk);
>> +	clk_put(clk);
>> +
>>   	return NULL;
>>   }
>>   
Thanks,
Wan Jiabing
diff mbox series

Patch

diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index e1827393143f..7d1bf4ae4495 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -3119,7 +3119,7 @@  static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
 	clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		d40_err(&pdev->dev, "No matching clock found\n");
-		goto check_prepare_enabled;
+		goto disable_unprepare;
 	}
 
 	clk_ret = clk_prepare_enable(clk);
@@ -3305,12 +3305,10 @@  static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
 	iounmap(virtbase);
  release_region:
 	release_mem_region(res->start, resource_size(res));
- check_prepare_enabled:
-	if (!clk_ret)
  disable_unprepare:
-		clk_disable_unprepare(clk);
-	if (!IS_ERR(clk))
-		clk_put(clk);
+	clk_disable_unprepare(clk);
+	clk_put(clk);
+
 	return NULL;
 }