mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/3] firmware: qcom: uefisecapp: Simplify mutex with guard
@ 2026-02-15 11:05 Krzysztof Kozlowski
  2026-02-15 11:05 ` [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse Krzysztof Kozlowski
  2026-02-15 11:05 ` [PATCH 3/3] firmware: qcom: scom: Simplify mutex with guard Krzysztof Kozlowski
  0 siblings, 2 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-15 11:05 UTC (permalink / raw)
  To: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel
  Cc: Krzysztof Kozlowski

Simplify error path unlocking mutex with the guard.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_qseecom_uefisecapp.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
index 98a463e9774b..21be447374aa 100644
--- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
+++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
@@ -699,16 +699,13 @@ static DEFINE_MUTEX(__qcuefi_lock);
 
 static int qcuefi_set_reference(struct qcuefi_client *qcuefi)
 {
-	mutex_lock(&__qcuefi_lock);
+	guard(mutex)(&__qcuefi_lock);
 
-	if (qcuefi && __qcuefi) {
-		mutex_unlock(&__qcuefi_lock);
+	if (qcuefi && __qcuefi)
 		return -EEXIST;
-	}
 
 	__qcuefi = qcuefi;
 
-	mutex_unlock(&__qcuefi_lock);
 	return 0;
 }
 
-- 
2.51.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse
  2026-02-15 11:05 [PATCH 1/3] firmware: qcom: uefisecapp: Simplify mutex with guard Krzysztof Kozlowski
@ 2026-02-15 11:05 ` Krzysztof Kozlowski
  2026-02-16  8:00   ` Johan Hovold
  2026-02-15 11:05 ` [PATCH 3/3] firmware: qcom: scom: Simplify mutex with guard Krzysztof Kozlowski
  1 sibling, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-15 11:05 UTC (permalink / raw)
  To: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel
  Cc: Krzysztof Kozlowski

qcuefi_acquire() and qcuefi_release() end with mutex locked or unlocked
respectively, so annotate them so the lock usage will be tracked by
sparse.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_qseecom_uefisecapp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
index 21be447374aa..befa68d1dcaf 100644
--- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
+++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
@@ -710,6 +710,7 @@ static int qcuefi_set_reference(struct qcuefi_client *qcuefi)
 }
 
 static struct qcuefi_client *qcuefi_acquire(void)
+	__acquires(__qcuefi_lock)
 {
 	mutex_lock(&__qcuefi_lock);
 	if (!__qcuefi) {
@@ -720,6 +721,7 @@ static struct qcuefi_client *qcuefi_acquire(void)
 }
 
 static void qcuefi_release(void)
+	__releases(__qcuefi_lock)
 {
 	mutex_unlock(&__qcuefi_lock);
 }
-- 
2.51.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] firmware: qcom: scom: Simplify mutex with guard
  2026-02-15 11:05 [PATCH 1/3] firmware: qcom: uefisecapp: Simplify mutex with guard Krzysztof Kozlowski
  2026-02-15 11:05 ` [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse Krzysztof Kozlowski
@ 2026-02-15 11:05 ` Krzysztof Kozlowski
  1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-15 11:05 UTC (permalink / raw)
  To: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel
  Cc: Krzysztof Kozlowski

Simplify error path unlocking mutex with the guard.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_scm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index 8fbc96693a55..f1947025d8b5 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -199,19 +199,18 @@ static int qcom_scm_bw_enable(void)
 	if (!__scm->path)
 		return 0;
 
-	mutex_lock(&__scm->scm_bw_lock);
+	guard(mutex)(&__scm->scm_bw_lock);
+
 	if (!__scm->scm_vote_count) {
 		ret = icc_set_bw(__scm->path, 0, UINT_MAX);
 		if (ret < 0) {
 			dev_err(__scm->dev, "failed to set bandwidth request\n");
-			goto err_bw;
+			return ret;
 		}
 	}
 	__scm->scm_vote_count++;
-err_bw:
-	mutex_unlock(&__scm->scm_bw_lock);
 
-	return ret;
+	return 0;
 }
 
 static void qcom_scm_bw_disable(void)
-- 
2.51.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse
  2026-02-15 11:05 ` [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse Krzysztof Kozlowski
@ 2026-02-16  8:00   ` Johan Hovold
  2026-02-16  8:14     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2026-02-16  8:00 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel

On Sun, Feb 15, 2026 at 12:05:50PM +0100, Krzysztof Kozlowski wrote:
> qcuefi_acquire() and qcuefi_release() end with mutex locked or unlocked
> respectively, so annotate them so the lock usage will be tracked by
> sparse.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>  drivers/firmware/qcom/qcom_qseecom_uefisecapp.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
> index 21be447374aa..befa68d1dcaf 100644
> --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
> +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
> @@ -710,6 +710,7 @@ static int qcuefi_set_reference(struct qcuefi_client *qcuefi)
>  }
>  
>  static struct qcuefi_client *qcuefi_acquire(void)
> +	__acquires(__qcuefi_lock)
>  {
>  	mutex_lock(&__qcuefi_lock);
>  	if (!__qcuefi) {
> @@ -720,6 +721,7 @@ static struct qcuefi_client *qcuefi_acquire(void)
>  }
>  
>  static void qcuefi_release(void)
> +	__releases(__qcuefi_lock)
>  {
>  	mutex_unlock(&__qcuefi_lock);
>  }

The mutex implementation does not use sparse annotation so this actually
introduces sparse warnings (unless something changed very recently).

See 
	
	https://lore.kernel.org/all/ZJ11H8btBhvCx9gD@hovoldconsulting.com/

for what his looks like for the code in question.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse
  2026-02-16  8:00   ` Johan Hovold
@ 2026-02-16  8:14     ` Krzysztof Kozlowski
  2026-02-16  8:20       ` Johan Hovold
  0 siblings, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-16  8:14 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel

On 16/02/2026 09:00, Johan Hovold wrote:
> On Sun, Feb 15, 2026 at 12:05:50PM +0100, Krzysztof Kozlowski wrote:
>> qcuefi_acquire() and qcuefi_release() end with mutex locked or unlocked
>> respectively, so annotate them so the lock usage will be tracked by
>> sparse.
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
>> ---
>>  drivers/firmware/qcom/qcom_qseecom_uefisecapp.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
>> index 21be447374aa..befa68d1dcaf 100644
>> --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
>> +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
>> @@ -710,6 +710,7 @@ static int qcuefi_set_reference(struct qcuefi_client *qcuefi)
>>  }
>>  
>>  static struct qcuefi_client *qcuefi_acquire(void)
>> +	__acquires(__qcuefi_lock)
>>  {
>>  	mutex_lock(&__qcuefi_lock);
>>  	if (!__qcuefi) {
>> @@ -720,6 +721,7 @@ static struct qcuefi_client *qcuefi_acquire(void)
>>  }
>>  
>>  static void qcuefi_release(void)
>> +	__releases(__qcuefi_lock)
>>  {
>>  	mutex_unlock(&__qcuefi_lock);
>>  }
> 
> The mutex implementation does not use sparse annotation so this actually
> introduces sparse warnings (unless something changed very recently).
> 
> See 
> 	
> 	https://lore.kernel.org/all/ZJ11H8btBhvCx9gD@hovoldconsulting.com/
> 
> for what his looks like for the code in question.
> 

I checked with sparse and there were no warnings. More importantly,
mutex uses __acquires, so this apparently changed:

https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mutex.h#n214

Also clang v22 has context tracking, which I should probably mention as
well, and it supports mutex:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/dev-tools/context-analysis.rst

(this I could not test, too old LLVM, I need to set up containerized builds)

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse
  2026-02-16  8:14     ` Krzysztof Kozlowski
@ 2026-02-16  8:20       ` Johan Hovold
  2026-02-16  8:27         ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2026-02-16  8:20 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel

On Mon, Feb 16, 2026 at 09:14:13AM +0100, Krzysztof Kozlowski wrote:
> On 16/02/2026 09:00, Johan Hovold wrote:
> > On Sun, Feb 15, 2026 at 12:05:50PM +0100, Krzysztof Kozlowski wrote:
> >> qcuefi_acquire() and qcuefi_release() end with mutex locked or unlocked
> >> respectively, so annotate them so the lock usage will be tracked by
> >> sparse.

> > The mutex implementation does not use sparse annotation so this actually
> > introduces sparse warnings (unless something changed very recently).
> > 
> > See 
> > 	
> > 	https://lore.kernel.org/all/ZJ11H8btBhvCx9gD@hovoldconsulting.com/
> > 
> > for what his looks like for the code in question.
> 
> I checked with sparse and there were no warnings. More importantly,
> mutex uses __acquires, so this apparently changed:
> 
> https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mutex.h#n214

Thanks for checking. This is apparently about to change for v7.0-rc1:

	370f0a345a70 ("locking/mutex: Support Clang's context analysis")

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse
  2026-02-16  8:20       ` Johan Hovold
@ 2026-02-16  8:27         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-16  8:27 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	linux-kernel

On 16/02/2026 09:20, Johan Hovold wrote:
> On Mon, Feb 16, 2026 at 09:14:13AM +0100, Krzysztof Kozlowski wrote:
>> On 16/02/2026 09:00, Johan Hovold wrote:
>>> On Sun, Feb 15, 2026 at 12:05:50PM +0100, Krzysztof Kozlowski wrote:
>>>> qcuefi_acquire() and qcuefi_release() end with mutex locked or unlocked
>>>> respectively, so annotate them so the lock usage will be tracked by
>>>> sparse.
> 
>>> The mutex implementation does not use sparse annotation so this actually
>>> introduces sparse warnings (unless something changed very recently).
>>>
>>> See 
>>> 	
>>> 	https://lore.kernel.org/all/ZJ11H8btBhvCx9gD@hovoldconsulting.com/
>>>
>>> for what his looks like for the code in question.
>>
>> I checked with sparse and there were no warnings. More importantly,
>> mutex uses __acquires, so this apparently changed:
>>
>> https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mutex.h#n214
> 
> Thanks for checking. This is apparently about to change for v7.0-rc1:
> 
> 	370f0a345a70 ("locking/mutex: Support Clang's context analysis")

Yeah. I will include note about this in the commit msg.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-02-16  8:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-15 11:05 [PATCH 1/3] firmware: qcom: uefisecapp: Simplify mutex with guard Krzysztof Kozlowski
2026-02-15 11:05 ` [PATCH 2/3] firmware: qcom: uefisecapp: Annotate acquiring locks for sparse Krzysztof Kozlowski
2026-02-16  8:00   ` Johan Hovold
2026-02-16  8:14     ` Krzysztof Kozlowski
2026-02-16  8:20       ` Johan Hovold
2026-02-16  8:27         ` Krzysztof Kozlowski
2026-02-15 11:05 ` [PATCH 3/3] firmware: qcom: scom: Simplify mutex with guard Krzysztof Kozlowski

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®