[PATCH] kthread_worker: switch to modern timers

From: Petr Mladek
Date: Wed May 17 2017 - 08:00:19 EST


Suggested-by: Christoph Hellwig <hch@xxxxxx>
Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
---
include/linux/kthread.h | 11 ++++-------
kernel/kthread.c | 9 ++++-----
2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 4fec8b775895..8c62c36eb32a 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -75,7 +75,7 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
*/
struct kthread_work;
typedef void (*kthread_work_func_t)(struct kthread_work *work);
-void kthread_delayed_work_timer_fn(unsigned long __data);
+void kthread_delayed_work_timer_fn(struct timer_list *timer);

enum {
KTW_FREEZABLE = 1 << 0, /* freeze during suspend */
@@ -116,9 +116,8 @@ struct kthread_delayed_work {

#define KTHREAD_DELAYED_WORK_INIT(dwork, fn) { \
.work = KTHREAD_WORK_INIT((dwork).work, (fn)), \
- .timer = __TIMER_INITIALIZER(kthread_delayed_work_timer_fn, \
- 0, (unsigned long)&(dwork), \
- TIMER_IRQSAFE), \
+ .timer = INIT_TIMER(kthread_delayed_work_timer_fn, \
+ 0, TIMER_IRQSAFE), \
}

#define DEFINE_KTHREAD_WORKER(worker) \
@@ -163,9 +162,7 @@ extern void __kthread_init_worker(struct kthread_worker *worker,
#define kthread_init_delayed_work(dwork, fn) \
do { \
kthread_init_work(&(dwork)->work, (fn)); \
- __setup_timer(&(dwork)->timer, \
- kthread_delayed_work_timer_fn, \
- (unsigned long)(dwork), \
+ prepare_timer(&(dwork)->timer, delayed_work_timer_fn, \
TIMER_IRQSAFE); \
} while (0)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index 26db528c1d88..369e72ec7e48 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -797,15 +797,15 @@ bool kthread_queue_work(struct kthread_worker *worker,
/**
* kthread_delayed_work_timer_fn - callback that queues the associated kthread
* delayed work when the timer expires.
- * @__data: pointer to the data associated with the timer
+ * @timer: pointer to timer_list in the associated data structure
*
* The format of the function is defined by struct timer_list.
* It should have been called from irqsafe timer with irq already off.
*/
-void kthread_delayed_work_timer_fn(unsigned long __data)
+void kthread_delayed_work_timer_fn(struct timer_list *timer)
{
struct kthread_delayed_work *dwork =
- (struct kthread_delayed_work *)__data;
+ container_of(timer, struct kthread_delayed_work, timer);
struct kthread_work *work = &dwork->work;
struct kthread_worker *worker = work->worker;

@@ -836,8 +836,7 @@ void __kthread_queue_delayed_work(struct kthread_worker *worker,
struct timer_list *timer = &dwork->timer;
struct kthread_work *work = &dwork->work;

- WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn ||
- timer->data != (unsigned long)dwork);
+ WARN_ON_ONCE(timer->func != kthread_delayed_work_timer_fn);

/*
* If @delay is 0, queue @dwork->work immediately. This is for
--
1.8.5.6