diff options
author | Bjørn Mork <bjorn@mork.no> | 2012-07-26 19:11:42 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-10 14:51:43 -0400 |
commit | d5fd650cfc7ffeca4af0da939293c8e7a5aa7c36 (patch) | |
tree | 1f005c3c25a7d75d2cf4abc01f566efa23f9425a /drivers/usb | |
parent | a1028f0abfb321e0f87c10ac0cce8508097c2b42 (diff) |
usb: serial: prevent suspend/resume from racing against probe/remove
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>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/serial/bus.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index f398d1e34474..c15f2e7cefc7 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c | |||
@@ -61,18 +61,23 @@ static int usb_serial_device_probe(struct device *dev) | |||
61 | goto exit; | 61 | goto exit; |
62 | } | 62 | } |
63 | 63 | ||
64 | /* make sure suspend/resume doesn't race against port_probe */ | ||
65 | retval = usb_autopm_get_interface(port->serial->interface); | ||
66 | if (retval) | ||
67 | goto exit; | ||
68 | |||
64 | driver = port->serial->type; | 69 | driver = port->serial->type; |
65 | if (driver->port_probe) { | 70 | if (driver->port_probe) { |
66 | retval = driver->port_probe(port); | 71 | retval = driver->port_probe(port); |
67 | if (retval) | 72 | if (retval) |
68 | goto exit; | 73 | goto exit_with_autopm; |
69 | } | 74 | } |
70 | 75 | ||
71 | retval = device_create_file(dev, &dev_attr_port_number); | 76 | retval = device_create_file(dev, &dev_attr_port_number); |
72 | if (retval) { | 77 | if (retval) { |
73 | if (driver->port_remove) | 78 | if (driver->port_remove) |
74 | retval = driver->port_remove(port); | 79 | retval = driver->port_remove(port); |
75 | goto exit; | 80 | goto exit_with_autopm; |
76 | } | 81 | } |
77 | 82 | ||
78 | minor = port->number; | 83 | minor = port->number; |
@@ -81,6 +86,8 @@ static int usb_serial_device_probe(struct device *dev) | |||
81 | "%s converter now attached to ttyUSB%d\n", | 86 | "%s converter now attached to ttyUSB%d\n", |
82 | driver->description, minor); | 87 | driver->description, minor); |
83 | 88 | ||
89 | exit_with_autopm: | ||
90 | usb_autopm_put_interface(port->serial->interface); | ||
84 | exit: | 91 | exit: |
85 | return retval; | 92 | return retval; |
86 | } | 93 | } |
@@ -96,6 +103,9 @@ static int usb_serial_device_remove(struct device *dev) | |||
96 | if (!port) | 103 | if (!port) |
97 | return -ENODEV; | 104 | return -ENODEV; |
98 | 105 | ||
106 | /* make sure suspend/resume doesn't race against port_remove */ | ||
107 | usb_autopm_get_interface(port->serial->interface); | ||
108 | |||
99 | device_remove_file(&port->dev, &dev_attr_port_number); | 109 | device_remove_file(&port->dev, &dev_attr_port_number); |
100 | 110 | ||
101 | driver = port->serial->type; | 111 | driver = port->serial->type; |
@@ -107,6 +117,7 @@ static int usb_serial_device_remove(struct device *dev) | |||
107 | dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", | 117 | dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", |
108 | driver->description, minor); | 118 | driver->description, minor); |
109 | 119 | ||
120 | usb_autopm_put_interface(port->serial->interface); | ||
110 | return retval; | 121 | return retval; |
111 | } | 122 | } |
112 | 123 | ||