mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
To: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org
Cc: Boqun Feng <boqun.feng@gmail.com>,
	Daniel Wagner <daniel.wagner@bmw-carit.de>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH tip v4 2/5] [s]wait: Add compile time type check assertion
Date: Tue, 24 Nov 2015 14:03:04 +0100	[thread overview]
Message-ID: <1448370187-10075-3-git-send-email-daniel.wagner@bmw-carit.de> (raw)
In-Reply-To: <1448370187-10075-1-git-send-email-daniel.wagner@bmw-carit.de>

The API provided by wait.h and swait.h is very similiar. Most of the
time your are only one character away from either of it:

     wake_up() vs swake_up()

This is on purpose so that we do not have two nearly identical bits of
infrastructre code with dissimilar names.

A compile time type check assertion ensures that obvious wrong usage
is caught at early stage.

Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
 include/linux/compiler.h | 4 ++++
 include/linux/swait.h    | 2 ++
 include/linux/wait.h     | 2 ++
 3 files changed, 8 insertions(+)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index c836eb2..ac7afcb 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -455,6 +455,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 	compiletime_assert(__native_word(t),				\
 		"Need native word sized stores/loads for atomicity.")
 
+#define compiletime_assert_same_type(a, b)				\
+	compiletime_assert(__same_type(a, b),				\
+		"Need same type.");
+
 /*
  * Prevent the compiler from merging or refetching accesses.  The compiler
  * is also forbidden from reordering successive instances of ACCESS_ONCE(),
diff --git a/include/linux/swait.h b/include/linux/swait.h
index c1f9c62..80e2eb8 100644
--- a/include/linux/swait.h
+++ b/include/linux/swait.h
@@ -66,6 +66,7 @@ extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name
 #define init_swait_queue_head(q)				\
 	do {							\
 		static struct lock_class_key __key;		\
+		compiletime_assert_same_type(struct swait_queue_head *, q); \
 		__init_swait_queue_head((q), #q, &__key);	\
 	} while (0)
 
@@ -101,6 +102,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);
 	struct swait_queue __wait;					\
 	long __ret = ret;						\
 									\
+	compiletime_assert_same_type(struct swait_queue_head, wq);	\
 	INIT_LIST_HEAD(&__wait.task_list);				\
 	for (;;) {							\
 		long __int = prepare_to_swait_event(&wq, &__wait, state);\
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 1e1bf9f..bc4f829 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -75,6 +75,7 @@ extern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct
 	do {						\
 		static struct lock_class_key __key;	\
 							\
+		compiletime_assert_same_type(wait_queue_head_t *, q); \
 		__init_waitqueue_head((q), #q, &__key);	\
 	} while (0)
 
@@ -215,6 +216,7 @@ wait_queue_head_t *bit_waitqueue(void *, int);
 	wait_queue_t __wait;						\
 	long __ret = ret;	/* explicit shadow */			\
 									\
+	compiletime_assert_same_type(wait_queue_head_t, wq);		\
 	INIT_LIST_HEAD(&__wait.task_list);				\
 	if (exclusive)							\
 		__wait.flags = WQ_FLAG_EXCLUSIVE;			\
-- 
2.4.3


  parent reply	other threads:[~2015-11-24 13:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 13:03 [PATCH tip v4 0/5] Simple wait queue support Daniel Wagner
2015-11-24 13:03 ` [PATCH tip v4 1/5] wait.[ch]: Introduce the simple waitqueue (swait) implementation Daniel Wagner
2015-11-24 13:03 ` Daniel Wagner [this message]
2015-11-26 12:22   ` [PATCH tip v4 2/5] [s]wait: Add compile time type check assertion Daniel Wagner
2015-11-27 20:10     ` Thomas Gleixner
2015-11-24 13:03 ` [PATCH tip v4 3/5] KVM: use simple waitqueue for vcpu->wq Daniel Wagner
2015-11-24 13:03 ` [PATCH tip v4 4/5] rcu: Do not call rcu_nocb_gp_cleanup() while holding rnp->lock Daniel Wagner
2015-11-24 15:52   ` Boqun Feng
2015-11-25  1:01     ` Boqun Feng
2015-11-25 10:29       ` Daniel Wagner
2015-11-24 13:03 ` [PATCH tip v4 5/5] rcu: use simple wait queues where possible in rcutree Daniel Wagner

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=1448370187-10075-3-git-send-email-daniel.wagner@bmw-carit.de \
    --to=daniel.wagner@bmw-carit.de \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®