Skip to content

Commit b1ae345

Browse files
jmberg-inteltorvalds
authored andcommitted
lockdep: make lockdep_assert_held() not have a return value
I recently made the mistake of writing: foo = lockdep_dereference_protected(..., lockdep_assert_held(...)); which is clearly bogus. If lockdep is disabled in the config this would cause a compile failure, if it is enabled then it compiles and causes a puzzling warning about dereferencing without the correct protection. Wrap the macro in "do { ... } while (0)" to also fail compile for this when lockdep is enabled. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3278bb7 commit b1ae345

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎include/linux/lockdep.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ extern void lockdep_trace_alloc(gfp_t mask);
359359

360360
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
361361

362-
#define lockdep_assert_held(l) WARN_ON(debug_locks && !lockdep_is_held(l))
362+
#define lockdep_assert_held(l) do { \
363+
WARN_ON(debug_locks && !lockdep_is_held(l)); \
364+
} while (0)
363365

364366
#define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
365367

0 commit comments

Comments
 (0)