[PATCH tip v4 2/5] [s]wait: Add compile time type check assertion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux