From 1d27e3e2252ba9d949ca82fbdb73cde102cb2067 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 4 Oct 2017 16:27:04 -0700 Subject: timer: Remove expires and data arguments from DEFINE_TIMER Drop the arguments from the macro and adjust all callers with the following script: perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \ $(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h) Signed-off-by: Kees Cook Acked-by: Geert Uytterhoeven # for m68k parts Acked-by: Guenter Roeck # for watchdog parts Acked-by: David S. Miller # for networking parts Acked-by: Greg Kroah-Hartman Acked-by: Kalle Valo # for wireless parts Acked-by: Arnd Bergmann Cc: linux-mips@linux-mips.org Cc: Petr Mladek Cc: Benjamin Herrenschmidt Cc: Lai Jiangshan Cc: Sebastian Reichel Cc: Kalle Valo Cc: Paul Mackerras Cc: Pavel Machek Cc: linux1394-devel@lists.sourceforge.net Cc: Chris Metcalf Cc: linux-s390@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: "James E.J. Bottomley" Cc: Wim Van Sebroeck Cc: Michael Ellerman Cc: Ursula Braun Cc: Viresh Kumar Cc: Harish Patil Cc: Stephen Boyd Cc: Michael Reed Cc: Manish Chopra Cc: Len Brown Cc: Arnd Bergmann Cc: linux-pm@vger.kernel.org Cc: Heiko Carstens Cc: Tejun Heo Cc: Julian Wiedmann Cc: John Stultz Cc: Mark Gross Cc: linux-watchdog@vger.kernel.org Cc: linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Oleg Nesterov Cc: Ralf Baechle Cc: Stefan Richter Cc: Guenter Roeck Cc: netdev@vger.kernel.org Cc: Martin Schwidefsky Cc: Andrew Morton Cc: linuxppc-dev@lists.ozlabs.org Cc: Sudip Mukherjee Link: https://lkml.kernel.org/r/1507159627-127660-11-git-send-email-keescook@chromium.org Signed-off-by: Thomas Gleixner --- drivers/block/ataflop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/block') diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 92da886180aa..ae596e55bcb6 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -373,10 +373,10 @@ static void floppy_release(struct gendisk *disk, fmode_t mode); /************************* End of Prototypes **************************/ -static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer, 0, 0); -static DEFINE_TIMER(readtrack_timer, fd_readtrack_check, 0, 0); -static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0); -static DEFINE_TIMER(fd_timer, check_change, 0, 0); +static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer); +static DEFINE_TIMER(readtrack_timer, fd_readtrack_check); +static DEFINE_TIMER(timeout_timer, fd_times_out); +static DEFINE_TIMER(fd_timer, check_change); static void fd_end_request_cur(blk_status_t err) { -- cgit v1.2.1 From 3c557df67257c114401f18ee412f0b74091c3c6f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Mon, 9 Oct 2017 17:10:32 -0700 Subject: timer: Remove meaningless .data/.function assignments Several timer users needlessly reset their .function/.data fields during their timer callback, but nothing else changes them. Some users do not use their .data field at all. Each instance is removed here. Signed-off-by: Kees Cook Signed-off-by: Thomas Gleixner Acked-by: Greg Kroah-Hartman # for staging Acked-by: Krzysztof Halasa # for wan/hdlc* Acked-by: Jens Axboe # for amiflop Cc: devel@driverdev.osuosl.org Cc: netdev@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: Jens Axboe Cc: Ganesh Krishna Cc: Aditya Shankar Link: https://lkml.kernel.org/r/20171010001032.GA119829@beast --- drivers/block/amiflop.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/block') diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index 49908c74bfcb..4e3fb9f104af 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -323,7 +323,7 @@ static void fd_deselect (int drive) } -static void motor_on_callback(unsigned long nr) +static void motor_on_callback(unsigned long ignored) { if (!(ciaa.pra & DSKRDY) || --on_attempts == 0) { complete_all(&motor_on_completion); @@ -344,7 +344,6 @@ static int fd_motor_on(int nr) fd_select(nr); reinit_completion(&motor_on_completion); - motor_on_timer.data = nr; mod_timer(&motor_on_timer, jiffies + HZ/2); on_attempts = 10; -- cgit v1.2.1 From 2bccef39c0d94b9ee428ae777c59cef1fced786c Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 17 Oct 2017 20:33:01 -0700 Subject: drbd: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Philipp Reisner Cc: Lars Ellenberg Cc: drbd-dev@lists.linbit.com Signed-off-by: Kees Cook --- drivers/block/drbd/drbd_int.h | 4 ++-- drivers/block/drbd/drbd_main.c | 18 +++++++----------- drivers/block/drbd/drbd_receiver.c | 2 +- drivers/block/drbd/drbd_req.c | 4 ++-- drivers/block/drbd/drbd_req.h | 2 +- drivers/block/drbd/drbd_worker.c | 8 ++++---- 6 files changed, 17 insertions(+), 21 deletions(-) (limited to 'drivers/block') diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index 7e8589ce631c..06ecee1b528e 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h @@ -1551,8 +1551,8 @@ extern int w_restart_disk_io(struct drbd_work *, int); extern int w_send_out_of_sync(struct drbd_work *, int); extern int w_start_resync(struct drbd_work *, int); -extern void resync_timer_fn(unsigned long data); -extern void start_resync_timer_fn(unsigned long data); +extern void resync_timer_fn(struct timer_list *t); +extern void start_resync_timer_fn(struct timer_list *t); extern void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req); diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 8cb3791898ae..4b4697a1f963 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -64,7 +64,7 @@ static DEFINE_MUTEX(drbd_main_mutex); static int drbd_open(struct block_device *bdev, fmode_t mode); static void drbd_release(struct gendisk *gd, fmode_t mode); -static void md_sync_timer_fn(unsigned long data); +static void md_sync_timer_fn(struct timer_list *t); static int w_bitmap_io(struct drbd_work *w, int unused); MODULE_AUTHOR("Philipp Reisner , " @@ -2023,14 +2023,10 @@ void drbd_init_set_defaults(struct drbd_device *device) device->unplug_work.cb = w_send_write_hint; device->bm_io_work.w.cb = w_bitmap_io; - setup_timer(&device->resync_timer, resync_timer_fn, - (unsigned long)device); - setup_timer(&device->md_sync_timer, md_sync_timer_fn, - (unsigned long)device); - setup_timer(&device->start_resync_timer, start_resync_timer_fn, - (unsigned long)device); - setup_timer(&device->request_timer, request_timer_fn, - (unsigned long)device); + timer_setup(&device->resync_timer, resync_timer_fn, 0); + timer_setup(&device->md_sync_timer, md_sync_timer_fn, 0); + timer_setup(&device->start_resync_timer, start_resync_timer_fn, 0); + timer_setup(&device->request_timer, request_timer_fn, 0); init_waitqueue_head(&device->misc_wait); init_waitqueue_head(&device->state_wait); @@ -3721,9 +3717,9 @@ int drbd_md_test_flag(struct drbd_backing_dev *bdev, int flag) return (bdev->md.flags & flag) != 0; } -static void md_sync_timer_fn(unsigned long data) +static void md_sync_timer_fn(struct timer_list *t) { - struct drbd_device *device = (struct drbd_device *) data; + struct drbd_device *device = from_timer(device, t, md_sync_timer); drbd_device_post_work(device, MD_SYNC); } diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c index 796eaf347dc0..cb2fa63f6bc0 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c @@ -5056,7 +5056,7 @@ static int drbd_disconnected(struct drbd_peer_device *peer_device) wake_up(&device->misc_wait); del_timer_sync(&device->resync_timer); - resync_timer_fn((unsigned long)device); + resync_timer_fn(&device->resync_timer); /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, * w_make_resync_request etc. which may still be on the worker queue diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c index de8566e55334..a500e738d929 100644 --- a/drivers/block/drbd/drbd_req.c +++ b/drivers/block/drbd/drbd_req.c @@ -1714,9 +1714,9 @@ static bool net_timeout_reached(struct drbd_request *net_req, * to expire twice (worst case) to become effective. Good enough. */ -void request_timer_fn(unsigned long data) +void request_timer_fn(struct timer_list *t) { - struct drbd_device *device = (struct drbd_device *) data; + struct drbd_device *device = from_timer(device, t, request_timer); struct drbd_connection *connection = first_peer_device(device)->connection; struct drbd_request *req_read, *req_write, *req_peer; /* oldest request */ struct net_conf *nc; diff --git a/drivers/block/drbd/drbd_req.h b/drivers/block/drbd/drbd_req.h index a2254f825601..cb97b3b30962 100644 --- a/drivers/block/drbd/drbd_req.h +++ b/drivers/block/drbd/drbd_req.h @@ -294,7 +294,7 @@ extern int __req_mod(struct drbd_request *req, enum drbd_req_event what, struct bio_and_error *m); extern void complete_master_bio(struct drbd_device *device, struct bio_and_error *m); -extern void request_timer_fn(unsigned long data); +extern void request_timer_fn(struct timer_list *t); extern void tl_restart(struct drbd_connection *connection, enum drbd_req_event what); extern void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what); extern void tl_abort_disk_io(struct drbd_device *device); diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c index 03471b3fce86..1476cb3439f4 100644 --- a/drivers/block/drbd/drbd_worker.c +++ b/drivers/block/drbd/drbd_worker.c @@ -457,9 +457,9 @@ int w_resync_timer(struct drbd_work *w, int cancel) return 0; } -void resync_timer_fn(unsigned long data) +void resync_timer_fn(struct timer_list *t) { - struct drbd_device *device = (struct drbd_device *) data; + struct drbd_device *device = from_timer(device, t, resync_timer); drbd_queue_work_if_unqueued( &first_peer_device(device)->connection->sender_work, @@ -1705,9 +1705,9 @@ void drbd_rs_controller_reset(struct drbd_device *device) rcu_read_unlock(); } -void start_resync_timer_fn(unsigned long data) +void start_resync_timer_fn(struct timer_list *t) { - struct drbd_device *device = (struct drbd_device *) data; + struct drbd_device *device = from_timer(device, t, start_resync_timer); drbd_device_post_work(device, RS_START); } -- cgit v1.2.1 From 5ea22086ed42bef8dde93f45a42a3ace486eb788 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 30 Aug 2017 14:53:24 -0700 Subject: block/aoe: discover_timer: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. This refactors the discover_timer to remove the needless locking and state machine used for synchronizing timer death. Using del_timer_sync() will already do the right thing. Cc: Jens Axboe Cc: "Ed L. Cashin" Cc: Thomas Gleixner Signed-off-by: Kees Cook --- drivers/block/aoe/aoemain.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) (limited to 'drivers/block') diff --git a/drivers/block/aoe/aoemain.c b/drivers/block/aoe/aoemain.c index 4b987c2fefbe..251482066977 100644 --- a/drivers/block/aoe/aoemain.c +++ b/drivers/block/aoe/aoemain.c @@ -15,49 +15,19 @@ MODULE_AUTHOR("Sam Hopkins "); MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels"); MODULE_VERSION(VERSION); -enum { TINIT, TRUN, TKILL }; +static struct timer_list timer; -static void -discover_timer(ulong vp) +static void discover_timer(struct timer_list *t) { - static struct timer_list t; - static volatile ulong die; - static spinlock_t lock; - ulong flags; - enum { DTIMERTICK = HZ * 60 }; /* one minute */ - - switch (vp) { - case TINIT: - init_timer(&t); - spin_lock_init(&lock); - t.data = TRUN; - t.function = discover_timer; - die = 0; - case TRUN: - spin_lock_irqsave(&lock, flags); - if (!die) { - t.expires = jiffies + DTIMERTICK; - add_timer(&t); - } - spin_unlock_irqrestore(&lock, flags); - - aoecmd_cfg(0xffff, 0xff); - return; - case TKILL: - spin_lock_irqsave(&lock, flags); - die = 1; - spin_unlock_irqrestore(&lock, flags); + mod_timer(t, jiffies + HZ * 60); /* one minute */ - del_timer_sync(&t); - default: - return; - } + aoecmd_cfg(0xffff, 0xff); } static void aoe_exit(void) { - discover_timer(TKILL); + del_timer_sync(&timer); aoenet_exit(); unregister_blkdev(AOE_MAJOR, DEVICE_NAME); @@ -93,7 +63,9 @@ aoe_init(void) goto blkreg_fail; } printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION); - discover_timer(TINIT); + + timer_setup(&timer, discover_timer, 0); + discover_timer(&timer); return 0; blkreg_fail: aoecmd_exit(); -- cgit v1.2.1