USB: sierra: refactor delayed-urb submission
authorJohan Hovold <jhovold@gmail.com>
Mon, 26 May 2014 17:23:07 +0000 (19:23 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 27 May 2014 22:04:05 +0000 (15:04 -0700)
Refactor and clean up delayed-urb submission at resume.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/serial/sierra.c

index 1d42e8305b8e6a4ded3fcf93de1cf23037d8b01d..967331964f361eda9170377180c9bd8abaf5cca1 100644 (file)
@@ -981,12 +981,51 @@ static int sierra_suspend(struct usb_serial *serial, pm_message_t message)
        return 0;
 }
 
+/* Caller must hold susp_lock. */
+static int sierra_submit_delayed_urbs(struct usb_serial_port *port)
+{
+       struct sierra_port_private *portdata = usb_get_serial_port_data(port);
+       struct sierra_intf_private *intfdata;
+       struct urb *urb;
+       int ec = 0;
+       int err;
+
+       intfdata = usb_get_serial_data(port->serial);
+
+       for (;;) {
+               urb = usb_get_from_anchor(&portdata->delayed);
+               if (!urb)
+                       break;
+
+               usb_anchor_urb(urb, &portdata->active);
+               intfdata->in_flight++;
+               err = usb_submit_urb(urb, GFP_ATOMIC);
+               if (err) {
+                       dev_err(&port->dev, "%s - submit urb failed: %d",
+                                       __func__, err);
+                       ec++;
+                       intfdata->in_flight--;
+                       usb_unanchor_urb(urb);
+                       kfree(urb->transfer_buffer);
+                       usb_free_urb(urb);
+
+                       spin_lock(&portdata->lock);
+                       portdata->outstanding_urbs--;
+                       spin_unlock(&portdata->lock);
+               }
+       }
+
+       if (ec)
+               return -EIO;
+
+       return 0;
+}
+
 static int sierra_resume(struct usb_serial *serial)
 {
        struct usb_serial_port *port;
        struct sierra_intf_private *intfdata = usb_get_serial_data(serial);
        struct sierra_port_private *portdata;
-       struct urb *urb;
        int ec = 0;
        int i, err;
 
@@ -998,25 +1037,9 @@ static int sierra_resume(struct usb_serial *serial)
                if (!portdata || !portdata->opened)
                        continue;
 
-               while ((urb = usb_get_from_anchor(&portdata->delayed))) {
-                       usb_anchor_urb(urb, &portdata->active);
-                       intfdata->in_flight++;
-                       err = usb_submit_urb(urb, GFP_ATOMIC);
-                       if (err < 0) {
-                               dev_err(&port->dev,
-                                       "%s - submit urb failed: %d",
-                                       __func__, err);
-                               ec++;
-                               intfdata->in_flight--;
-                               usb_unanchor_urb(urb);
-                               kfree(urb->transfer_buffer);
-                               usb_free_urb(urb);
-                               spin_lock(&portdata->lock);
-                               portdata->outstanding_urbs--;
-                               spin_unlock(&portdata->lock);
-                               continue;
-                       }
-               }
+               err = sierra_submit_delayed_urbs(port);
+               if (err)
+                       ec++;
 
                err = sierra_submit_rx_urbs(port, GFP_ATOMIC);
                if (err)