usb: usb_wwan: resume/suspend can be called after port is gone

We cannot unconditionally access any usb-serial port specific
data from the interface driver.  Both supending and resuming
may happen after the port has been removed and portdata is
freed.

Treat ports with no portdata as closed ports to avoid a NULL
pointer dereference on resume.  No need to kill URBs for
removed ports on suspend, avoiding the same NULL pointer
reference there.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Bjørn Mork 2012-07-27 01:11:43 +02:00 коммит произвёл Greg Kroah-Hartman
Родитель d5fd650cfc
Коммит 032129cb03
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -602,6 +602,8 @@ static void stop_read_write_urbs(struct usb_serial *serial)
for (i = 0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
port = serial->port[i]; port = serial->port[i];
portdata = usb_get_serial_port_data(port); portdata = usb_get_serial_port_data(port);
if (!portdata)
continue;
for (j = 0; j < N_IN_URB; j++) for (j = 0; j < N_IN_URB; j++)
usb_kill_urb(portdata->in_urbs[j]); usb_kill_urb(portdata->in_urbs[j]);
for (j = 0; j < N_OUT_URB; j++) for (j = 0; j < N_OUT_URB; j++)
@ -700,7 +702,7 @@ int usb_wwan_resume(struct usb_serial *serial)
/* skip closed ports */ /* skip closed ports */
spin_lock_irq(&intfdata->susp_lock); spin_lock_irq(&intfdata->susp_lock);
if (!portdata->opened) { if (!portdata || !portdata->opened) {
spin_unlock_irq(&intfdata->susp_lock); spin_unlock_irq(&intfdata->susp_lock);
continue; continue;
} }