From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Bartosz Golaszewski <brgl@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@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 v2 4/4] firmware: qcom: scm: introduce qcom_scm_bw class for bandwidth management
Date: Fri, 31 Jul 2026 10:00:37 +0200 [thread overview]
Message-ID: <20260731-qcom-scm-code-shrink-v2-4-4ba76096915f@oss.qualcomm.com> (raw)
In-Reply-To: <20260731-qcom-scm-code-shrink-v2-0-4ba76096915f@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 | 61 ++++++++++++++++------------------------
1 file changed, 25 insertions(+), 36 deletions(-)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index bb213f64703a7adb9ce413ec00524a7d0a1d3856..512fc51fee3cc4da811bfe03ae79509af4888803 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, 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);
@@ -614,14 +617,13 @@ static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
if (clk)
return clk;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw, bw)();
+ if (bw)
+ return bw;
desc.args[1] = mdata_phys;
ret = qcom_scm_call(dev, &desc, res);
- qcom_scm_bw_disable();
return ret;
}
@@ -736,12 +738,11 @@ static int __qcom_scm_pas_mem_setup(struct device *dev, u32 pas_id,
if (clk)
return clk;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw, bw)();
+ if (bw)
+ return bw;
ret = qcom_scm_call(dev, &desc, &res);
- qcom_scm_bw_disable();
return ret ? : res.result[0];
}
@@ -812,15 +813,14 @@ static void *__qcom_scm_pas_get_rsc_table2(struct device *dev,
struct resource_table empty_rsc = {};
size_t size = SZ_16K;
void *tbl_ptr;
- int ret;
CLASS(qcom_scm_clk, clk)();
if (clk)
return ERR_PTR(clk);
- ret = qcom_scm_bw_enable();
- if (ret)
- return ERR_PTR(ret);
+ CLASS(qcom_scm_bw, bw)();
+ if (bw)
+ return ERR_PTR(bw);
/*
* TrustZone can not accept buffer as NULL value as argument hence,
@@ -835,10 +835,8 @@ static void *__qcom_scm_pas_get_rsc_table2(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);
@@ -851,23 +849,16 @@ static void *__qcom_scm_pas_get_rsc_table2(struct device *dev,
input_rt_tzm,
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;
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;
}
struct resource_table *qcom_scm_pas_get_rsc_table(struct qcom_scm_pas_context *ctx,
@@ -898,12 +889,11 @@ static int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 pas_id)
if (clk)
return clk;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw, bw)();
+ if (bw)
+ return bw;
ret = qcom_scm_call(dev, &desc, &res);
- qcom_scm_bw_disable();
return ret ? : res.result[0];
}
@@ -990,12 +980,11 @@ static int __qcom_scm_pas_shutdown(struct device *dev, u32 pas_id)
if (clk)
return clk;
- ret = qcom_scm_bw_enable();
- if (ret)
- return ret;
+ CLASS(qcom_scm_bw, bw)();
+ if (bw)
+ return bw;
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-07-31 8:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:00 [PATCH v2 0/4] firmware: qcom: scm: simplify code by using classes Bartosz Golaszewski
2026-07-31 8:00 ` [PATCH v2 1/4] firmware: qcom: tzmem: guard against IS_ERR() in the cleanup handler Bartosz Golaszewski
2026-07-31 8:00 ` [PATCH v2 2/4] firmware: qcom: scm: use __free(qcom_tzmem) to simplify cleanup Bartosz Golaszewski
2026-08-04 22:30 ` Bjorn Andersson
2026-08-10 8:36 ` Bartosz Golaszewski
2026-07-31 8:00 ` [PATCH v2 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management Bartosz Golaszewski
2026-08-04 15:35 ` Bjorn Andersson
2026-08-10 8:37 ` Bartosz Golaszewski
2026-07-31 8:00 ` 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=20260731-qcom-scm-code-shrink-v2-4-4ba76096915f@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--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®