summaryrefslogtreecommitdiffstats
path: root/drivers/pmdomain
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>2024-08-23 14:51:10 +0200
committerUlf Hansson <ulf.hansson@linaro.org>2024-09-13 12:21:04 +0200
commitba3a65c69bdbff04ea5699597bf491de5cbe82e9 (patch)
treeaea3bc51d6899ffa87c62d2735565cbde4684ec7 /drivers/pmdomain
parentpmdomain: qcom: cpr: Simplify with dev_err_probe() (diff)
downloadlinux-ba3a65c69bdbff04ea5699597bf491de5cbe82e9.tar.xz
linux-ba3a65c69bdbff04ea5699597bf491de5cbe82e9.zip
pmdomain: qcom: cpr: Simplify locking with guard()
Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Reviewed-by: Konrad Dybcio <konradybcio@kernel.org> Link: https://lore.kernel.org/r/20240823-cleanup-h-guard-pm-domain-v1-6-8320722eaf39@linaro.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/pmdomain')
-rw-r--r--drivers/pmdomain/qcom/cpr.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/drivers/pmdomain/qcom/cpr.c b/drivers/pmdomain/qcom/cpr.c
index 87d1db1a0019..e1fca65b80be 100644
--- a/drivers/pmdomain/qcom/cpr.c
+++ b/drivers/pmdomain/qcom/cpr.c
@@ -4,6 +4,7 @@
* Copyright (c) 2019, Linaro Limited
*/
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/debugfs.h>
@@ -747,9 +748,9 @@ static int cpr_set_performance_state(struct generic_pm_domain *domain,
struct cpr_drv *drv = container_of(domain, struct cpr_drv, pd);
struct corner *corner, *end;
enum voltage_change_dir dir;
- int ret = 0, new_uV;
+ int ret, new_uV;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
dev_dbg(drv->dev, "%s: setting perf state: %u (prev state: %u)\n",
__func__, state, cpr_get_cur_perf_state(drv));
@@ -760,10 +761,8 @@ static int cpr_set_performance_state(struct generic_pm_domain *domain,
*/
corner = drv->corners + state - 1;
end = &drv->corners[drv->num_corners - 1];
- if (corner > end || corner < drv->corners) {
- ret = -EINVAL;
- goto unlock;
- }
+ if (corner > end || corner < drv->corners)
+ return -EINVAL;
/* Determine direction */
if (drv->corner > corner)
@@ -783,7 +782,7 @@ static int cpr_set_performance_state(struct generic_pm_domain *domain,
ret = cpr_scale_voltage(drv, corner, new_uV, dir);
if (ret)
- goto unlock;
+ return ret;
if (cpr_is_allowed(drv)) {
cpr_irq_clr(drv);
@@ -794,10 +793,7 @@ static int cpr_set_performance_state(struct generic_pm_domain *domain,
drv->corner = corner;
-unlock:
- mutex_unlock(&drv->lock);
-
- return ret;
+ return 0;
}
static int
@@ -1437,9 +1433,9 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain,
{
struct cpr_drv *drv = container_of(domain, struct cpr_drv, pd);
const struct acc_desc *acc_desc = drv->acc_desc;
- int ret = 0;
+ int ret;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
dev_dbg(drv->dev, "attach callback for: %s\n", dev_name(dev));
@@ -1451,7 +1447,7 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain,
* additional initialization when further CPUs get attached.
*/
if (drv->attached_cpu_dev)
- goto unlock;
+ return 0;
/*
* cpr_scale_voltage() requires the direction (if we are changing
@@ -1463,11 +1459,10 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain,
* the first time cpr_set_performance_state() is called.
*/
drv->cpu_clk = devm_clk_get(dev, NULL);
- if (IS_ERR(drv->cpu_clk)) {
- ret = dev_err_probe(drv->dev, PTR_ERR(drv->cpu_clk),
- "could not get cpu clk\n");
- goto unlock;
- }
+ if (IS_ERR(drv->cpu_clk))
+ return dev_err_probe(drv->dev, PTR_ERR(drv->cpu_clk),
+ "could not get cpu clk\n");
+
drv->attached_cpu_dev = dev;
dev_dbg(drv->dev, "using cpu clk from: %s\n",
@@ -1484,42 +1479,39 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain,
ret = dev_pm_opp_get_opp_count(&drv->pd.dev);
if (ret < 0) {
dev_err(drv->dev, "could not get OPP count\n");
- goto unlock;
+ return ret;
}
drv->num_corners = ret;
if (drv->num_corners < 2) {
dev_err(drv->dev, "need at least 2 OPPs to use CPR\n");
- ret = -EINVAL;
- goto unlock;
+ return -EINVAL;
}
drv->corners = devm_kcalloc(drv->dev, drv->num_corners,
sizeof(*drv->corners),
GFP_KERNEL);
- if (!drv->corners) {
- ret = -ENOMEM;
- goto unlock;
- }
+ if (!drv->corners)
+ return -ENOMEM;
ret = cpr_corner_init(drv);
if (ret)
- goto unlock;
+ return ret;
cpr_set_loop_allowed(drv);
ret = cpr_init_parameters(drv);
if (ret)
- goto unlock;
+ return ret;
/* Configure CPR HW but keep it disabled */
ret = cpr_config(drv);
if (ret)
- goto unlock;
+ return ret;
ret = cpr_find_initial_corner(drv);
if (ret)
- goto unlock;
+ return ret;
if (acc_desc->config)
regmap_multi_reg_write(drv->tcsr, acc_desc->config,
@@ -1534,10 +1526,7 @@ static int cpr_pd_attach_dev(struct generic_pm_domain *domain,
dev_info(drv->dev, "driver initialized with %u OPPs\n",
drv->num_corners);
-unlock:
- mutex_unlock(&drv->lock);
-
- return ret;
+ return 0;
}
static int cpr_debug_info_show(struct seq_file *s, void *unused)