In-Reply-To: <[email protected]>
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 <[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(-)
--- 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]