backports: backport from_timer() and timer_setup()
authorJohannes Berg <johannes.berg@intel.com>
Wed, 11 Oct 2017 13:41:56 +0000 (15:41 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 11 Oct 2017 15:00:42 +0000 (17:00 +0200)
These are needed for Kees's new timer API, and luckily
he already provided them for conversion purposes :-)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
backport/backport-include/linux/timer.h

index df560a26f77f306f7d3d9ff5b96f242e42e4533f..9824ea6bd8890cafdcea517ea6593078f0d9b0a4 100644 (file)
@@ -29,7 +29,35 @@ static inline void setup_deferrable_timer_key(struct timer_list *timer,
                                           (fn), (data));               \
        } while (0)
 #endif
+#endif
+
+#ifndef TIMER_DEFERRABLE
+#define TIMER_DEFERRABLE       1
+#endif
+
+#ifndef from_timer
+#define TIMER_DATA_TYPE          unsigned long
+#define TIMER_FUNC_TYPE          void (*)(TIMER_DATA_TYPE)
+
+static inline void timer_setup(struct timer_list *timer,
+                              void (*callback) (struct timer_list *),
+                              unsigned int flags)
+{
+#ifdef __setup_timer
+       __setup_timer(timer, (TIMER_FUNC_TYPE) callback,
+                     (TIMER_DATA_TYPE) timer, flags);
+#else
+       if (flags & TIMER_DEFERRABLE)
+               setup_deferrable_timer(timer, (TIMER_FUNC_TYPE) callback,
+                                      (TIMER_DATA_TYPE) timer);
+       else
+               setup_timer(timer, (TIMER_FUNC_TYPE) callback,
+                           (TIMER_DATA_TYPE) timer);
+#endif
+}
 
+#define from_timer(var, callback_timer, timer_fieldname) \
+       container_of(callback_timer, typeof(*var), timer_fieldname)
 #endif
 
 #endif /* _BACKPORT_TIMER_H */