public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Johannes Berg <johannes.berg@intel.com>
Subject: Re: [PATCH] lockdep: make lockdep_assert_held() not have a return value
Date: Wed, 23 Jan 2013 13:22:59 -0800	[thread overview]
Message-ID: <20130123132259.27dcbace.akpm@linux-foundation.org> (raw)
In-Reply-To: <1358548303-21732-1-git-send-email-johannes@sipsolutions.net>

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.

      reply	other threads:[~2013-01-23 21:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130123132259.27dcbace.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox