* [PATCH] lockdep: make lockdep_assert_held() not have a return value
@ 2013-01-18 22:31 Johannes Berg
2013-01-23 21:22 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2013-01-18 22:31 UTC (permalink / raw)
To: linux-wireless, linux-kernel
Cc: Peter Zijlstra, Ingo Molnar, johannes, Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
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>
---
include/linux/lockdep.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 00e4637..6d2fba2 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -359,7 +359,9 @@ extern void lockdep_trace_alloc(gfp_t mask);
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
-#define lockdep_assert_held(l) WARN_ON(debug_locks && !lockdep_is_held(l))
+#define lockdep_assert_held(l) do { \
+ WARN_ON(debug_locks && !lockdep_is_held(l)); \
+ } while (0)
#define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
--
1.8.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lockdep: make lockdep_assert_held() not have a return value
2013-01-18 22:31 [PATCH] lockdep: make lockdep_assert_held() not have a return value Johannes Berg
@ 2013-01-23 21:22 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2013-01-23 21:22 UTC (permalink / raw)
To: Johannes Berg
Cc: linux-wireless, linux-kernel, Peter Zijlstra, Ingo Molnar, Johannes Berg
On Fri, 18 Jan 2013 23:31:43 +0100
Johannes Berg <johannes@sipsolutions.net> wrote:
> From: Johannes Berg <johannes.berg@intel.com>
>
> 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.
>
> ...
>
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -359,7 +359,9 @@ extern void lockdep_trace_alloc(gfp_t mask);
>
> #define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
>
> -#define lockdep_assert_held(l) WARN_ON(debug_locks && !lockdep_is_held(l))
> +#define lockdep_assert_held(l) do { \
> + WARN_ON(debug_locks && !lockdep_is_held(l)); \
> + } while (0)
>
> #define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
A sane fix would be to convert lockdep_assert_held() into a static
inline void C function. But, alas, much of the lockdep API is designed
to work on "any type which has a field called dep_map", which was
rather a silly stunt IMO.
lockdep_depth() and lockdep_assert_held() may or may not evaluate their
argument, and this is runtime controllable. whee.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-01-23 21:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-18 22:31 [PATCH] lockdep: make lockdep_assert_held() not have a return value Johannes Berg
2013-01-23 21:22 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.