USB: usb_wwan: fix race between write and resume
authorxiao jin <jin.xiao@intel.com>
Mon, 26 May 2014 17:23:14 +0000 (19:23 +0200)
committerJiri Slaby <jslaby@suse.cz>
Wed, 2 Jul 2014 10:06:18 +0000 (12:06 +0200)
commit d9e93c08d8d985e5ef89436ebc9f4aad7e31559f upstream.

We find a race between write and resume. usb_wwan_resume run play_delayed()
and spin_unlock, but intfdata->suspended still is not set to zero.
At this time usb_wwan_write is called and anchor the urb to delay
list. Then resume keep running but the delayed urb have no chance
to be commit until next resume. If the time of next resume is far
away, tty will be blocked in tty_wait_until_sent during time. The
race also can lead to writes being reordered.

This patch put play_Delayed and intfdata->suspended together in the
spinlock, it's to avoid the write race during resume.

Fixes: 383cedc3bb43 ("USB: serial: full autosuspend support for the
option driver")

Signed-off-by: xiao jin <jin.xiao@intel.com>
Signed-off-by: Zhang, Qi1 <qi1.zhang@intel.com>
Reviewed-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/usb/serial/usb_wwan.c

index 7096d0ba1d0f00d3a607daa1d13064c9111c4652..80c16d84156a3aafca2f14c06608ce0e1cc5cedd 100644 (file)
@@ -664,17 +664,15 @@ int usb_wwan_resume(struct usb_serial *serial)
                }
        }
 
+       spin_lock_irq(&intfdata->susp_lock);
        for (i = 0; i < serial->num_ports; i++) {
                /* walk all ports */
                port = serial->port[i];
                portdata = usb_get_serial_port_data(port);
 
                /* skip closed ports */
-               spin_lock_irq(&intfdata->susp_lock);
-               if (!portdata || !portdata->opened) {
-                       spin_unlock_irq(&intfdata->susp_lock);
+               if (!portdata || !portdata->opened)
                        continue;
-               }
 
                for (j = 0; j < N_IN_URB; j++) {
                        urb = portdata->in_urbs[j];
@@ -687,9 +685,7 @@ int usb_wwan_resume(struct usb_serial *serial)
                        }
                }
                play_delayed(port);
-               spin_unlock_irq(&intfdata->susp_lock);
        }
-       spin_lock_irq(&intfdata->susp_lock);
        intfdata->suspended = 0;
        spin_unlock_irq(&intfdata->susp_lock);
 err_out: