staging/irda-usb: Convert timers to use timer_setup()
authorKees Cook <keescook@chromium.org>
Wed, 18 Oct 2017 20:23:07 +0000 (13:23 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 20 Oct 2017 12:42:50 +0000 (14:42 +0200)
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 requires adding a pointer to
hold the timer's target URB, as there won't be a way to pass this in the
future.

Cc: Samuel Ortiz <samuel@sortiz.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/irda/drivers/irda-usb.c
drivers/staging/irda/drivers/irda-usb.h

index 82bfc051e1de241b1dd2b01db09fc6c1797b8e57..bda6bdc6c70b4b7568b4dd571990640207eea558 100644 (file)
@@ -117,7 +117,7 @@ static void irda_usb_close(struct irda_usb_cb *self);
 static void speed_bulk_callback(struct urb *urb);
 static void write_bulk_callback(struct urb *urb);
 static void irda_usb_receive(struct urb *urb);
-static void irda_usb_rx_defer_expired(unsigned long data);
+static void irda_usb_rx_defer_expired(struct timer_list *t);
 static int irda_usb_net_open(struct net_device *dev);
 static int irda_usb_net_close(struct net_device *dev);
 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -846,8 +846,7 @@ static void irda_usb_receive(struct urb *urb)
                 * hot unplug of the dongle...
                 * Lowest effective timer is 10ms...
                 * Jean II */
-               self->rx_defer_timer.function = irda_usb_rx_defer_expired;
-               self->rx_defer_timer.data = (unsigned long) urb;
+               self->rx_defer_timer_urb = urb;
                mod_timer(&self->rx_defer_timer,
                          jiffies + msecs_to_jiffies(10));
 
@@ -953,20 +952,13 @@ done:
  * In case of errors, we want the USB layer to have time to recover.
  * Now, it is time to resubmit ouur Rx URB...
  */
-static void irda_usb_rx_defer_expired(unsigned long data)
+static void irda_usb_rx_defer_expired(struct timer_list *t)
 {
-       struct urb *urb = (struct urb *) data;
+       struct irda_usb_cb *self = from_timer(self, t, rx_defer_timer);
+       struct urb *urb = self->rx_defer_timer_urb;
        struct sk_buff *skb = (struct sk_buff *) urb->context;
-       struct irda_usb_cb *self; 
-       struct irda_skb_cb *cb;
        struct urb *next_urb;
 
-       /* Find ourselves */
-       cb = (struct irda_skb_cb *) skb->cb;
-       IRDA_ASSERT(cb != NULL, return;);
-       self = (struct irda_usb_cb *) cb->context;
-       IRDA_ASSERT(self != NULL, return;);
-
        /* Same stuff as when Rx is done, see above... */
        next_urb = self->idle_rx_urb;
        urb->context = NULL;
@@ -1622,7 +1614,7 @@ static int irda_usb_probe(struct usb_interface *intf,
        self = netdev_priv(net);
        self->netdev = net;
        spin_lock_init(&self->lock);
-       init_timer(&self->rx_defer_timer);
+       timer_setup(&self->rx_defer_timer, irda_usb_rx_defer_expired, 0);
 
        self->capability = id->driver_info;
        self->needspatch = ((self->capability & IUC_STIR421X) != 0);
index 8ac389fa93487c56f4745c5f61a59bd441064677..56ee8c16c5e23ef08c5f0e1fb23c5d9c22aa5c12 100644 (file)
@@ -170,5 +170,6 @@ struct irda_usb_cb {
        int needspatch;                 /* device needs firmware patch */
 
        struct timer_list rx_defer_timer;       /* Wait for Rx error to clear */
+       struct urb *rx_defer_timer_urb; /* URB attached to rx_defer_timer */
 };