mutex subsystem, add include/asm-i386/mutex.h
In-Reply-To: <[email protected]>
Review
Quoted 8 lines · Ingo Molnar
(quoted diff) +8
-0+#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 <[email protected]>
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(-)
include/asm-arm/mutex.h +3 -9
@@ -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__ ( \
include/asm-i386/mutex.h +2 -6
@@ -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__( \
include/asm-x86_64/mutex.h +2 -6
@@ -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__( \
include/linux/mutex.h +4 -0
@@ -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
include/linux/kernel.h +9 -0
@@ -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
Signature · 1 line
Chuck
Ingo Molnar
AppliedQuoted 15 lines · Chuck Ebbert
In-Reply-To: <[email protected]>
Review
Quoted 8 lines · Ingo Molnar
(quoted diff) +8
-0+#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?
Quoted 1 line
Signed-off-by Chuck Ebbert <[email protected]>
thanks, applied.
Ingo
include/linux/mutex.h struct mutex_waiter { · line 74
Quoted 3 lines · Chuck Ebbert
include/linux/mutex.h +3
-0+/* 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 *);
i didnt apply this bit: there's not much to be won and readability suffers.
Ingo