Skip to content

Commit

Permalink
usb: serial: prevent suspend/resume from racing against probe/remove
Browse files Browse the repository at this point in the history
Some usb-serial drivers may access port data in their suspend/
resume functions. Such drivers must always verify the validity
of the data as both suspend and resume can be called both before
usb_serial_device_probe and after usb_serial_device_remove.

But the port data may be invalidated during port_probe and
port_remove. This patch prevents the race against suspend and
resume by disabling suspend while port_probe or port_remove is
running.

Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Bjørn Mork authored and Greg Kroah-Hartman committed Aug 10, 2012
1 parent a1028f0 commit d5fd650
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions drivers/usb/serial/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,23 @@ static int usb_serial_device_probe(struct device *dev)
goto exit;
}

/* make sure suspend/resume doesn't race against port_probe */
retval = usb_autopm_get_interface(port->serial->interface);
if (retval)
goto exit;

driver = port->serial->type;
if (driver->port_probe) {
retval = driver->port_probe(port);
if (retval)
goto exit;
goto exit_with_autopm;
}

retval = device_create_file(dev, &dev_attr_port_number);
if (retval) {
if (driver->port_remove)
retval = driver->port_remove(port);
goto exit;
goto exit_with_autopm;
}

minor = port->number;
Expand All @@ -81,6 +86,8 @@ static int usb_serial_device_probe(struct device *dev)
"%s converter now attached to ttyUSB%d\n",
driver->description, minor);

exit_with_autopm:
usb_autopm_put_interface(port->serial->interface);
exit:
return retval;
}
Expand All @@ -96,6 +103,9 @@ static int usb_serial_device_remove(struct device *dev)
if (!port)
return -ENODEV;

/* make sure suspend/resume doesn't race against port_remove */
usb_autopm_get_interface(port->serial->interface);

device_remove_file(&port->dev, &dev_attr_port_number);

driver = port->serial->type;
Expand All @@ -107,6 +117,7 @@ static int usb_serial_device_remove(struct device *dev)
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
driver->description, minor);

usb_autopm_put_interface(port->serial->interface);
return retval;
}

Expand Down

0 comments on commit d5fd650

Please sign in to comment.