Re: [PATCH v2 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management

Bartosz Golaszewski <[email protected]>
Newsgroups org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-kernel
Message-ID <CAMRc=MfZkmqt6w9LFca0OpyK87-oZJA8V24JiUJHSuWnrNx4kg@mail.gmail.com>
On Tue, 4 Aug 2026 17:35:53 +0200, Bjorn Andersson <[email protected]> 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 <[email protected]>
>> Reviewed-by: Mukesh Ojha <[email protected]>
>> Signed-off-by: Bartosz Golaszewski <[email protected]>
>> ---
>>  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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.