Skip to content

Commit f8cfa46

Browse files
shuahkhIngo Molnar
authored andcommitted
lockdep: Add lockdep lock state defines
Adds defines for lock state returns from lock_is_held_type() based on Johannes Berg's suggestions as it make it easier to read and maintain the lock states. These are defines and a enum to avoid changes to lock_is_held_type() and lockdep_is_held() return types. Updates to lock_is_held_type() and __lock_is_held() to use the new defines. Signed-off-by: Shuah Khan <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/linux-wireless/[email protected]/
1 parent 3e31f94 commit f8cfa46

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

include/linux/lockdep.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
268268

269269
extern void lock_release(struct lockdep_map *lock, unsigned long ip);
270270

271+
/* lock_is_held_type() returns */
272+
#define LOCK_STATE_UNKNOWN -1
273+
#define LOCK_STATE_NOT_HELD 0
274+
#define LOCK_STATE_HELD 1
275+
271276
/*
272277
* Same "read" as for lock_acquire(), except -1 means any.
273278
*/
@@ -302,11 +307,13 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
302307
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
303308

304309
#define lockdep_assert_held(l) do { \
305-
WARN_ON(debug_locks && lockdep_is_held(l) == 0); \
310+
WARN_ON(debug_locks && \
311+
lockdep_is_held(l) == LOCK_STATE_NOT_HELD); \
306312
} while (0)
307313

308314
#define lockdep_assert_not_held(l) do { \
309-
WARN_ON(debug_locks && lockdep_is_held(l) == 1); \
315+
WARN_ON(debug_locks && \
316+
lockdep_is_held(l) == LOCK_STATE_HELD); \
310317
} while (0)
311318

312319
#define lockdep_assert_held_write(l) do { \

kernel/locking/lockdep.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <linux/nmi.h>
5555
#include <linux/rcupdate.h>
5656
#include <linux/kprobes.h>
57+
#include <linux/lockdep.h>
5758

5859
#include <asm/sections.h>
5960

@@ -5252,13 +5253,13 @@ int __lock_is_held(const struct lockdep_map *lock, int read)
52525253

52535254
if (match_held_lock(hlock, lock)) {
52545255
if (read == -1 || hlock->read == read)
5255-
return 1;
5256+
return LOCK_STATE_HELD;
52565257

5257-
return 0;
5258+
return LOCK_STATE_NOT_HELD;
52585259
}
52595260
}
52605261

5261-
return 0;
5262+
return LOCK_STATE_NOT_HELD;
52625263
}
52635264

52645265
static struct pin_cookie __lock_pin_lock(struct lockdep_map *lock)
@@ -5537,14 +5538,14 @@ EXPORT_SYMBOL_GPL(lock_release);
55375538
noinstr int lock_is_held_type(const struct lockdep_map *lock, int read)
55385539
{
55395540
unsigned long flags;
5540-
int ret = 0;
5541+
int ret = LOCK_STATE_NOT_HELD;
55415542

55425543
/*
55435544
* Avoid false negative lockdep_assert_held() and
55445545
* lockdep_assert_not_held().
55455546
*/
55465547
if (unlikely(!lockdep_enabled()))
5547-
return -1;
5548+
return LOCK_STATE_UNKNOWN;
55485549

55495550
raw_local_irq_save(flags);
55505551
check_flags(flags);

0 commit comments

Comments
 (0)