]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
clk: qcom: rpm: simplify locking with guard()
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Fri, 23 Aug 2024 15:38:43 +0000 (17:38 +0200)
committerBjorn Andersson <andersson@kernel.org>
Thu, 26 Dec 2024 04:14:28 +0000 (22:14 -0600)
Simplify error handling (less gotos) over locks with guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240823-cleanup-h-guard-clk-qcom-v1-1-68bb9601c9dd@linaro.org
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/clk/qcom/clk-rpm.c

index 9da034f8f2ff504404abc4f7a0d3b8fb841a6ce0..ccc112c21667ebf8522b06b37234f46c69b07698 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk-provider.h>
 #include <linux/err.h>
 #include <linux/export.h>
@@ -224,10 +225,10 @@ static void clk_rpm_unprepare(struct clk_hw *hw)
        unsigned long active_rate, sleep_rate;
        int ret;
 
-       mutex_lock(&rpm_clk_lock);
+       guard(mutex)(&rpm_clk_lock);
 
        if (!r->rate)
-               goto out;
+               return;
 
        /* Take peer clock's rate into account only if it's enabled. */
        if (peer->enabled)
@@ -237,17 +238,14 @@ static void clk_rpm_unprepare(struct clk_hw *hw)
        active_rate = r->branch ? !!peer_rate : peer_rate;
        ret = clk_rpm_set_rate_active(r, active_rate);
        if (ret)
-               goto out;
+               return;
 
        sleep_rate = r->branch ? !!peer_sleep_rate : peer_sleep_rate;
        ret = clk_rpm_set_rate_sleep(r, sleep_rate);
        if (ret)
-               goto out;
+               return;
 
        r->enabled = false;
-
-out:
-       mutex_unlock(&rpm_clk_lock);
 }
 
 static int clk_rpm_xo_prepare(struct clk_hw *hw)
@@ -324,12 +322,12 @@ static int clk_rpm_set_rate(struct clk_hw *hw,
        unsigned long active_rate, sleep_rate;
        unsigned long this_rate = 0, this_sleep_rate = 0;
        unsigned long peer_rate = 0, peer_sleep_rate = 0;
-       int ret = 0;
+       int ret;
 
-       mutex_lock(&rpm_clk_lock);
+       guard(mutex)(&rpm_clk_lock);
 
        if (!r->enabled)
-               goto out;
+               return 0;
 
        to_active_sleep(r, rate, &this_rate, &this_sleep_rate);
 
@@ -341,19 +339,16 @@ static int clk_rpm_set_rate(struct clk_hw *hw,
        active_rate = max(this_rate, peer_rate);
        ret = clk_rpm_set_rate_active(r, active_rate);
        if (ret)
-               goto out;
+               return ret;
 
        sleep_rate = max(this_sleep_rate, peer_sleep_rate);
        ret = clk_rpm_set_rate_sleep(r, sleep_rate);
        if (ret)
-               goto out;
+               return ret;
 
        r->rate = rate;
 
-out:
-       mutex_unlock(&rpm_clk_lock);
-
-       return ret;
+       return 0;
 }
 
 static long clk_rpm_round_rate(struct clk_hw *hw, unsigned long rate,