diff options
author | Kees Cook <keescook@chromium.org> | 2017-10-21 03:12:34 -0400 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2017-11-21 18:46:44 -0500 |
commit | 72a9f9a445d4e296484aa5dfbfea6254d01f7cf5 (patch) | |
tree | 664dc548e6684555b1a9d141bdff1eab328dbe6b | |
parent | ff07a23fec3f9ea28d22852097260b38903891c4 (diff) |
usb: usbatm: 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. Additionally corrects and on-stack
timer usage.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Duncan Sands <duncan.sands@free.fr>
Cc: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Cc: accessrunner-general@lists.sourceforge.net
Cc: linux-usb@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Allen Pais <allen.lkml@gmail.com>
-rw-r--r-- | drivers/usb/atm/cxacru.c | 23 | ||||
-rw-r--r-- | drivers/usb/atm/speedtch.c | 16 | ||||
-rw-r--r-- | drivers/usb/atm/usbatm.c | 10 |
3 files changed, 29 insertions, 20 deletions
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 6470d259b7d8..8af797252af2 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c | |||
@@ -547,21 +547,30 @@ static void cxacru_blocking_completion(struct urb *urb) | |||
547 | complete(urb->context); | 547 | complete(urb->context); |
548 | } | 548 | } |
549 | 549 | ||
550 | static void cxacru_timeout_kill(unsigned long data) | 550 | struct cxacru_timer { |
551 | struct timer_list timer; | ||
552 | struct urb *urb; | ||
553 | }; | ||
554 | |||
555 | static void cxacru_timeout_kill(struct timer_list *t) | ||
551 | { | 556 | { |
552 | usb_unlink_urb((struct urb *) data); | 557 | struct cxacru_timer *timer = from_timer(timer, t, timer); |
558 | |||
559 | usb_unlink_urb(timer->urb); | ||
553 | } | 560 | } |
554 | 561 | ||
555 | static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, | 562 | static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, |
556 | int *actual_length) | 563 | int *actual_length) |
557 | { | 564 | { |
558 | struct timer_list timer; | 565 | struct cxacru_timer timer = { |
566 | .urb = urb, | ||
567 | }; | ||
559 | 568 | ||
560 | setup_timer(&timer, cxacru_timeout_kill, (unsigned long)urb); | 569 | timer_setup_on_stack(&timer.timer, cxacru_timeout_kill, 0); |
561 | timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT); | 570 | mod_timer(&timer.timer, jiffies + msecs_to_jiffies(CMD_TIMEOUT)); |
562 | add_timer(&timer); | ||
563 | wait_for_completion(done); | 571 | wait_for_completion(done); |
564 | del_timer_sync(&timer); | 572 | del_timer_sync(&timer.timer); |
573 | destroy_timer_on_stack(&timer.timer); | ||
565 | 574 | ||
566 | if (actual_length) | 575 | if (actual_length) |
567 | *actual_length = urb->actual_length; | 576 | *actual_length = urb->actual_length; |
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 5a5e8c0aaa39..973548b5c15c 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c | |||
@@ -557,9 +557,10 @@ static void speedtch_check_status(struct work_struct *work) | |||
557 | } | 557 | } |
558 | } | 558 | } |
559 | 559 | ||
560 | static void speedtch_status_poll(unsigned long data) | 560 | static void speedtch_status_poll(struct timer_list *t) |
561 | { | 561 | { |
562 | struct speedtch_instance_data *instance = (void *)data; | 562 | struct speedtch_instance_data *instance = from_timer(instance, t, |
563 | status_check_timer); | ||
563 | 564 | ||
564 | schedule_work(&instance->status_check_work); | 565 | schedule_work(&instance->status_check_work); |
565 | 566 | ||
@@ -570,9 +571,10 @@ static void speedtch_status_poll(unsigned long data) | |||
570 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); | 571 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); |
571 | } | 572 | } |
572 | 573 | ||
573 | static void speedtch_resubmit_int(unsigned long data) | 574 | static void speedtch_resubmit_int(struct timer_list *t) |
574 | { | 575 | { |
575 | struct speedtch_instance_data *instance = (void *)data; | 576 | struct speedtch_instance_data *instance = from_timer(instance, t, |
577 | resubmit_timer); | ||
576 | struct urb *int_urb = instance->int_urb; | 578 | struct urb *int_urb = instance->int_urb; |
577 | int ret; | 579 | int ret; |
578 | 580 | ||
@@ -860,13 +862,11 @@ static int speedtch_bind(struct usbatm_data *usbatm, | |||
860 | usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0); | 862 | usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0); |
861 | 863 | ||
862 | INIT_WORK(&instance->status_check_work, speedtch_check_status); | 864 | INIT_WORK(&instance->status_check_work, speedtch_check_status); |
863 | setup_timer(&instance->status_check_timer, speedtch_status_poll, | 865 | timer_setup(&instance->status_check_timer, speedtch_status_poll, 0); |
864 | (unsigned long)instance); | ||
865 | instance->last_status = 0xff; | 866 | instance->last_status = 0xff; |
866 | instance->poll_delay = MIN_POLL_DELAY; | 867 | instance->poll_delay = MIN_POLL_DELAY; |
867 | 868 | ||
868 | setup_timer(&instance->resubmit_timer, speedtch_resubmit_int, | 869 | timer_setup(&instance->resubmit_timer, speedtch_resubmit_int, 0); |
869 | (unsigned long)instance); | ||
870 | 870 | ||
871 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); | 871 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); |
872 | 872 | ||
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c index 044264aa1f96..dbea28495e1d 100644 --- a/drivers/usb/atm/usbatm.c +++ b/drivers/usb/atm/usbatm.c | |||
@@ -989,18 +989,18 @@ static int usbatm_heavy_init(struct usbatm_data *instance) | |||
989 | return 0; | 989 | return 0; |
990 | } | 990 | } |
991 | 991 | ||
992 | static void usbatm_tasklet_schedule(unsigned long data) | 992 | static void usbatm_tasklet_schedule(struct timer_list *t) |
993 | { | 993 | { |
994 | tasklet_schedule((struct tasklet_struct *) data); | 994 | struct usbatm_channel *channel = from_timer(channel, t, delay); |
995 | |||
996 | tasklet_schedule(&channel->tasklet); | ||
995 | } | 997 | } |
996 | 998 | ||
997 | static void usbatm_init_channel(struct usbatm_channel *channel) | 999 | static void usbatm_init_channel(struct usbatm_channel *channel) |
998 | { | 1000 | { |
999 | spin_lock_init(&channel->lock); | 1001 | spin_lock_init(&channel->lock); |
1000 | INIT_LIST_HEAD(&channel->list); | 1002 | INIT_LIST_HEAD(&channel->list); |
1001 | channel->delay.function = usbatm_tasklet_schedule; | 1003 | timer_setup(&channel->delay, usbatm_tasklet_schedule, 0); |
1002 | channel->delay.data = (unsigned long) &channel->tasklet; | ||
1003 | init_timer(&channel->delay); | ||
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, | 1006 | int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, |