From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from he.sipsolutions.net ([78.46.109.217]:32896 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092Ab3ARWbZ (ORCPT ); Fri, 18 Jan 2013 17:31:25 -0500 From: Johannes Berg To: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , johannes@sipsolutions.net, Johannes Berg Subject: [PATCH] lockdep: make lockdep_assert_held() not have a return value Date: Fri, 18 Jan 2013 23:31:43 +0100 Message-Id: <1358548303-21732-1-git-send-email-johannes@sipsolutions.net> (sfid-20130118_233141_400276_7DF3E9E5) Sender: linux-wireless-owner@vger.kernel.org List-ID: From: Johannes Berg 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 --- 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