Skip to content

Commit

Permalink
timer: Pass timer_list pointer to callbacks unconditionally
Browse files Browse the repository at this point in the history
Now that all timer callbacks are already taking their struct timer_list
pointer as the callback argument, just do this unconditionally and remove
the .data field.

Cc: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Stephen Boyd <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed Nov 21, 2017
1 parent 9477b4a commit c1eba5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 0 additions & 4 deletions include/linux/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct timer_list {
struct hlist_node entry;
unsigned long expires;
void (*function)(unsigned long);
unsigned long data;
u32 flags;

#ifdef CONFIG_LOCKDEP
Expand Down Expand Up @@ -70,7 +69,6 @@ struct timer_list {
#define __TIMER_INITIALIZER(_function, _data, _flags) { \
.entry = { .next = TIMER_ENTRY_STATIC }, \
.function = (_function), \
.data = (_data), \
.flags = (_flags), \
__TIMER_LOCKDEP_MAP_INITIALIZER( \
__FILE__ ":" __stringify(__LINE__)) \
Expand Down Expand Up @@ -121,14 +119,12 @@ static inline void init_timer_on_stack_key(struct timer_list *timer,
do { \
__init_timer((_timer), (_flags)); \
(_timer)->function = (_fn); \
(_timer)->data = (_data); \
} while (0)

#define __setup_timer_on_stack(_timer, _fn, _data, _flags) \
do { \
__init_timer_on_stack((_timer), (_flags)); \
(_timer)->function = (_fn); \
(_timer)->data = (_data); \
} while (0)

#ifndef CONFIG_LOCKDEP
Expand Down
17 changes: 7 additions & 10 deletions kernel/time/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,12 @@ EXPORT_SYMBOL(timer_reduce);
* add_timer - start a timer
* @timer: the timer to be added
*
* The kernel will do a ->function(->data) callback from the
* The kernel will do a ->function(@timer) callback from the
* timer interrupt at the ->expires point in the future. The
* current time is 'jiffies'.
*
* The timer's ->expires, ->function (and if the handler uses it, ->data)
* fields must be set prior calling this function.
* The timer's ->expires, ->function fields must be set prior calling this
* function.
*
* Timers with an ->expires field in the past will be executed in the next
* timer tick.
Expand Down Expand Up @@ -1284,8 +1284,7 @@ int del_timer_sync(struct timer_list *timer)
EXPORT_SYMBOL(del_timer_sync);
#endif

static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
unsigned long data)
static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long))
{
int count = preempt_count();

Expand All @@ -1309,7 +1308,7 @@ static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
lock_map_acquire(&lockdep_map);

trace_timer_expire_entry(timer);
fn(data);
fn((TIMER_DATA_TYPE)timer);
trace_timer_expire_exit(timer);

lock_map_release(&lockdep_map);
Expand All @@ -1332,23 +1331,21 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head)
while (!hlist_empty(head)) {
struct timer_list *timer;
void (*fn)(unsigned long);
unsigned long data;

timer = hlist_entry(head->first, struct timer_list, entry);

base->running_timer = timer;
detach_timer(timer, true);

fn = timer->function;
data = timer->data;

if (timer->flags & TIMER_IRQSAFE) {
raw_spin_unlock(&base->lock);
call_timer_fn(timer, fn, data);
call_timer_fn(timer, fn);
raw_spin_lock(&base->lock);
} else {
raw_spin_unlock_irq(&base->lock);
call_timer_fn(timer, fn, data);
call_timer_fn(timer, fn);
raw_spin_lock_irq(&base->lock);
}
}
Expand Down

0 comments on commit c1eba5b

Please sign in to comment.