aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/usb-serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r--drivers/usb/serial/usb-serial.c408
1 files changed, 187 insertions, 221 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 99188c92068b..ff75a3589e7e 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -35,6 +35,7 @@
35#include <linux/serial.h> 35#include <linux/serial.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/usb/serial.h> 37#include <linux/usb/serial.h>
38#include <linux/kfifo.h>
38#include "pl2303.h" 39#include "pl2303.h"
39 40
40/* 41/*
@@ -43,8 +44,6 @@
43#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" 44#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/"
44#define DRIVER_DESC "USB Serial Driver core" 45#define DRIVER_DESC "USB Serial Driver core"
45 46
46static void port_free(struct usb_serial_port *port);
47
48/* Driver structure we register with the USB core */ 47/* Driver structure we register with the USB core */
49static struct usb_driver usb_serial_driver = { 48static struct usb_driver usb_serial_driver = {
50 .name = "usbserial", 49 .name = "usbserial",
@@ -68,6 +67,11 @@ static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
68static DEFINE_MUTEX(table_lock); 67static DEFINE_MUTEX(table_lock);
69static LIST_HEAD(usb_serial_driver_list); 68static LIST_HEAD(usb_serial_driver_list);
70 69
70/*
71 * Look up the serial structure. If it is found and it hasn't been
72 * disconnected, return with its disc_mutex held and its refcount
73 * incremented. Otherwise return NULL.
74 */
71struct usb_serial *usb_serial_get_by_index(unsigned index) 75struct usb_serial *usb_serial_get_by_index(unsigned index)
72{ 76{
73 struct usb_serial *serial; 77 struct usb_serial *serial;
@@ -75,8 +79,15 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
75 mutex_lock(&table_lock); 79 mutex_lock(&table_lock);
76 serial = serial_table[index]; 80 serial = serial_table[index];
77 81
78 if (serial) 82 if (serial) {
79 kref_get(&serial->kref); 83 mutex_lock(&serial->disc_mutex);
84 if (serial->disconnected) {
85 mutex_unlock(&serial->disc_mutex);
86 serial = NULL;
87 } else {
88 kref_get(&serial->kref);
89 }
90 }
80 mutex_unlock(&table_lock); 91 mutex_unlock(&table_lock);
81 return serial; 92 return serial;
82} 93}
@@ -125,8 +136,10 @@ static void return_serial(struct usb_serial *serial)
125 136
126 dbg("%s", __func__); 137 dbg("%s", __func__);
127 138
139 mutex_lock(&table_lock);
128 for (i = 0; i < serial->num_ports; ++i) 140 for (i = 0; i < serial->num_ports; ++i)
129 serial_table[serial->minor + i] = NULL; 141 serial_table[serial->minor + i] = NULL;
142 mutex_unlock(&table_lock);
130} 143}
131 144
132static void destroy_serial(struct kref *kref) 145static void destroy_serial(struct kref *kref)
@@ -145,244 +158,224 @@ static void destroy_serial(struct kref *kref)
145 158
146 serial->type->release(serial); 159 serial->type->release(serial);
147 160
148 for (i = 0; i < serial->num_ports; ++i) { 161 /* Now that nothing is using the ports, they can be freed */
162 for (i = 0; i < serial->num_port_pointers; ++i) {
149 port = serial->port[i]; 163 port = serial->port[i];
150 if (port) 164 if (port) {
165 port->serial = NULL;
151 put_device(&port->dev); 166 put_device(&port->dev);
152 }
153
154 /* If this is a "fake" port, we have to clean it up here, as it will
155 * not get cleaned up in port_release() as it was never registered with
156 * the driver core */
157 if (serial->num_ports < serial->num_port_pointers) {
158 for (i = serial->num_ports;
159 i < serial->num_port_pointers; ++i) {
160 port = serial->port[i];
161 if (port)
162 port_free(port);
163 } 167 }
164 } 168 }
165 169
166 usb_put_dev(serial->dev); 170 usb_put_dev(serial->dev);
167
168 /* free up any memory that we allocated */
169 kfree(serial); 171 kfree(serial);
170} 172}
171 173
172void usb_serial_put(struct usb_serial *serial) 174void usb_serial_put(struct usb_serial *serial)
173{ 175{
174 mutex_lock(&table_lock);
175 kref_put(&serial->kref, destroy_serial); 176 kref_put(&serial->kref, destroy_serial);
176 mutex_unlock(&table_lock);
177} 177}
178 178
179/***************************************************************************** 179/*****************************************************************************
180 * Driver tty interface functions 180 * Driver tty interface functions
181 *****************************************************************************/ 181 *****************************************************************************/
182static int serial_open (struct tty_struct *tty, struct file *filp) 182
183/**
184 * serial_install - install tty
185 * @driver: the driver (USB in our case)
186 * @tty: the tty being created
187 *
188 * Create the termios objects for this tty. We use the default
189 * USB serial settings but permit them to be overridden by
190 * serial->type->init_termios.
191 *
192 * This is the first place a new tty gets used. Hence this is where we
193 * acquire references to the usb_serial structure and the driver module,
194 * where we store a pointer to the port, and where we do an autoresume.
195 * All these actions are reversed in serial_release().
196 */
197static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
183{ 198{
199 int idx = tty->index;
184 struct usb_serial *serial; 200 struct usb_serial *serial;
185 struct usb_serial_port *port; 201 struct usb_serial_port *port;
186 unsigned int portNumber; 202 int retval = -ENODEV;
187 int retval = 0;
188 int first = 0;
189 203
190 dbg("%s", __func__); 204 dbg("%s", __func__);
191 205
192 /* get the serial object associated with this tty pointer */ 206 serial = usb_serial_get_by_index(idx);
193 serial = usb_serial_get_by_index(tty->index); 207 if (!serial)
194 if (!serial) { 208 return retval;
195 tty->driver_data = NULL;
196 return -ENODEV;
197 }
198 209
199 mutex_lock(&serial->disc_mutex); 210 port = serial->port[idx - serial->minor];
200 portNumber = tty->index - serial->minor; 211 if (!port)
201 port = serial->port[portNumber]; 212 goto error_no_port;
202 if (!port || serial->disconnected) 213 if (!try_module_get(serial->type->driver.owner))
203 retval = -ENODEV; 214 goto error_module_get;
204 else 215
205 get_device(&port->dev); 216 /* perform the standard setup */
206 /* 217 retval = tty_init_termios(tty);
207 * Note: Our locking order requirement does not allow port->mutex
208 * to be acquired while serial->disc_mutex is held.
209 */
210 mutex_unlock(&serial->disc_mutex);
211 if (retval) 218 if (retval)
212 goto bailout_serial_put; 219 goto error_init_termios;
213 220
214 if (mutex_lock_interruptible(&port->mutex)) { 221 retval = usb_autopm_get_interface(serial->interface);
215 retval = -ERESTARTSYS; 222 if (retval)
216 goto bailout_port_put; 223 goto error_get_interface;
217 }
218 224
219 ++port->port.count; 225 mutex_unlock(&serial->disc_mutex);
226
227 /* allow the driver to update the settings */
228 if (serial->type->init_termios)
229 serial->type->init_termios(tty);
220 230
221 /* set up our port structure making the tty driver
222 * remember our port object, and us it */
223 tty->driver_data = port; 231 tty->driver_data = port;
224 tty_port_tty_set(&port->port, tty);
225 232
226 /* If the console is attached, the device is already open */ 233 /* Final install (we use the default method) */
227 if (port->port.count == 1 && !port->console) { 234 tty_driver_kref_get(driver);
228 first = 1; 235 tty->count++;
229 /* lock this module before we call it 236 driver->ttys[idx] = tty;
230 * this may fail, which means we must bail out, 237 return retval;
231 * safe because we are called with BKL held */ 238
232 if (!try_module_get(serial->type->driver.owner)) { 239 error_get_interface:
233 retval = -ENODEV; 240 error_init_termios:
234 goto bailout_mutex_unlock; 241 module_put(serial->type->driver.owner);
235 } 242 error_module_get:
243 error_no_port:
244 usb_serial_put(serial);
245 mutex_unlock(&serial->disc_mutex);
246 return retval;
247}
236 248
249static int serial_open(struct tty_struct *tty, struct file *filp)
250{
251 struct usb_serial_port *port = tty->driver_data;
252 struct usb_serial *serial = port->serial;
253 int retval;
254
255 dbg("%s - port %d", __func__, port->number);
256
257 spin_lock_irq(&port->port.lock);
258 if (!tty_hung_up_p(filp))
259 ++port->port.count;
260 spin_unlock_irq(&port->port.lock);
261 tty_port_tty_set(&port->port, tty);
262
263 /* Do the device-specific open only if the hardware isn't
264 * already initialized.
265 */
266 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
267 if (mutex_lock_interruptible(&port->mutex))
268 return -ERESTARTSYS;
237 mutex_lock(&serial->disc_mutex); 269 mutex_lock(&serial->disc_mutex);
238 if (serial->disconnected) 270 if (serial->disconnected)
239 retval = -ENODEV; 271 retval = -ENODEV;
240 else 272 else
241 retval = usb_autopm_get_interface(serial->interface); 273 retval = port->serial->type->open(tty, port);
242 if (retval)
243 goto bailout_module_put;
244
245 /* only call the device specific open if this
246 * is the first time the port is opened */
247 retval = serial->type->open(tty, port, filp);
248 if (retval)
249 goto bailout_interface_put;
250 mutex_unlock(&serial->disc_mutex); 274 mutex_unlock(&serial->disc_mutex);
275 mutex_unlock(&port->mutex);
276 if (retval)
277 return retval;
251 set_bit(ASYNCB_INITIALIZED, &port->port.flags); 278 set_bit(ASYNCB_INITIALIZED, &port->port.flags);
252 } 279 }
253 mutex_unlock(&port->mutex); 280
254 /* Now do the correct tty layer semantics */ 281 /* Now do the correct tty layer semantics */
255 retval = tty_port_block_til_ready(&port->port, tty, filp); 282 retval = tty_port_block_til_ready(&port->port, tty, filp);
256 if (retval == 0) {
257 if (!first)
258 usb_serial_put(serial);
259 return 0;
260 }
261 mutex_lock(&port->mutex);
262 if (first == 0)
263 goto bailout_mutex_unlock;
264 /* Undo the initial port actions */
265 mutex_lock(&serial->disc_mutex);
266bailout_interface_put:
267 usb_autopm_put_interface(serial->interface);
268bailout_module_put:
269 mutex_unlock(&serial->disc_mutex);
270 module_put(serial->type->driver.owner);
271bailout_mutex_unlock:
272 port->port.count = 0;
273 tty->driver_data = NULL;
274 tty_port_tty_set(&port->port, NULL);
275 mutex_unlock(&port->mutex);
276bailout_port_put:
277 put_device(&port->dev);
278bailout_serial_put:
279 usb_serial_put(serial);
280 return retval; 283 return retval;
281} 284}
282 285
283/** 286/**
284 * serial_do_down - shut down hardware 287 * serial_down - shut down hardware
285 * @port: port to shut down 288 * @port: port to shut down
286 *
287 * Shut down a USB port unless it is the console. We never shut down the
288 * console hardware as it will always be in use.
289 * 289 *
290 * Don't free any resources at this point 290 * Shut down a USB serial port unless it is the console. We never
291 * shut down the console hardware as it will always be in use.
291 */ 292 */
292static void serial_do_down(struct usb_serial_port *port) 293static void serial_down(struct usb_serial_port *port)
293{ 294{
294 struct usb_serial_driver *drv = port->serial->type; 295 struct usb_serial_driver *drv = port->serial->type;
295 struct usb_serial *serial;
296 struct module *owner;
297 296
298 /* The console is magical, do not hang up the console hardware 297 /*
299 or there will be tears */ 298 * The console is magical. Do not hang up the console hardware
299 * or there will be tears.
300 */
300 if (port->console) 301 if (port->console)
301 return; 302 return;
302 303
303 mutex_lock(&port->mutex); 304 /* Don't call the close method if the hardware hasn't been
304 serial = port->serial; 305 * initialized.
305 owner = serial->type->driver.owner; 306 */
307 if (!test_and_clear_bit(ASYNCB_INITIALIZED, &port->port.flags))
308 return;
306 309
310 mutex_lock(&port->mutex);
307 if (drv->close) 311 if (drv->close)
308 drv->close(port); 312 drv->close(port);
309
310 mutex_unlock(&port->mutex); 313 mutex_unlock(&port->mutex);
311} 314}
312 315
313/** 316static void serial_hangup(struct tty_struct *tty)
314 * serial_do_free - free resources post close/hangup
315 * @port: port to free up
316 *
317 * Do the resource freeing and refcount dropping for the port. We must
318 * be careful about ordering and we must avoid freeing up the console.
319 */
320
321static void serial_do_free(struct usb_serial_port *port)
322{ 317{
323 struct usb_serial *serial; 318 struct usb_serial_port *port = tty->driver_data;
324 struct module *owner;
325 319
326 /* The console is magical, do not hang up the console hardware 320 dbg("%s - port %d", __func__, port->number);
327 or there will be tears */
328 if (port->console)
329 return;
330 321
331 serial = port->serial; 322 serial_down(port);
332 owner = serial->type->driver.owner; 323 tty_port_hangup(&port->port);
333 put_device(&port->dev);
334 /* Mustn't dereference port any more */
335 mutex_lock(&serial->disc_mutex);
336 if (!serial->disconnected)
337 usb_autopm_put_interface(serial->interface);
338 mutex_unlock(&serial->disc_mutex);
339 usb_serial_put(serial);
340 /* Mustn't dereference serial any more */
341 module_put(owner);
342} 324}
343 325
344static void serial_close(struct tty_struct *tty, struct file *filp) 326static void serial_close(struct tty_struct *tty, struct file *filp)
345{ 327{
346 struct usb_serial_port *port = tty->driver_data; 328 struct usb_serial_port *port = tty->driver_data;
347 329
348 if (!port)
349 return;
350
351 dbg("%s - port %d", __func__, port->number); 330 dbg("%s - port %d", __func__, port->number);
352 331
353 /* FIXME: 332 if (tty_hung_up_p(filp))
354 This leaves a very narrow race. Really we should do the
355 serial_do_free() on tty->shutdown(), but tty->shutdown can
356 be called from IRQ context and serial_do_free can sleep.
357
358 The right fix is probably to make the tty free (which is rare)
359 and thus tty->shutdown() occur via a work queue and simplify all
360 the drivers that use it.
361 */
362 if (tty_hung_up_p(filp)) {
363 /* serial_hangup already called serial_down at this point.
364 Another user may have already reopened the port but
365 serial_do_free is refcounted */
366 serial_do_free(port);
367 return; 333 return;
368 }
369
370 if (tty_port_close_start(&port->port, tty, filp) == 0) 334 if (tty_port_close_start(&port->port, tty, filp) == 0)
371 return; 335 return;
372 336 serial_down(port);
373 serial_do_down(port);
374 tty_port_close_end(&port->port, tty); 337 tty_port_close_end(&port->port, tty);
375 tty_port_tty_set(&port->port, NULL); 338 tty_port_tty_set(&port->port, NULL);
376 serial_do_free(port);
377} 339}
378 340
379static void serial_hangup(struct tty_struct *tty) 341/**
342 * serial_release - free resources post close/hangup
343 * @port: port to free up
344 *
345 * Do the resource freeing and refcount dropping for the port.
346 * Avoid freeing the console.
347 *
348 * Called when the last tty kref is dropped.
349 */
350static void serial_release(struct tty_struct *tty)
380{ 351{
381 struct usb_serial_port *port = tty->driver_data; 352 struct usb_serial_port *port = tty->driver_data;
382 serial_do_down(port); 353 struct usb_serial *serial;
383 tty_port_hangup(&port->port); 354 struct module *owner;
384 /* We must not free port yet - the USB serial layer depends on it's 355
385 continued existence */ 356 /* The console is magical. Do not hang up the console hardware
357 * or there will be tears.
358 */
359 if (port->console)
360 return;
361
362 dbg("%s - port %d", __func__, port->number);
363
364 /* Standard shutdown processing */
365 tty_shutdown(tty);
366
367 tty->driver_data = NULL;
368
369 serial = port->serial;
370 owner = serial->type->driver.owner;
371
372 mutex_lock(&serial->disc_mutex);
373 if (!serial->disconnected)
374 usb_autopm_put_interface(serial->interface);
375 mutex_unlock(&serial->disc_mutex);
376
377 usb_serial_put(serial);
378 module_put(owner);
386} 379}
387 380
388static int serial_write(struct tty_struct *tty, const unsigned char *buf, 381static int serial_write(struct tty_struct *tty, const unsigned char *buf,
@@ -527,6 +520,7 @@ static int serial_proc_show(struct seq_file *m, void *v)
527 520
528 seq_putc(m, '\n'); 521 seq_putc(m, '\n');
529 usb_serial_put(serial); 522 usb_serial_put(serial);
523 mutex_unlock(&serial->disc_mutex);
530 } 524 }
531 return 0; 525 return 0;
532} 526}
@@ -596,14 +590,6 @@ static void usb_serial_port_work(struct work_struct *work)
596 tty_kref_put(tty); 590 tty_kref_put(tty);
597} 591}
598 592
599static void port_release(struct device *dev)
600{
601 struct usb_serial_port *port = to_usb_serial_port(dev);
602
603 dbg ("%s - %s", __func__, dev_name(dev));
604 port_free(port);
605}
606
607static void kill_traffic(struct usb_serial_port *port) 593static void kill_traffic(struct usb_serial_port *port)
608{ 594{
609 usb_kill_urb(port->read_urb); 595 usb_kill_urb(port->read_urb);
@@ -623,8 +609,12 @@ static void kill_traffic(struct usb_serial_port *port)
623 usb_kill_urb(port->interrupt_out_urb); 609 usb_kill_urb(port->interrupt_out_urb);
624} 610}
625 611
626static void port_free(struct usb_serial_port *port) 612static void port_release(struct device *dev)
627{ 613{
614 struct usb_serial_port *port = to_usb_serial_port(dev);
615
616 dbg ("%s - %s", __func__, dev_name(dev));
617
628 /* 618 /*
629 * Stop all the traffic before cancelling the work, so that 619 * Stop all the traffic before cancelling the work, so that
630 * nobody will restart it by calling usb_serial_port_softint. 620 * nobody will restart it by calling usb_serial_port_softint.
@@ -636,6 +626,8 @@ static void port_free(struct usb_serial_port *port)
636 usb_free_urb(port->write_urb); 626 usb_free_urb(port->write_urb);
637 usb_free_urb(port->interrupt_in_urb); 627 usb_free_urb(port->interrupt_in_urb);
638 usb_free_urb(port->interrupt_out_urb); 628 usb_free_urb(port->interrupt_out_urb);
629 if (!IS_ERR(port->write_fifo) && port->write_fifo)
630 kfifo_free(port->write_fifo);
639 kfree(port->bulk_in_buffer); 631 kfree(port->bulk_in_buffer);
640 kfree(port->bulk_out_buffer); 632 kfree(port->bulk_out_buffer);
641 kfree(port->interrupt_in_buffer); 633 kfree(port->interrupt_in_buffer);
@@ -935,6 +927,11 @@ int usb_serial_probe(struct usb_interface *interface,
935 mutex_init(&port->mutex); 927 mutex_init(&port->mutex);
936 INIT_WORK(&port->work, usb_serial_port_work); 928 INIT_WORK(&port->work, usb_serial_port_work);
937 serial->port[i] = port; 929 serial->port[i] = port;
930 port->dev.parent = &interface->dev;
931 port->dev.driver = NULL;
932 port->dev.bus = &usb_serial_bus_type;
933 port->dev.release = &port_release;
934 device_initialize(&port->dev);
938 } 935 }
939 936
940 /* set up the endpoint information */ 937 /* set up the endpoint information */
@@ -970,6 +967,10 @@ int usb_serial_probe(struct usb_interface *interface,
970 dev_err(&interface->dev, "No free urbs available\n"); 967 dev_err(&interface->dev, "No free urbs available\n");
971 goto probe_error; 968 goto probe_error;
972 } 969 }
970 port->write_fifo = kfifo_alloc(PAGE_SIZE, GFP_KERNEL,
971 &port->lock);
972 if (IS_ERR(port->write_fifo))
973 goto probe_error;
973 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 974 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
974 port->bulk_out_size = buffer_size; 975 port->bulk_out_size = buffer_size;
975 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 976 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
@@ -1077,15 +1078,10 @@ int usb_serial_probe(struct usb_interface *interface,
1077 /* register all of the individual ports with the driver core */ 1078 /* register all of the individual ports with the driver core */
1078 for (i = 0; i < num_ports; ++i) { 1079 for (i = 0; i < num_ports; ++i) {
1079 port = serial->port[i]; 1080 port = serial->port[i];
1080 port->dev.parent = &interface->dev;
1081 port->dev.driver = NULL;
1082 port->dev.bus = &usb_serial_bus_type;
1083 port->dev.release = &port_release;
1084
1085 dev_set_name(&port->dev, "ttyUSB%d", port->number); 1081 dev_set_name(&port->dev, "ttyUSB%d", port->number);
1086 dbg ("%s - registering %s", __func__, dev_name(&port->dev)); 1082 dbg ("%s - registering %s", __func__, dev_name(&port->dev));
1087 port->dev_state = PORT_REGISTERING; 1083 port->dev_state = PORT_REGISTERING;
1088 retval = device_register(&port->dev); 1084 retval = device_add(&port->dev);
1089 if (retval) { 1085 if (retval) {
1090 dev_err(&port->dev, "Error registering port device, " 1086 dev_err(&port->dev, "Error registering port device, "
1091 "continuing\n"); 1087 "continuing\n");
@@ -1103,39 +1099,7 @@ exit:
1103 return 0; 1099 return 0;
1104 1100
1105probe_error: 1101probe_error:
1106 for (i = 0; i < num_bulk_in; ++i) { 1102 usb_serial_put(serial);
1107 port = serial->port[i];
1108 if (!port)
1109 continue;
1110 usb_free_urb(port->read_urb);
1111 kfree(port->bulk_in_buffer);
1112 }
1113 for (i = 0; i < num_bulk_out; ++i) {
1114 port = serial->port[i];
1115 if (!port)
1116 continue;
1117 usb_free_urb(port->write_urb);
1118 kfree(port->bulk_out_buffer);
1119 }
1120 for (i = 0; i < num_interrupt_in; ++i) {
1121 port = serial->port[i];
1122 if (!port)
1123 continue;
1124 usb_free_urb(port->interrupt_in_urb);
1125 kfree(port->interrupt_in_buffer);
1126 }
1127 for (i = 0; i < num_interrupt_out; ++i) {
1128 port = serial->port[i];
1129 if (!port)
1130 continue;
1131 usb_free_urb(port->interrupt_out_urb);
1132 kfree(port->interrupt_out_buffer);
1133 }
1134
1135 /* free up any memory that we allocated */
1136 for (i = 0; i < serial->num_port_pointers; ++i)
1137 kfree(serial->port[i]);
1138 kfree(serial);
1139 return -EIO; 1103 return -EIO;
1140} 1104}
1141EXPORT_SYMBOL_GPL(usb_serial_probe); 1105EXPORT_SYMBOL_GPL(usb_serial_probe);
@@ -1161,10 +1125,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1161 if (port) { 1125 if (port) {
1162 struct tty_struct *tty = tty_port_tty_get(&port->port); 1126 struct tty_struct *tty = tty_port_tty_get(&port->port);
1163 if (tty) { 1127 if (tty) {
1164 /* The hangup will occur asynchronously but 1128 tty_vhangup(tty);
1165 the object refcounts will sort out all the
1166 cleanup */
1167 tty_hangup(tty);
1168 tty_kref_put(tty); 1129 tty_kref_put(tty);
1169 } 1130 }
1170 kill_traffic(port); 1131 kill_traffic(port);
@@ -1189,8 +1150,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1189 } 1150 }
1190 serial->type->disconnect(serial); 1151 serial->type->disconnect(serial);
1191 1152
1192 /* let the last holder of this object 1153 /* let the last holder of this object cause it to be cleaned up */
1193 * cause it to be cleaned up */
1194 usb_serial_put(serial); 1154 usb_serial_put(serial);
1195 dev_info(dev, "device disconnected\n"); 1155 dev_info(dev, "device disconnected\n");
1196} 1156}
@@ -1204,15 +1164,19 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1204 1164
1205 serial->suspending = 1; 1165 serial->suspending = 1;
1206 1166
1167 if (serial->type->suspend) {
1168 r = serial->type->suspend(serial, message);
1169 if (r < 0)
1170 goto err_out;
1171 }
1172
1207 for (i = 0; i < serial->num_ports; ++i) { 1173 for (i = 0; i < serial->num_ports; ++i) {
1208 port = serial->port[i]; 1174 port = serial->port[i];
1209 if (port) 1175 if (port)
1210 kill_traffic(port); 1176 kill_traffic(port);
1211 } 1177 }
1212 1178
1213 if (serial->type->suspend) 1179err_out:
1214 r = serial->type->suspend(serial, message);
1215
1216 return r; 1180 return r;
1217} 1181}
1218EXPORT_SYMBOL(usb_serial_suspend); 1182EXPORT_SYMBOL(usb_serial_suspend);
@@ -1246,6 +1210,8 @@ static const struct tty_operations serial_ops = {
1246 .chars_in_buffer = serial_chars_in_buffer, 1210 .chars_in_buffer = serial_chars_in_buffer,
1247 .tiocmget = serial_tiocmget, 1211 .tiocmget = serial_tiocmget,
1248 .tiocmset = serial_tiocmset, 1212 .tiocmset = serial_tiocmset,
1213 .shutdown = serial_release,
1214 .install = serial_install,
1249 .proc_fops = &serial_proc_fops, 1215 .proc_fops = &serial_proc_fops,
1250}; 1216};
1251 1217