From 8e4e276a3857461b2bb5dd596768fcbe2a469d5a Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 24 Oct 2017 03:08:42 -0700 Subject: usb: r8a66597-hcd: 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 rearranges the arrays of timers to minimize the need for a pointer back to the main structure. Cc: Chris Brandt Cc: Julia Lawall Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/r8a66597-hcd.c | 27 ++++++++++++++------------- drivers/usb/host/r8a66597.h | 11 +++++++++-- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'drivers/usb/host') diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index 5e5fc9d..0f3d2ae 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c @@ -1273,7 +1273,7 @@ static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td) break; } - mod_timer(&r8a66597->td_timer[td->pipenum], + mod_timer(&r8a66597->timers[td->pipenum].td, jiffies + msecs_to_jiffies(time)); } } @@ -1733,9 +1733,10 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port) } } -static void r8a66597_interval_timer(unsigned long _r8a66597) +static void r8a66597_interval_timer(struct timer_list *t) { - struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; + struct r8a66597_timers *timers = from_timer(timers, t, interval); + struct r8a66597 *r8a66597 = timers->r8a66597; unsigned long flags; u16 pipenum; struct r8a66597_td *td; @@ -1745,7 +1746,7 @@ static void r8a66597_interval_timer(unsigned long _r8a66597) for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { if (!(r8a66597->interval_map & (1 << pipenum))) continue; - if (timer_pending(&r8a66597->interval_timer[pipenum])) + if (timer_pending(&r8a66597->timers[pipenum].interval)) continue; td = r8a66597_get_td(r8a66597, pipenum); @@ -1756,9 +1757,10 @@ static void r8a66597_interval_timer(unsigned long _r8a66597) spin_unlock_irqrestore(&r8a66597->lock, flags); } -static void r8a66597_td_timer(unsigned long _r8a66597) +static void r8a66597_td_timer(struct timer_list *t) { - struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; + struct r8a66597_timers *timers = from_timer(timers, t, td); + struct r8a66597 *r8a66597 = timers->r8a66597; unsigned long flags; u16 pipenum; struct r8a66597_td *td, *new_td = NULL; @@ -1768,7 +1770,7 @@ static void r8a66597_td_timer(unsigned long _r8a66597) for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { if (!(r8a66597->timeout_map & (1 << pipenum))) continue; - if (timer_pending(&r8a66597->td_timer[pipenum])) + if (timer_pending(&r8a66597->timers[pipenum].td)) continue; td = r8a66597_get_td(r8a66597, pipenum); @@ -1942,7 +1944,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd, if (request) { if (td->pipe->info.timer_interval) { r8a66597->interval_map |= 1 << td->pipenum; - mod_timer(&r8a66597->interval_timer[td->pipenum], + mod_timer(&r8a66597->timers[td->pipenum].interval, jiffies + msecs_to_jiffies( td->pipe->info.timer_interval)); } else { @@ -2495,11 +2497,10 @@ static int r8a66597_probe(struct platform_device *pdev) for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { INIT_LIST_HEAD(&r8a66597->pipe_queue[i]); - setup_timer(&r8a66597->td_timer[i], r8a66597_td_timer, - (unsigned long)r8a66597); - setup_timer(&r8a66597->interval_timer[i], - r8a66597_interval_timer, - (unsigned long)r8a66597); + r8a66597->timers[i].r8a66597 = r8a66597; + timer_setup(&r8a66597->timers[i].td, r8a66597_td_timer, 0); + timer_setup(&r8a66597->timers[i].interval, + r8a66597_interval_timer, 0); } INIT_LIST_HEAD(&r8a66597->child_device); diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h index 672cea3..b8406c0 100644 --- a/drivers/usb/host/r8a66597.h +++ b/drivers/usb/host/r8a66597.h @@ -107,6 +107,14 @@ struct r8a66597_root_hub { struct r8a66597_device *dev; }; +struct r8a66597; + +struct r8a66597_timers { + struct timer_list td; + struct timer_list interval; + struct r8a66597 *r8a66597; +}; + struct r8a66597 { spinlock_t lock; void __iomem *reg; @@ -117,8 +125,7 @@ struct r8a66597 { struct list_head pipe_queue[R8A66597_MAX_NUM_PIPE]; struct timer_list rh_timer; - struct timer_list td_timer[R8A66597_MAX_NUM_PIPE]; - struct timer_list interval_timer[R8A66597_MAX_NUM_PIPE]; + struct r8a66597_timers timers[R8A66597_MAX_NUM_PIPE]; unsigned short address_map; unsigned short timeout_map; -- cgit v1.1