timer: Pass function down to initialization routines
authorKees Cook <keescook@chromium.org>
Mon, 23 Oct 2017 01:14:46 +0000 (18:14 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 21 Nov 2017 23:57:14 +0000 (15:57 -0800)
In preparation for removing more macros, pass the function down to the
initialization routines instead of doing it in macros.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/timer.h
kernel/time/timer.c

index e6bab51db13d6c20a09a4a0d30f8f97c2094194a..aff73b1c8f7be441197d1addc3accb87ff143c97 100644 (file)
@@ -78,53 +78,56 @@ struct timer_list {
        struct timer_list _name =                               \
                __TIMER_INITIALIZER((TIMER_FUNC_TYPE)_function, 0)
 
-void init_timer_key(struct timer_list *timer, unsigned int flags,
+void init_timer_key(struct timer_list *timer,
+                   void (*func)(struct timer_list *), unsigned int flags,
                    const char *name, struct lock_class_key *key);
 
 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
 extern void init_timer_on_stack_key(struct timer_list *timer,
+                                   void (*func)(struct timer_list *),
                                    unsigned int flags, const char *name,
                                    struct lock_class_key *key);
 extern void destroy_timer_on_stack(struct timer_list *timer);
 #else
 static inline void destroy_timer_on_stack(struct timer_list *timer) { }
 static inline void init_timer_on_stack_key(struct timer_list *timer,
-                                          unsigned int flags, const char *name,
+                                          void (*func)(struct timer_list *),
+                                          unsigned int flags,
+                                          const char *name,
                                           struct lock_class_key *key)
 {
-       init_timer_key(timer, flags, name, key);
+       init_timer_key(timer, func, flags, name, key);
 }
 #endif
 
 #ifdef CONFIG_LOCKDEP
-#define __init_timer(_timer, _flags)                                   \
+#define __init_timer(_timer, _fn, _flags)                              \
        do {                                                            \
                static struct lock_class_key __key;                     \
-               init_timer_key((_timer), (_flags), #_timer, &__key);    \
+               init_timer_key((_timer), (_fn), (_flags), #_timer, &__key);\
        } while (0)
 
-#define __init_timer_on_stack(_timer, _flags)                          \
+#define __init_timer_on_stack(_timer, _fn, _flags)                     \
        do {                                                            \
                static struct lock_class_key __key;                     \
-               init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \
+               init_timer_on_stack_key((_timer), (_fn), (_flags),      \
+                                       #_timer, &__key);                \
        } while (0)
 #else
-#define __init_timer(_timer, _flags)                                   \
-       init_timer_key((_timer), (_flags), NULL, NULL)
-#define __init_timer_on_stack(_timer, _flags)                          \
-       init_timer_on_stack_key((_timer), (_flags), NULL, NULL)
+#define __init_timer(_timer, _fn, _flags)                              \
+       init_timer_key((_timer), (_fn), (_flags), NULL, NULL)
+#define __init_timer_on_stack(_timer, _fn, _flags)                     \
+       init_timer_on_stack_key((_timer), (_fn), (_flags), NULL, NULL)
 #endif
 
 #define __setup_timer(_timer, _fn, _flags)                             \
        do {                                                            \
-               __init_timer((_timer), (_flags));                       \
-               (_timer)->function = (_fn);                             \
+               __init_timer((_timer), (_fn), (_flags));                \
        } while (0)
 
 #define __setup_timer_on_stack(_timer, _fn, _flags)                    \
        do {                                                            \
-               __init_timer_on_stack((_timer), (_flags));              \
-               (_timer)->function = (_fn);                             \
+               __init_timer_on_stack((_timer), (_fn), (_flags));       \
        } while (0)
 
 #ifndef CONFIG_LOCKDEP
index 0f0d49a02d042dbf75c6d72e54a78b8cfd633a82..ffebcf878fba5d5cf67f5e9abcece25c16259919 100644 (file)
@@ -707,14 +707,18 @@ static inline void debug_timer_assert_init(struct timer_list *timer)
        debug_object_assert_init(timer, &timer_debug_descr);
 }
 
-static void do_init_timer(struct timer_list *timer, unsigned int flags,
+static void do_init_timer(struct timer_list *timer,
+                         void (*func)(struct timer_list *),
+                         unsigned int flags,
                          const char *name, struct lock_class_key *key);
 
-void init_timer_on_stack_key(struct timer_list *timer, unsigned int flags,
+void init_timer_on_stack_key(struct timer_list *timer,
+                            void (*func)(struct timer_list *),
+                            unsigned int flags,
                             const char *name, struct lock_class_key *key)
 {
        debug_object_init_on_stack(timer, &timer_debug_descr);
-       do_init_timer(timer, flags, name, key);
+       do_init_timer(timer, func, flags, name, key);
 }
 EXPORT_SYMBOL_GPL(init_timer_on_stack_key);
 
@@ -755,10 +759,13 @@ static inline void debug_assert_init(struct timer_list *timer)
        debug_timer_assert_init(timer);
 }
 
-static void do_init_timer(struct timer_list *timer, unsigned int flags,
+static void do_init_timer(struct timer_list *timer,
+                         void (*func)(struct timer_list *),
+                         unsigned int flags,
                          const char *name, struct lock_class_key *key)
 {
        timer->entry.pprev = NULL;
+       timer->function = func;
        timer->flags = flags | raw_smp_processor_id();
        lockdep_init_map(&timer->lockdep_map, name, key, 0);
 }
@@ -766,6 +773,7 @@ static void do_init_timer(struct timer_list *timer, unsigned int flags,
 /**
  * init_timer_key - initialize a timer
  * @timer: the timer to be initialized
+ * @func: timer callback function
  * @flags: timer flags
  * @name: name of the timer
  * @key: lockdep class key of the fake lock used for tracking timer
@@ -774,11 +782,12 @@ static void do_init_timer(struct timer_list *timer, unsigned int flags,
  * init_timer_key() must be done to a timer prior calling *any* of the
  * other timer functions.
  */
-void init_timer_key(struct timer_list *timer, unsigned int flags,
+void init_timer_key(struct timer_list *timer,
+                   void (*func)(struct timer_list *), unsigned int flags,
                    const char *name, struct lock_class_key *key)
 {
        debug_init(timer);
-       do_init_timer(timer, flags, name, key);
+       do_init_timer(timer, func, flags, name, key);
 }
 EXPORT_SYMBOL(init_timer_key);