From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Bartosz Golaszewski <brgl@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Abel Vesa <abelvesa@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: [PATCH v4 4/4] firmware: qcom: scm: introduce qcom_scm_bw class for bandwidth management
Date: Mon, 02 Nov 2026 11:18:55 +0100 [thread overview]
Message-ID: <20261102-qcom-scm-code-shrink-v4-4-21fdbe876883@oss.qualcomm.com> (raw)
In-Reply-To: <20261102-qcom-scm-code-shrink-v4-0-21fdbe876883@oss.qualcomm.com>
Define DEFINE_CLASS(qcom_scm_bw) that calls qcom_scm_bw_enable() on
construction and automatically calls qcom_scm_bw_disable() at scope exit
*if* the enable succeeded.
This allows us to convert all call sites to using
CLASS(qcom_scm_bw, bw)() instead of the manual enable/check/disable
pattern and to remove the associated goto labels in cleanup path.
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Reviewed-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/firmware/qcom/qcom_scm.c | 67 ++++++++++++++++------------------------
1 file changed, 27 insertions(+), 40 deletions(-)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index 28fb80a8496fe9a613228d4fe3acab9de2637634..73f8868c7bffa2a7149110c8b201d5e3c5c3c807 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -244,6 +244,9 @@ static void qcom_scm_bw_disable(void)
mutex_unlock(&__scm->scm_bw_lock);
}
+DEFINE_CLASS(qcom_scm_bw_guard, int, if (!_T) qcom_scm_bw_disable(),
+ qcom_scm_bw_enable(), void)
+
enum qcom_scm_convention qcom_scm_convention = SMC_CONVENTION_UNKNOWN;
static DEFINE_SPINLOCK(scm_query_lock);
@@ -594,14 +597,13 @@ static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
if (clk_guard)
return clk_guard;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw_guard, bw_guard)();
+ if (bw_guard)
+ return bw_guard;
desc.args[1] = mdata_phys;
ret = qcom_scm_call(dev, &desc, res);
- qcom_scm_bw_disable();
return ret;
}
@@ -701,12 +703,11 @@ static int qcom_scm_pas_mem_setup(struct device *dev, u32 pas_id,
if (clk_guard)
return clk_guard;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw_guard, bw_guard)();
+ if (bw_guard)
+ return bw_guard;
ret = qcom_scm_call(dev, &desc, &res);
- qcom_scm_bw_disable();
return ret ? : res.result[0];
}
@@ -770,15 +771,14 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
struct resource_table empty_rsc = {};
size_t size = SZ_16K;
void *tbl_ptr;
- int ret;
CLASS(qcom_scm_clk_guard, clk_guard)();
if (clk_guard)
return ERR_PTR(clk_guard);
- ret = qcom_scm_bw_enable();
- if (ret)
- return ERR_PTR(ret);
+ CLASS(qcom_scm_bw_guard, bw_guard)();
+ if (bw_guard)
+ return ERR_PTR(bw_guard);
/*
* TrustZone can not accept buffer as NULL value as argument hence,
@@ -793,10 +793,8 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
void *input_rt_tzm __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool,
input_rt_size,
GFP_KERNEL);
- if (!input_rt_tzm) {
- ret = -ENOMEM;
- goto disable_scm_bw;
- }
+ if (!input_rt_tzm)
+ return ERR_PTR(-ENOMEM);
memcpy(input_rt_tzm, input_rt, input_rt_size);
@@ -811,31 +809,22 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
input_rt_size,
&size);
}
- if (IS_ERR(output_rt_tzm)) {
- ret = PTR_ERR(output_rt_tzm);
- goto disable_scm_bw;
- }
+ if (IS_ERR(output_rt_tzm))
+ return output_rt_tzm;
*output_rt_size = size;
/* A zero-sized table means that TrustZone has no resource table. */
- if (!size) {
- tbl_ptr = NULL;
- goto disable_scm_bw;
- }
+ if (!size)
+ return NULL;
tbl_ptr = kmemdup(output_rt_tzm, size, GFP_KERNEL);
- if (!tbl_ptr) {
- ret = -ENOMEM;
- goto disable_scm_bw;
- }
+ if (!tbl_ptr)
+ return ERR_PTR(-ENOMEM);
*output_rt_size = size;
-disable_scm_bw:
- qcom_scm_bw_disable();
-
- return ret ? ERR_PTR(ret) : tbl_ptr;
+ return tbl_ptr;
}
static int qcom_scm_pas_auth_and_reset(struct device *dev, u32 pas_id)
@@ -854,12 +843,11 @@ static int qcom_scm_pas_auth_and_reset(struct device *dev, u32 pas_id)
if (clk_guard)
return clk_guard;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw_guard, bw_guard)();
+ if (bw_guard)
+ return bw_guard;
ret = qcom_scm_call(dev, &desc, &res);
- qcom_scm_bw_disable();
return ret ? : res.result[0];
}
@@ -927,12 +915,11 @@ static int qcom_scm_pas_shutdown(struct device *dev, u32 pas_id)
if (clk_guard)
return clk_guard;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw_guard, bw_guard)();
+ if (bw_guard)
+ return bw_guard;
ret = qcom_scm_call(dev, &desc, &res);
- qcom_scm_bw_disable();
return ret ? : res.result[0];
}
--
2.47.3
prev parent reply other threads:[~2026-11-02 10:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 10:18 [PATCH v4 0/4] firmware: qcom: scm: simplify code by using classes Bartosz Golaszewski
2026-11-02 10:18 ` [PATCH v4 1/4] firmware: qcom: tzmem: guard against IS_ERR() in the cleanup handler Bartosz Golaszewski
2026-11-02 10:18 ` [PATCH v4 2/4] firmware: qcom: scm: use __free(qcom_tzmem) to simplify cleanup Bartosz Golaszewski
2026-11-02 10:18 ` [PATCH v4 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management Bartosz Golaszewski
2026-11-02 10:18 ` Bartosz Golaszewski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102-qcom-scm-code-shrink-v4-4-21fdbe876883@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--cc=abelvesa@kernel.org \
--cc=andersson@kernel.org \
--cc=brgl@kernel.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mukesh.ojha@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®