aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2009-09-01 11:38:44 -0400
committerLive-CD User <linux@linux.site>2009-09-19 16:13:39 -0400
commitf5b0953a89fa3407fb293cc54ead7d8feec489e4 (patch)
tree1cbf21925532e4a88b71b722756c80690d52aac2 /drivers/usb
parent41bd34ddd7aa46dbc03b5bb33896e0fa8100fe7b (diff)
usb-serial: put subroutines in logical order
This patch (as1285) rearranges the subroutines in usb-serial.c concerned with tty lifetimes into a more logical order: install, open, hangup, close, release. It also updates the formatting of the kerneldoc comments. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/usb-serial.c154
1 files changed, 77 insertions, 77 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index f1a1f0fb6d1b..266dc583867b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -166,6 +166,41 @@ void usb_serial_put(struct usb_serial *serial)
166/***************************************************************************** 166/*****************************************************************************
167 * Driver tty interface functions 167 * Driver tty interface functions
168 *****************************************************************************/ 168 *****************************************************************************/
169
170/**
171 * serial_install - install tty
172 * @driver: the driver (USB in our case)
173 * @tty: the tty being created
174 *
175 * Create the termios objects for this tty. We use the default
176 * USB serial settings but permit them to be overridden by
177 * serial->type->init_termios.
178 */
179static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
180{
181 int idx = tty->index;
182 struct usb_serial *serial;
183 int retval;
184
185 /* If the termios setup has yet to be done */
186 if (tty->driver->termios[idx] == NULL) {
187 /* perform the standard setup */
188 retval = tty_init_termios(tty);
189 if (retval)
190 return retval;
191 /* allow the driver to update it */
192 serial = usb_serial_get_by_index(tty->index);
193 if (serial->type->init_termios)
194 serial->type->init_termios(tty);
195 usb_serial_put(serial);
196 }
197 /* Final install (we use the default method) */
198 tty_driver_kref_get(driver);
199 tty->count++;
200 driver->ttys[idx] = tty;
201 return 0;
202}
203
169static int serial_open (struct tty_struct *tty, struct file *filp) 204static int serial_open (struct tty_struct *tty, struct file *filp)
170{ 205{
171 struct usb_serial *serial; 206 struct usb_serial *serial;
@@ -264,13 +299,11 @@ bailout_serial_put:
264} 299}
265 300
266/** 301/**
267 * serial_do_down - shut down hardware 302 * serial_do_down - shut down hardware
268 * @port: port to shut down 303 * @port: port to shut down
269 * 304 *
270 * Shut down a USB port unless it is the console. We never shut down the 305 * Shut down a USB serial port unless it is the console. We never
271 * console hardware as it will always be in use. 306 * shut down the console hardware as it will always be in use.
272 *
273 * Don't free any resources at this point
274 */ 307 */
275static void serial_do_down(struct usb_serial_port *port) 308static void serial_do_down(struct usb_serial_port *port)
276{ 309{
@@ -278,8 +311,10 @@ static void serial_do_down(struct usb_serial_port *port)
278 struct usb_serial *serial; 311 struct usb_serial *serial;
279 struct module *owner; 312 struct module *owner;
280 313
281 /* The console is magical, do not hang up the console hardware 314 /*
282 or there will be tears */ 315 * The console is magical. Do not hang up the console hardware
316 * or there will be tears.
317 */
283 if (port->console) 318 if (port->console)
284 return; 319 return;
285 320
@@ -293,24 +328,50 @@ static void serial_do_down(struct usb_serial_port *port)
293 mutex_unlock(&port->mutex); 328 mutex_unlock(&port->mutex);
294} 329}
295 330
331static void serial_hangup(struct tty_struct *tty)
332{
333 struct usb_serial_port *port = tty->driver_data;
334 serial_do_down(port);
335 tty_port_hangup(&port->port);
336 /* We must not free port yet - the USB serial layer depends on it's
337 continued existence */
338}
339
340static void serial_close(struct tty_struct *tty, struct file *filp)
341{
342 struct usb_serial_port *port = tty->driver_data;
343
344 if (!port)
345 return;
346
347 dbg("%s - port %d", __func__, port->number);
348
349 if (tty_port_close_start(&port->port, tty, filp) == 0)
350 return;
351 serial_do_down(port);
352 tty_port_close_end(&port->port, tty);
353 tty_port_tty_set(&port->port, NULL);
354
355}
356
296/** 357/**
297 * serial_do_free - free resources post close/hangup 358 * serial_do_free - free resources post close/hangup
298 * @port: port to free up 359 * @port: port to free up
299 * 360 *
300 * Do the resource freeing and refcount dropping for the port. We must 361 * Do the resource freeing and refcount dropping for the port.
301 * be careful about ordering and we must avoid freeing up the console. 362 * Avoid freeing the console.
302 * 363 *
303 * Called when the last tty kref is dropped. 364 * Called when the last tty kref is dropped.
304 */ 365 */
305
306static void serial_do_free(struct tty_struct *tty) 366static void serial_do_free(struct tty_struct *tty)
307{ 367{
308 struct usb_serial_port *port = tty->driver_data; 368 struct usb_serial_port *port = tty->driver_data;
309 struct usb_serial *serial; 369 struct usb_serial *serial;
310 struct module *owner; 370 struct module *owner;
311 371
312 /* The console is magical, do not hang up the console hardware 372 /* The console is magical. Do not hang up the console hardware
313 or there will be tears */ 373 * or there will be tears.
374 */
314 if (port == NULL || port->console) 375 if (port == NULL || port->console)
315 return; 376 return;
316 377
@@ -326,32 +387,6 @@ static void serial_do_free(struct tty_struct *tty)
326 module_put(owner); 387 module_put(owner);
327} 388}
328 389
329static void serial_close(struct tty_struct *tty, struct file *filp)
330{
331 struct usb_serial_port *port = tty->driver_data;
332
333 if (!port)
334 return;
335
336 dbg("%s - port %d", __func__, port->number);
337
338 if (tty_port_close_start(&port->port, tty, filp) == 0)
339 return;
340 serial_do_down(port);
341 tty_port_close_end(&port->port, tty);
342 tty_port_tty_set(&port->port, NULL);
343
344}
345
346static void serial_hangup(struct tty_struct *tty)
347{
348 struct usb_serial_port *port = tty->driver_data;
349 serial_do_down(port);
350 tty_port_hangup(&port->port);
351 /* We must not free port yet - the USB serial layer depends on it's
352 continued existence */
353}
354
355static int serial_write(struct tty_struct *tty, const unsigned char *buf, 390static int serial_write(struct tty_struct *tty, const unsigned char *buf,
356 int count) 391 int count)
357{ 392{
@@ -699,41 +734,6 @@ static const struct tty_port_operations serial_port_ops = {
699 .dtr_rts = serial_dtr_rts, 734 .dtr_rts = serial_dtr_rts,
700}; 735};
701 736
702/**
703 * serial_install - install tty
704 * @driver: the driver (USB in our case)
705 * @tty: the tty being created
706 *
707 * Create the termios objects for this tty. We use the default USB
708 * serial ones but permit them to be overriddenby serial->type->termios.
709 * This lets us remove all the ugly hackery
710 */
711
712static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
713{
714 int idx = tty->index;
715 struct usb_serial *serial;
716 int retval;
717
718 /* If the termios setup has yet to be done */
719 if (tty->driver->termios[idx] == NULL) {
720 /* perform the standard setup */
721 retval = tty_init_termios(tty);
722 if (retval)
723 return retval;
724 /* allow the driver to update it */
725 serial = usb_serial_get_by_index(tty->index);
726 if (serial->type->init_termios)
727 serial->type->init_termios(tty);
728 usb_serial_put(serial);
729 }
730 /* Final install (we use the default method) */
731 tty_driver_kref_get(driver);
732 tty->count++;
733 driver->ttys[idx] = tty;
734 return 0;
735}
736
737int usb_serial_probe(struct usb_interface *interface, 737int usb_serial_probe(struct usb_interface *interface,
738 const struct usb_device_id *id) 738 const struct usb_device_id *id)
739{ 739{