linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel: locking: add releases(lock) annotation
@ 2019-12-16 15:39 Jules Irenge
  2019-12-17  9:13 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Jules Irenge @ 2019-12-16 15:39 UTC (permalink / raw)
  To: boqun.feng; +Cc: peterz, mingo, will, linux-kernel, Jules Irenge

Add releases(lock) annotation to remove issue detected by sparse tool.
warning: context imbalance in xxxxxxx() - unexpected unlock

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
 kernel/locking/spinlock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c
index 0ff08380f531..bb088fcf2be5 100644
--- a/kernel/locking/spinlock.c
+++ b/kernel/locking/spinlock.c
@@ -187,6 +187,7 @@ EXPORT_SYMBOL(_raw_spin_unlock);
 
 #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
 void __lockfunc _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
+	__releases(lock)
 {
 	__raw_spin_unlock_irqrestore(lock, flags);
 }
@@ -203,6 +204,7 @@ EXPORT_SYMBOL(_raw_spin_unlock_irq);
 
 #ifndef CONFIG_INLINE_SPIN_UNLOCK_BH
 void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock)
+	__releases(lock)
 {
 	__raw_spin_unlock_bh(lock);
 }
@@ -275,6 +277,7 @@ EXPORT_SYMBOL(_raw_read_unlock_irq);
 
 #ifndef CONFIG_INLINE_READ_UNLOCK_BH
 void __lockfunc _raw_read_unlock_bh(rwlock_t *lock)
+	__releases(lock)
 {
 	__raw_read_unlock_bh(lock);
 }
@@ -331,6 +334,7 @@ EXPORT_SYMBOL(_raw_write_unlock);
 
 #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
 void __lockfunc _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
+	__releases(lock)
 {
 	__raw_write_unlock_irqrestore(lock, flags);
 }
@@ -347,6 +351,7 @@ EXPORT_SYMBOL(_raw_write_unlock_irq);
 
 #ifndef CONFIG_INLINE_WRITE_UNLOCK_BH
 void __lockfunc _raw_write_unlock_bh(rwlock_t *lock)
+	__releases(lock)
 {
 	__raw_write_unlock_bh(lock);
 }
-- 
2.23.0


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

* Re: [PATCH] kernel: locking: add releases(lock) annotation
  2019-12-16 15:39 [PATCH] kernel: locking: add releases(lock) annotation Jules Irenge
@ 2019-12-17  9:13 ` Peter Zijlstra
  2020-02-06 14:59   ` Jules Irenge
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2019-12-17  9:13 UTC (permalink / raw)
  To: Jules Irenge; +Cc: boqun.feng, mingo, will, linux-kernel

On Mon, Dec 16, 2019 at 03:39:52PM +0000, Jules Irenge wrote:
> Add releases(lock) annotation to remove issue detected by sparse tool.
> warning: context imbalance in xxxxxxx() - unexpected unlock
> 
> Signed-off-by: Jules Irenge <jbi.octave@gmail.com>

So, personally I detest these sparse things.

But I'm also confused, as that function already has the annotation, see
spinlock_api_smp.h. In order for sparse to see these annotations at the
usage size, they need to be on the declaration, not the definition.

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

* Re: [PATCH] kernel: locking: add releases(lock) annotation
  2019-12-17  9:13 ` Peter Zijlstra
@ 2020-02-06 14:59   ` Jules Irenge
  0 siblings, 0 replies; 3+ messages in thread
From: Jules Irenge @ 2020-02-06 14:59 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Jules Irenge, boqun.feng, mingo, will, linux-kernel



On Tue, 17 Dec 2019, Peter Zijlstra wrote:

> On Mon, Dec 16, 2019 at 03:39:52PM +0000, Jules Irenge wrote:
> > Add releases(lock) annotation to remove issue detected by sparse tool.
> > warning: context imbalance in xxxxxxx() - unexpected unlock
> > 
> > Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> 
> So, personally I detest these sparse things.
> 
> But I'm also confused, as that function already has the annotation, see
> spinlock_api_smp.h. In order for sparse to see these annotations at the
> usage size, they need to be on the declaration, not the definition.
> 

Yes, I completely agree with you, but acording to my short experience 
with Sparse, the warning at function definition will always be there 
despite the annotation being at the function declaration.

The annotation at declaration help fix the warning when the anotated 
function is called within another function, this function can be 
elsewhere. It fixes the warning at the function within which the 
annotated function has been called.

Please correct me if I am wrong.

Kind regards,
Jules

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

end of thread, other threads:[~2020-02-06 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-16 15:39 [PATCH] kernel: locking: add releases(lock) annotation Jules Irenge
2019-12-17  9:13 ` Peter Zijlstra
2020-02-06 14:59   ` Jules Irenge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).