lkml.org 
[lkml]   [2020]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/3] mutex: Add missing annotations
Date
Sparse reports false warnings and hide real warnings
where mutex_lock() and mutex_unlock() are used within the kernel
An example is within the kernel cgroup files
where the below warnings are found
|warning: context imbalance in cgroup_lock_and_drain_offline()
| - wrong count at exit
|warning: context imbalance in cgroup_procs_write_finish()
|- wrong count at exit
|warning: context imbalance in cgroup_procs_write_start()
|- wrong count at exit.

To fix these,
an __acquires(lock) is added to mutex_lock() declaration
a __releases(lock) to mutex_unlock() declaration

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
include/linux/mutex.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index aca8f36dfac9..a8ab4029913e 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -162,7 +162,7 @@ do { \
} while (0)

#else
-extern void mutex_lock(struct mutex *lock);
+extern void mutex_lock(struct mutex *lock) __acquires(lock);
extern int __must_check mutex_lock_interruptible(struct mutex *lock);
extern int __must_check mutex_lock_killable(struct mutex *lock);
extern void mutex_lock_io(struct mutex *lock);
@@ -181,7 +181,7 @@ extern void mutex_lock_io(struct mutex *lock);
* Returns 1 if the mutex has been acquired successfully, and 0 on contention.
*/
extern int mutex_trylock(struct mutex *lock);
-extern void mutex_unlock(struct mutex *lock);
+extern void mutex_unlock(struct mutex *lock) __releases(lock);

extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);

--
2.24.1
\
 
 \ /
  Last update: 2020-01-24 21:12    [W:0.049 / U:16.736 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site