Re: [PATCH v2 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management
From: Bartosz Golaszewski
Date: Mon Aug 10 2026 - 04:46:25 EST
On Tue, 4 Aug 2026 17:35:53 +0200, Bjorn Andersson <andersson@xxxxxxxxxx> said:
> On Fri, Jul 31, 2026 at 10:00:36AM +0200, Bartosz Golaszewski wrote:
>> Define DEFINE_CLASS(qcom_scm_clk) that calls qcom_scm_clk_enable() on
>> construction and automatically calls qcom_scm_clk_disable() at scope exit
>> *if* the enable succeeded.
>>
>> This allows us to convert all call sites to using
>> CLASS(qcom_scm_clk, clk)() instead of the manual enable/check/disable
>> pattern and to remove the associated goto labels.
>>
>> Reviewed-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
>> Reviewed-by: Mukesh Ojha <mukesh.ojha@xxxxxxxxxxxxxxxx>
>> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
>> ---
>> drivers/firmware/qcom/qcom_scm.c | 89 +++++++++++++++-------------------------
>> 1 file changed, 34 insertions(+), 55 deletions(-)
>>
>> diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
>> index 10c79d2e59a14af0532c515d332f65bdfea05621..bb213f64703a7adb9ce413ec00524a7d0a1d3856 100644
>> --- a/drivers/firmware/qcom/qcom_scm.c
>> +++ b/drivers/firmware/qcom/qcom_scm.c
>> @@ -209,6 +209,9 @@ static void qcom_scm_clk_disable(void)
>> clk_disable_unprepare(__scm->bus_clk);
>> }
>>
>> +DEFINE_CLASS(qcom_scm_clk, int, if (!_T) qcom_scm_clk_disable(),
>> + qcom_scm_clk_enable(), void)
>> +
>> static int qcom_scm_bw_enable(void)
>> {
>> int ret = 0;
>> @@ -509,13 +512,11 @@ static int qcom_scm_disable_sdi(void)
>> };
>> struct qcom_scm_res res;
>>
>> - ret = qcom_scm_clk_enable();
>> - if (ret)
>> - return ret;
>> + CLASS(qcom_scm_clk, clk)();
>
> No matter how many times I read this line, it doesn't tell me "clocks
> will be enabled from here to the end of the scope".
>
Would CLASS(qcom_scm_scoped_clk, clk)(); work for you? Or maybe
CLASS(qcom_scm_clk_guard, clk_guard)()?
Bart