[PATCH 6/6] typesafe: timers

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Andrew Morton <akpm@...>, <linux-kernel@...>, Jeff Garzik <jeff@...>, Tejun Heo <htejun@...>
Date: Sunday, January 20, 2008 - 5:57 am

This patch lets timer callback functions have their natural type
(ie. exactly match the data pointer type); it allows the old "unsigned
long data" type as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r 142a2cf4a8dc include/linux/timer.h
--- a/include/linux/timer.h	Sun Jan 20 19:01:56 2008 +1100
+++ b/include/linux/timer.h	Sun Jan 20 19:36:33 2008 +1100
@@ -24,11 +24,13 @@ struct timer_list {
 
 extern struct tvec_t_base_s boot_tvec_bases;
 
-#define TIMER_INITIALIZER(_function, _expires, _data) {		\
-		.function = (_function),			\
-		.expires = (_expires),				\
-		.data = (_data),				\
-		.base = &boot_tvec_bases,			\
+
+#define TIMER_INITIALIZER(_function, _expires, _data) {			\
+		.function = cast_if_type(_function, void (*)(typeof(_data)), \
+					 void (*)(unsigned long)),	\
+		.expires = (_expires),					\
+		.data = (unsigned long)(_data),				\
+		.base = &boot_tvec_bases,				\
 	}
 
 #define DEFINE_TIMER(_name, _function, _expires, _data)		\
@@ -38,9 +40,15 @@ void fastcall init_timer(struct timer_li
 void fastcall init_timer(struct timer_list * timer);
 void fastcall init_timer_deferrable(struct timer_list *timer);
 
-static inline void setup_timer(struct timer_list * timer,
-				void (*function)(unsigned long),
-				unsigned long data)
+#define setup_timer(timer, function, data)				\
+	__setup_timer((timer),						\
+		      cast_if_type(function, void (*)(typeof(data)),	\
+				   void (*)(unsigned long)),		\
+		      (unsigned long)(data))
+
+static inline void __setup_timer(struct timer_list * timer,
+				 void (*function)(unsigned long),
+				 unsigned long data)
 {
 	timer->function = function;
 	timer->data = data;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/6] RFC: Typesafe callbacks, Rusty Russell, (Sun Jan 20, 5:46 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Tejun Heo, (Sun Jan 20, 8:56 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Tejun Heo, (Sun Jan 20, 9:00 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Rusty Russell, (Sun Jan 20, 6:17 pm)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Rusty Russell, (Mon Jan 21, 7:33 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Tejun Heo, (Mon Jan 21, 8:38 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Rusty Russell, (Mon Jan 21, 7:27 pm)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Andi Kleen, (Tue Jan 22, 12:20 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Linus Torvalds, (Mon Jan 21, 7:57 pm)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Rusty Russell, (Tue Jan 22, 3:16 am)
Re: [PATCH 0/6] RFC: Typesafe callbacks, Linus Torvalds, (Tue Jan 22, 11:53 am)
[PATCH 1/6] typesafe: Convert stop_machine and callers, Rusty Russell, (Sun Jan 20, 5:47 am)
[PATCH 2/6] typesafe: kthread_create and kthread_run, Rusty Russell, (Sun Jan 20, 5:48 am)
Re: [PATCH 2/6] typesafe: kthread_create and kthread_run, Jan Engelhardt, (Sun Jan 20, 7:25 am)
Re: [PATCH 2/6] typesafe: kthread_create and kthread_run, Johannes Weiner, (Sun Jan 20, 12:24 pm)
Re: [PATCH 2/6] typesafe: kthread_create and kthread_run, Rusty Russell, (Sun Jan 20, 6:04 pm)
[PATCH 3/6] typesafe: convert kthread users, Rusty Russell, (Sun Jan 20, 5:50 am)
[PATCH 5/6] typesafe: request_irq and devm_request_irq, Rusty Russell, (Sun Jan 20, 5:54 am)
[PATCH 6/6] typesafe: timers, Rusty Russell, (Sun Jan 20, 5:57 am)