diff mbox series

[-next] hwspinlock: stm32: Add missing clk_disable_unprepare in stm32_hwspinlock_probe

Message ID 20240803061443.287117-1-cuigaosheng1@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next] hwspinlock: stm32: Add missing clk_disable_unprepare in stm32_hwspinlock_probe | expand

Commit Message

cuigaosheng Aug. 3, 2024, 6:14 a.m. UTC
Add the missing clk_disable_unprepare() before return in
stm32_hwspinlock_probe().

Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/hwspinlock/stm32_hwspinlock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Baolin Wang Aug. 8, 2024, 1:37 a.m. UTC | #1
On 2024/8/3 14:14, Gaosheng Cui wrote:
> Add the missing clk_disable_unprepare() before return in
> stm32_hwspinlock_probe().
> 
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
>   drivers/hwspinlock/stm32_hwspinlock.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c
> index bb5c7e5f7a80..a4e3b9a9e29d 100644
> --- a/drivers/hwspinlock/stm32_hwspinlock.c
> +++ b/drivers/hwspinlock/stm32_hwspinlock.c
> @@ -103,6 +103,7 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev)
>   	ret = devm_add_action_or_reset(dev, stm32_hwspinlock_disable_clk, pdev);
>   	if (ret) {
>   		dev_err(dev, "Failed to register action\n");
> +		clk_disable_unprepare(hw->clk);
>   		return ret;
>   	}
>   
> @@ -112,8 +113,10 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev)
>   	ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops,
>   					0, STM32_MUTEX_NUM_LOCKS);
>   
> -	if (ret)
> +	if (ret) {
>   		dev_err(dev, "Failed to register hwspinlock\n");
> +		clk_disable_unprepare(hw->clk);
> +	}

I don't think this is needed, because if the device initialization 
fails, stm32_hwspinlock_disable_clk() will be called to disable the 
clock automatically when the device releases its resources. Please check 
how devm_add_action_or_reset() work.
diff mbox series

Patch

diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c
index bb5c7e5f7a80..a4e3b9a9e29d 100644
--- a/drivers/hwspinlock/stm32_hwspinlock.c
+++ b/drivers/hwspinlock/stm32_hwspinlock.c
@@ -103,6 +103,7 @@  static int stm32_hwspinlock_probe(struct platform_device *pdev)
 	ret = devm_add_action_or_reset(dev, stm32_hwspinlock_disable_clk, pdev);
 	if (ret) {
 		dev_err(dev, "Failed to register action\n");
+		clk_disable_unprepare(hw->clk);
 		return ret;
 	}
 
@@ -112,8 +113,10 @@  static int stm32_hwspinlock_probe(struct platform_device *pdev)
 	ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops,
 					0, STM32_MUTEX_NUM_LOCKS);
 
-	if (ret)
+	if (ret) {
 		dev_err(dev, "Failed to register hwspinlock\n");
+		clk_disable_unprepare(hw->clk);
+	}
 
 	return ret;
 }