mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@osdl.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Nicolas Pitre <nico@cam.org>,
	Jes Sorensen <jes@trained-monkey.org>,
	Al Viro <viro@ftp.linux.org.uk>, Oleg Nesterov <oleg@tv-sign.ru>,
	David Howells <dhowells@redhat.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
	Russell King <rmk+lkml@arm.linux.org.uk>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [patch 03/13] mutex subsystem, add include/asm-i386/mutex.h
Date: Sat, 31 Dec 2005 01:37:17 -0500	[thread overview]
Message-ID: <200512310140_MC3-1-B501-E855@compuserve.com> (raw)

In-Reply-To: <20051229210336.GD665@elte.hu>

On Thu, 29 Dec 2005 at 22:03:36 +0100, Ingo Molnar wrote:

> +#define __mutex_fastpath_lock(count, fn_name)                                \
> +do {                                                                 \
> +     /* type-check the function too: */                              \
> +     void fastcall (*__tmp)(atomic_t *) = fn_name;                   \
> +     unsigned int dummy;                                             \
> +                                                                     \
> +     (void)__tmp;                                                    \
> +     typecheck(atomic_t *, count);                                   \

 The function type checking is ugly.  Wouldn't this be better?

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>

 include/asm-arm/mutex.h    |   12 +++---------
 include/asm-i386/mutex.h   |    8 ++------
 include/asm-x86_64/mutex.h |    8 ++------
 include/linux/kernel.h     |    9 +++++++++
 include/linux/mutex.h      |    4 ++++
 5 files changed, 20 insertions(+), 21 deletions(-)

--- 2.6.15-rc7b.orig/include/asm-arm/mutex.h
+++ 2.6.15-rc7b/include/asm-arm/mutex.h
@@ -25,11 +25,9 @@
  */
 #define __mutex_fastpath_lock(count, fail_fn)				\
 do {									\
-	/* type-check the function too: */				\
-	void fastcall (*__tmp)(atomic_t *) = fail_fn;			\
 	int __ex_flag, __res;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fail_fn);			\
 	typecheck(atomic_t *, count);					\
 									\
 	__asm__ (							\
@@ -47,11 +45,9 @@ do {									\
 
 #define __mutex_fastpath_lock_retval(count, fail_fn)			\
 ({									\
-	/* type-check the function too: */				\
-	int fastcall (*__tmp)(atomic_t *) = fail_fn;			\
 	int __ex_flag, __res;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_int_fail_fn_t, fail_fn);			\
 	typecheck(atomic_t *, count);					\
 									\
 	__asm__ (							\
@@ -76,11 +72,9 @@ do {									\
  */
 #define __mutex_fastpath_unlock(count, fail_fn)				\
 do {									\
-	/* type-check the function too: */				\
-	void fastcall (*__tmp)(atomic_t *) = fail_fn;			\
 	int __ex_flag, __res, __orig;					\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fail_fn);			\
 	typecheck(atomic_t *, count);					\
 									\
 	__asm__ (							\
--- 2.6.15-rc7b.orig/include/asm-i386/mutex.h
+++ 2.6.15-rc7b/include/asm-i386/mutex.h
@@ -21,11 +21,9 @@
  */
 #define __mutex_fastpath_lock(count, fn_name)				\
 do {									\
-	/* type-check the function too: */				\
-	void fastcall (*__tmp)(atomic_t *) = fn_name;			\
 	unsigned int dummy;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fn_name);			\
 	typecheck(atomic_t *, count);					\
 									\
 	__asm__ __volatile__(						\
@@ -79,11 +77,9 @@ __mutex_fastpath_lock_retval(atomic_t *c
  */
 #define __mutex_fastpath_unlock(count, fn_name)				\
 do {									\
-	/* type-check the function too: */				\
-	void fastcall (*__tmp)(atomic_t *) = fn_name;			\
 	unsigned int dummy;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fn_name);			\
 	typecheck(atomic_t *, count);					\
 									\
 	__asm__ __volatile__(						\
--- 2.6.15-rc7b.orig/include/asm-x86_64/mutex.h
+++ 2.6.15-rc7b/include/asm-x86_64/mutex.h
@@ -18,11 +18,9 @@
  */
 #define __mutex_fastpath_lock(v, fn_name)				\
 do {									\
-	/* type-check the function too: */				\
-	fastcall void (*__tmp)(atomic_t *) = fn_name;			\
 	unsigned long dummy;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fn_name);			\
 	typecheck(atomic_t *, v);					\
 									\
 	__asm__ __volatile__(						\
@@ -50,11 +48,9 @@ do {									\
  */
 #define __mutex_fastpath_unlock(v, fn_name)				\
 do {									\
-	/* type-check the function too: */				\
-	fastcall void (*__tmp)(atomic_t *) = fn_name;			\
 	unsigned long dummy;						\
 									\
-	(void)__tmp;							\
+	typecheck_fn(mutex_void_fail_fn_t, fn_name);			\
 	typecheck(atomic_t *, v);					\
 									\
 	__asm__ __volatile__(						\
--- 2.6.15-rc7b.orig/include/linux/mutex.h
+++ 2.6.15-rc7b/include/linux/mutex.h
@@ -69,6 +69,10 @@ struct mutex_waiter {
 #endif
 };
 
+/* mutex functions called when extra work needs to be done have these types  */
+typedef void fastcall mutex_void_fail_fn_t(atomic_t *);
+typedef int fastcall mutex_int_fail_fn_t(atomic_t *);
+
 #ifdef CONFIG_DEBUG_MUTEXES
 # include <linux/mutex-debug.h>
 #else
--- 2.6.15-rc7b.orig/include/linux/kernel.h
+++ 2.6.15-rc7b/include/linux/kernel.h
@@ -286,6 +286,15 @@ extern void dump_stack(void);
 	1; \
 })
 
+/*
+ * Check at compile time that 'function' is a certain type, or is a pointer
+ * to that type (needs to use typedef for the function type.)
+ */
+#define typecheck_fn(type,function) \
+({	type *__dummy = function; \
+	(void)__dummy; \
+})
+
 #endif /* __KERNEL__ */
 
 #define SI_LOAD_SHIFT	16
-- 
Chuck

             reply	other threads:[~2005-12-31  6:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-31  6:37 Chuck Ebbert [this message]
2006-01-02 13:29 ` Ingo Molnar
2006-01-02 13:37 ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2005-12-29 21:03 Ingo Molnar

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=200512310140_MC3-1-B501-E855@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjan@infradead.org \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=jes@trained-monkey.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=nico@cam.org \
    --cc=oleg@tv-sign.ru \
    --cc=rmk+lkml@arm.linux.org.uk \
    --cc=viro@ftp.linux.org.uk \
    /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®