aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:12:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:24 -0400
commita8d6f0a9c4c9af0e478383d870e828693e983dfb (patch)
treee38f8a99ce825832491e134db15b421b6f0d9747
parentd60d43965e46674b9097b422336a55c6ca08559a (diff)
usb-serial: Coding style
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/usb/serial/usb-serial.c304
1 files changed, 164 insertions, 140 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index ffaed8ace066..51917b0f079a 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -12,7 +12,8 @@
12 * This driver was originally based on the ACM driver by Armin Fuerst (which was 12 * This driver was originally based on the ACM driver by Armin Fuerst (which was
13 * based on a driver by Brad Keryan) 13 * based on a driver by Brad Keryan)
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver
16 * 17 *
17 */ 18 */
18 19
@@ -28,7 +29,7 @@
28#include <linux/spinlock.h> 29#include <linux/spinlock.h>
29#include <linux/mutex.h> 30#include <linux/mutex.h>
30#include <linux/list.h> 31#include <linux/list.h>
31#include <asm/uaccess.h> 32#include <linux/uaccess.h>
32#include <linux/usb.h> 33#include <linux/usb.h>
33#include <linux/usb/serial.h> 34#include <linux/usb/serial.h>
34#include "pl2303.h" 35#include "pl2303.h"
@@ -59,7 +60,8 @@ static struct usb_driver usb_serial_driver = {
59*/ 60*/
60 61
61static int debug; 62static int debug;
62static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ 63/* initially all NULL */
64static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
63static DEFINE_MUTEX(table_lock); 65static DEFINE_MUTEX(table_lock);
64static LIST_HEAD(usb_serial_driver_list); 66static LIST_HEAD(usb_serial_driver_list);
65 67
@@ -76,7 +78,8 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
76 return serial; 78 return serial;
77} 79}
78 80
79static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor) 81static struct usb_serial *get_free_serial(struct usb_serial *serial,
82 int num_ports, unsigned int *minor)
80{ 83{
81 unsigned int i, j; 84 unsigned int i, j;
82 int good_spot; 85 int good_spot;
@@ -122,9 +125,8 @@ static void return_serial(struct usb_serial *serial)
122 if (serial == NULL) 125 if (serial == NULL)
123 return; 126 return;
124 127
125 for (i = 0; i < serial->num_ports; ++i) { 128 for (i = 0; i < serial->num_ports; ++i)
126 serial_table[serial->minor + i] = NULL; 129 serial_table[serial->minor + i] = NULL;
127 }
128} 130}
129 131
130static void destroy_serial(struct kref *kref) 132static void destroy_serial(struct kref *kref)
@@ -156,7 +158,8 @@ static void destroy_serial(struct kref *kref)
156 * not get cleaned up in port_release() as it was never registered with 158 * not get cleaned up in port_release() as it was never registered with
157 * the driver core */ 159 * the driver core */
158 if (serial->num_ports < serial->num_port_pointers) { 160 if (serial->num_ports < serial->num_port_pointers) {
159 for (i = serial->num_ports; i < serial->num_port_pointers; ++i) { 161 for (i = serial->num_ports;
162 i < serial->num_port_pointers; ++i) {
160 port = serial->port[i]; 163 port = serial->port[i];
161 if (!port) 164 if (!port)
162 continue; 165 continue;
@@ -167,7 +170,7 @@ static void destroy_serial(struct kref *kref)
167 usb_put_dev(serial->dev); 170 usb_put_dev(serial->dev);
168 171
169 /* free up any memory that we allocated */ 172 /* free up any memory that we allocated */
170 kfree (serial); 173 kfree(serial);
171} 174}
172 175
173void usb_serial_put(struct usb_serial *serial) 176void usb_serial_put(struct usb_serial *serial)
@@ -180,13 +183,13 @@ void usb_serial_put(struct usb_serial *serial)
180/***************************************************************************** 183/*****************************************************************************
181 * Driver tty interface functions 184 * Driver tty interface functions
182 *****************************************************************************/ 185 *****************************************************************************/
183static int serial_open (struct tty_struct *tty, struct file * filp) 186static int serial_open (struct tty_struct *tty, struct file *filp)
184{ 187{
185 struct usb_serial *serial; 188 struct usb_serial *serial;
186 struct usb_serial_port *port; 189 struct usb_serial_port *port;
187 unsigned int portNumber; 190 unsigned int portNumber;
188 int retval; 191 int retval;
189 192
190 dbg("%s", __func__); 193 dbg("%s", __func__);
191 194
192 /* get the serial object associated with this tty pointer */ 195 /* get the serial object associated with this tty pointer */
@@ -207,7 +210,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
207 retval = -ERESTARTSYS; 210 retval = -ERESTARTSYS;
208 goto bailout_kref_put; 211 goto bailout_kref_put;
209 } 212 }
210 213
211 ++port->port.count; 214 ++port->port.count;
212 215
213 /* set up our port structure making the tty driver 216 /* set up our port structure making the tty driver
@@ -228,7 +231,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
228 retval = usb_autopm_get_interface(serial->interface); 231 retval = usb_autopm_get_interface(serial->interface);
229 if (retval) 232 if (retval)
230 goto bailout_module_put; 233 goto bailout_module_put;
231 /* only call the device specific open if this 234 /* only call the device specific open if this
232 * is the first time the port is opened */ 235 * is the first time the port is opened */
233 retval = serial->type->open(tty, port, filp); 236 retval = serial->type->open(tty, port, filp);
234 if (retval) 237 if (retval)
@@ -252,7 +255,7 @@ bailout_kref_put:
252 return retval; 255 return retval;
253} 256}
254 257
255static void serial_close(struct tty_struct *tty, struct file * filp) 258static void serial_close(struct tty_struct *tty, struct file *filp)
256{ 259{
257 struct usb_serial_port *port = tty->driver_data; 260 struct usb_serial_port *port = tty->driver_data;
258 261
@@ -270,7 +273,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
270 273
271 --port->port.count; 274 --port->port.count;
272 if (port->port.count == 0) 275 if (port->port.count == 0)
273 /* only call the device specific close if this 276 /* only call the device specific close if this
274 * port is being closed by the last owner */ 277 * port is being closed by the last owner */
275 port->serial->type->close(tty, port, filp); 278 port->serial->type->close(tty, port, filp);
276 279
@@ -294,7 +297,8 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
294 usb_serial_put(port->serial); 297 usb_serial_put(port->serial);
295} 298}
296 299
297static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) 300static int serial_write(struct tty_struct *tty, const unsigned char *buf,
301 int count)
298{ 302{
299 struct usb_serial_port *port = tty->driver_data; 303 struct usb_serial_port *port = tty->driver_data;
300 int retval = -ENODEV; 304 int retval = -ENODEV;
@@ -305,7 +309,7 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
305 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 309 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
306 310
307 /* count is managed under the mutex lock for the tty so cannot 311 /* count is managed under the mutex lock for the tty so cannot
308 drop to zero until after the last close completes */ 312 drop to zero until after the last close completes */
309 WARN_ON(!port->port.count); 313 WARN_ON(!port->port.count);
310 314
311 /* pass on to the driver specific version of this function */ 315 /* pass on to the driver specific version of this function */
@@ -315,7 +319,7 @@ exit:
315 return retval; 319 return retval;
316} 320}
317 321
318static int serial_write_room (struct tty_struct *tty) 322static int serial_write_room(struct tty_struct *tty)
319{ 323{
320 struct usb_serial_port *port = tty->driver_data; 324 struct usb_serial_port *port = tty->driver_data;
321 dbg("%s - port %d", __func__, port->number); 325 dbg("%s - port %d", __func__, port->number);
@@ -324,7 +328,7 @@ static int serial_write_room (struct tty_struct *tty)
324 return port->serial->type->write_room(tty); 328 return port->serial->type->write_room(tty);
325} 329}
326 330
327static int serial_chars_in_buffer (struct tty_struct *tty) 331static int serial_chars_in_buffer(struct tty_struct *tty)
328{ 332{
329 struct usb_serial_port *port = tty->driver_data; 333 struct usb_serial_port *port = tty->driver_data;
330 dbg("%s = port %d", __func__, port->number); 334 dbg("%s = port %d", __func__, port->number);
@@ -334,7 +338,7 @@ static int serial_chars_in_buffer (struct tty_struct *tty)
334 return port->serial->type->chars_in_buffer(tty); 338 return port->serial->type->chars_in_buffer(tty);
335} 339}
336 340
337static void serial_throttle (struct tty_struct * tty) 341static void serial_throttle(struct tty_struct *tty)
338{ 342{
339 struct usb_serial_port *port = tty->driver_data; 343 struct usb_serial_port *port = tty->driver_data;
340 dbg("%s - port %d", __func__, port->number); 344 dbg("%s - port %d", __func__, port->number);
@@ -345,7 +349,7 @@ static void serial_throttle (struct tty_struct * tty)
345 port->serial->type->throttle(tty); 349 port->serial->type->throttle(tty);
346} 350}
347 351
348static void serial_unthrottle (struct tty_struct * tty) 352static void serial_unthrottle(struct tty_struct *tty)
349{ 353{
350 struct usb_serial_port *port = tty->driver_data; 354 struct usb_serial_port *port = tty->driver_data;
351 dbg("%s - port %d", __func__, port->number); 355 dbg("%s - port %d", __func__, port->number);
@@ -356,7 +360,8 @@ static void serial_unthrottle (struct tty_struct * tty)
356 port->serial->type->unthrottle(tty); 360 port->serial->type->unthrottle(tty);
357} 361}
358 362
359static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) 363static int serial_ioctl(struct tty_struct *tty, struct file *file,
364 unsigned int cmd, unsigned long arg)
360{ 365{
361 struct usb_serial_port *port = tty->driver_data; 366 struct usb_serial_port *port = tty->driver_data;
362 int retval = -ENODEV; 367 int retval = -ENODEV;
@@ -365,38 +370,40 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in
365 370
366 WARN_ON(!port->port.count); 371 WARN_ON(!port->port.count);
367 372
368 /* pass on to the driver specific version of this function if it is available */ 373 /* pass on to the driver specific version of this function
374 if it is available */
369 if (port->serial->type->ioctl) { 375 if (port->serial->type->ioctl) {
370 lock_kernel(); 376 lock_kernel();
371 retval = port->serial->type->ioctl(tty, file, cmd, arg); 377 retval = port->serial->type->ioctl(tty, file, cmd, arg);
372 unlock_kernel(); 378 unlock_kernel();
373 } 379 } else
374 else
375 retval = -ENOIOCTLCMD; 380 retval = -ENOIOCTLCMD;
376 return retval; 381 return retval;
377} 382}
378 383
379static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) 384static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
380{ 385{
381 struct usb_serial_port *port = tty->driver_data; 386 struct usb_serial_port *port = tty->driver_data;
382 dbg("%s - port %d", __func__, port->number); 387 dbg("%s - port %d", __func__, port->number);
383 388
384 WARN_ON(!port->port.count); 389 WARN_ON(!port->port.count);
385 /* pass on to the driver specific version of this function if it is available */ 390 /* pass on to the driver specific version of this function
391 if it is available */
386 if (port->serial->type->set_termios) 392 if (port->serial->type->set_termios)
387 port->serial->type->set_termios(tty, port, old); 393 port->serial->type->set_termios(tty, port, old);
388 else 394 else
389 tty_termios_copy_hw(tty->termios, old); 395 tty_termios_copy_hw(tty->termios, old);
390} 396}
391 397
392static void serial_break (struct tty_struct *tty, int break_state) 398static void serial_break(struct tty_struct *tty, int break_state)
393{ 399{
394 struct usb_serial_port *port = tty->driver_data; 400 struct usb_serial_port *port = tty->driver_data;
395 401
396 dbg("%s - port %d", __func__, port->number); 402 dbg("%s - port %d", __func__, port->number);
397 403
398 WARN_ON(!port->port.count); 404 WARN_ON(!port->port.count);
399 /* pass on to the driver specific version of this function if it is available */ 405 /* pass on to the driver specific version of this function
406 if it is available */
400 if (port->serial->type->break_ctl) { 407 if (port->serial->type->break_ctl) {
401 lock_kernel(); 408 lock_kernel();
402 port->serial->type->break_ctl(tty, break_state); 409 port->serial->type->break_ctl(tty, break_state);
@@ -404,7 +411,8 @@ static void serial_break (struct tty_struct *tty, int break_state)
404 } 411 }
405} 412}
406 413
407static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) 414static int serial_read_proc(char *page, char **start, off_t off, int count,
415 int *eof, void *data)
408{ 416{
409 struct usb_serial *serial; 417 struct usb_serial *serial;
410 int length = 0; 418 int length = 0;
@@ -413,26 +421,29 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
413 char tmp[40]; 421 char tmp[40];
414 422
415 dbg("%s", __func__); 423 dbg("%s", __func__);
416 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n"); 424 length += sprintf(page, "usbserinfo:1.0 driver:2.0\n");
417 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { 425 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
418 serial = usb_serial_get_by_index(i); 426 serial = usb_serial_get_by_index(i);
419 if (serial == NULL) 427 if (serial == NULL)
420 continue; 428 continue;
421 429
422 length += sprintf (page+length, "%d:", i); 430 length += sprintf(page+length, "%d:", i);
423 if (serial->type->driver.owner) 431 if (serial->type->driver.owner)
424 length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner)); 432 length += sprintf(page+length, " module:%s",
425 length += sprintf (page+length, " name:\"%s\"", serial->type->description); 433 module_name(serial->type->driver.owner));
426 length += sprintf (page+length, " vendor:%04x product:%04x", 434 length += sprintf(page+length, " name:\"%s\"",
427 le16_to_cpu(serial->dev->descriptor.idVendor), 435 serial->type->description);
428 le16_to_cpu(serial->dev->descriptor.idProduct)); 436 length += sprintf(page+length, " vendor:%04x product:%04x",
429 length += sprintf (page+length, " num_ports:%d", serial->num_ports); 437 le16_to_cpu(serial->dev->descriptor.idVendor),
430 length += sprintf (page+length, " port:%d", i - serial->minor + 1); 438 le16_to_cpu(serial->dev->descriptor.idProduct));
431 439 length += sprintf(page+length, " num_ports:%d",
440 serial->num_ports);
441 length += sprintf(page+length, " port:%d",
442 i - serial->minor + 1);
432 usb_make_path(serial->dev, tmp, sizeof(tmp)); 443 usb_make_path(serial->dev, tmp, sizeof(tmp));
433 length += sprintf (page+length, " path:%s", tmp); 444 length += sprintf(page+length, " path:%s", tmp);
434 445
435 length += sprintf (page+length, "\n"); 446 length += sprintf(page+length, "\n");
436 if ((length + begin) > (off + count)) { 447 if ((length + begin) > (off + count)) {
437 usb_serial_put(serial); 448 usb_serial_put(serial);
438 goto done; 449 goto done;
@@ -448,10 +459,10 @@ done:
448 if (off >= (length + begin)) 459 if (off >= (length + begin))
449 return 0; 460 return 0;
450 *start = page + (off-begin); 461 *start = page + (off-begin);
451 return ((count < begin+length-off) ? count : begin+length-off); 462 return (count < begin+length-off) ? count : begin+length-off;
452} 463}
453 464
454static int serial_tiocmget (struct tty_struct *tty, struct file *file) 465static int serial_tiocmget(struct tty_struct *tty, struct file *file)
455{ 466{
456 struct usb_serial_port *port = tty->driver_data; 467 struct usb_serial_port *port = tty->driver_data;
457 468
@@ -463,7 +474,7 @@ static int serial_tiocmget (struct tty_struct *tty, struct file *file)
463 return -EINVAL; 474 return -EINVAL;
464} 475}
465 476
466static int serial_tiocmset (struct tty_struct *tty, struct file *file, 477static int serial_tiocmset(struct tty_struct *tty, struct file *file,
467 unsigned int set, unsigned int clear) 478 unsigned int set, unsigned int clear)
468{ 479{
469 struct usb_serial_port *port = tty->driver_data; 480 struct usb_serial_port *port = tty->driver_data;
@@ -485,6 +496,7 @@ void usb_serial_port_softint(struct usb_serial_port *port)
485{ 496{
486 schedule_work(&port->work); 497 schedule_work(&port->work);
487} 498}
499EXPORT_SYMBOL_GPL(usb_serial_port_softint);
488 500
489static void usb_serial_port_work(struct work_struct *work) 501static void usb_serial_port_work(struct work_struct *work)
490{ 502{
@@ -493,7 +505,7 @@ static void usb_serial_port_work(struct work_struct *work)
493 struct tty_struct *tty; 505 struct tty_struct *tty;
494 506
495 dbg("%s - port %d", __func__, port->number); 507 dbg("%s - port %d", __func__, port->number);
496 508
497 if (!port) 509 if (!port)
498 return; 510 return;
499 511
@@ -546,9 +558,9 @@ static void port_free(struct usb_serial_port *port)
546 kfree(port); 558 kfree(port);
547} 559}
548 560
549static struct usb_serial * create_serial (struct usb_device *dev, 561static struct usb_serial *create_serial(struct usb_device *dev,
550 struct usb_interface *interface, 562 struct usb_interface *interface,
551 struct usb_serial_driver *driver) 563 struct usb_serial_driver *driver)
552{ 564{
553 struct usb_serial *serial; 565 struct usb_serial *serial;
554 566
@@ -567,7 +579,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
567} 579}
568 580
569static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf, 581static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf,
570 struct usb_serial_driver *drv) 582 struct usb_serial_driver *drv)
571{ 583{
572 struct usb_dynid *dynid; 584 struct usb_dynid *dynid;
573 585
@@ -599,7 +611,8 @@ exit:
599 return id; 611 return id;
600} 612}
601 613
602static struct usb_serial_driver *search_serial_device(struct usb_interface *iface) 614static struct usb_serial_driver *search_serial_device(
615 struct usb_interface *iface)
603{ 616{
604 const struct usb_device_id *id; 617 const struct usb_device_id *id;
605 struct usb_serial_driver *drv; 618 struct usb_serial_driver *drv;
@@ -617,7 +630,7 @@ static struct usb_serial_driver *search_serial_device(struct usb_interface *ifac
617int usb_serial_probe(struct usb_interface *interface, 630int usb_serial_probe(struct usb_interface *interface,
618 const struct usb_device_id *id) 631 const struct usb_device_id *id)
619{ 632{
620 struct usb_device *dev = interface_to_usbdev (interface); 633 struct usb_device *dev = interface_to_usbdev(interface);
621 struct usb_serial *serial = NULL; 634 struct usb_serial *serial = NULL;
622 struct usb_serial_port *port; 635 struct usb_serial_port *port;
623 struct usb_host_interface *iface_desc; 636 struct usb_host_interface *iface_desc;
@@ -646,7 +659,7 @@ int usb_serial_probe(struct usb_interface *interface,
646 return -ENODEV; 659 return -ENODEV;
647 } 660 }
648 661
649 serial = create_serial (dev, interface, type); 662 serial = create_serial(dev, interface, type);
650 if (!serial) { 663 if (!serial) {
651 unlock_kernel(); 664 unlock_kernel();
652 dev_err(&interface->dev, "%s - out of memory\n", __func__); 665 dev_err(&interface->dev, "%s - out of memory\n", __func__);
@@ -659,8 +672,9 @@ int usb_serial_probe(struct usb_interface *interface,
659 672
660 if (!try_module_get(type->driver.owner)) { 673 if (!try_module_get(type->driver.owner)) {
661 unlock_kernel(); 674 unlock_kernel();
662 dev_err(&interface->dev, "module get failed, exiting\n"); 675 dev_err(&interface->dev,
663 kfree (serial); 676 "module get failed, exiting\n");
677 kfree(serial);
664 return -EIO; 678 return -EIO;
665 } 679 }
666 680
@@ -670,8 +684,8 @@ int usb_serial_probe(struct usb_interface *interface,
670 684
671 if (retval) { 685 if (retval) {
672 unlock_kernel(); 686 unlock_kernel();
673 dbg ("sub driver rejected device"); 687 dbg("sub driver rejected device");
674 kfree (serial); 688 kfree(serial);
675 return retval; 689 return retval;
676 } 690 }
677 } 691 }
@@ -712,7 +726,7 @@ int usb_serial_probe(struct usb_interface *interface,
712 } 726 }
713 727
714#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE) 728#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
715 /* BEGIN HORRIBLE HACK FOR PL2303 */ 729 /* BEGIN HORRIBLE HACK FOR PL2303 */
716 /* this is needed due to the looney way its endpoints are set up */ 730 /* this is needed due to the looney way its endpoints are set up */
717 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && 731 if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) &&
718 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || 732 (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) ||
@@ -741,7 +755,7 @@ int usb_serial_probe(struct usb_interface *interface,
741 if (num_bulk_in == 0 || num_bulk_out == 0) { 755 if (num_bulk_in == 0 || num_bulk_out == 0) {
742 unlock_kernel(); 756 unlock_kernel();
743 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 757 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");
744 kfree (serial); 758 kfree(serial);
745 return -ENODEV; 759 return -ENODEV;
746 } 760 }
747 } 761 }
@@ -753,8 +767,9 @@ int usb_serial_probe(struct usb_interface *interface,
753 num_ports = num_bulk_out; 767 num_ports = num_bulk_out;
754 if (num_ports == 0) { 768 if (num_ports == 0) {
755 unlock_kernel(); 769 unlock_kernel();
756 dev_err(&interface->dev, "Generic device with no bulk out, not allowed.\n"); 770 dev_err(&interface->dev,
757 kfree (serial); 771 "Generic device with no bulk out, not allowed.\n");
772 kfree(serial);
758 return -EIO; 773 return -EIO;
759 } 774 }
760 } 775 }
@@ -764,11 +779,12 @@ int usb_serial_probe(struct usb_interface *interface,
764 if (type->calc_num_ports) { 779 if (type->calc_num_ports) {
765 if (!try_module_get(type->driver.owner)) { 780 if (!try_module_get(type->driver.owner)) {
766 unlock_kernel(); 781 unlock_kernel();
767 dev_err(&interface->dev, "module get failed, exiting\n"); 782 dev_err(&interface->dev,
768 kfree (serial); 783 "module get failed, exiting\n");
784 kfree(serial);
769 return -EIO; 785 return -EIO;
770 } 786 }
771 num_ports = type->calc_num_ports (serial); 787 num_ports = type->calc_num_ports(serial);
772 module_put(type->driver.owner); 788 module_put(type->driver.owner);
773 } 789 }
774 if (!num_ports) 790 if (!num_ports)
@@ -786,7 +802,8 @@ int usb_serial_probe(struct usb_interface *interface,
786 type->description); 802 type->description);
787 803
788 /* create our ports, we need as many as the max endpoints */ 804 /* create our ports, we need as many as the max endpoints */
789 /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */ 805 /* we don't use num_ports here because some devices have more
806 endpoint pairs than ports */
790 max_endpoints = max(num_bulk_in, num_bulk_out); 807 max_endpoints = max(num_bulk_in, num_bulk_out);
791 max_endpoints = max(max_endpoints, num_interrupt_in); 808 max_endpoints = max(max_endpoints, num_interrupt_in);
792 max_endpoints = max(max_endpoints, num_interrupt_out); 809 max_endpoints = max(max_endpoints, num_interrupt_out);
@@ -794,7 +811,8 @@ int usb_serial_probe(struct usb_interface *interface,
794 serial->num_port_pointers = max_endpoints; 811 serial->num_port_pointers = max_endpoints;
795 unlock_kernel(); 812 unlock_kernel();
796 813
797 dbg("%s - setting up %d port structures for this device", __func__, max_endpoints); 814 dbg("%s - setting up %d port structures for this device",
815 __func__, max_endpoints);
798 for (i = 0; i < max_endpoints; ++i) { 816 for (i = 0; i < max_endpoints; ++i) {
799 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 817 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
800 if (!port) 818 if (!port)
@@ -810,7 +828,7 @@ int usb_serial_probe(struct usb_interface *interface,
810 for (i = 0; i < num_bulk_in; ++i) { 828 for (i = 0; i < num_bulk_in; ++i) {
811 endpoint = bulk_in_endpoint[i]; 829 endpoint = bulk_in_endpoint[i];
812 port = serial->port[i]; 830 port = serial->port[i];
813 port->read_urb = usb_alloc_urb (0, GFP_KERNEL); 831 port->read_urb = usb_alloc_urb(0, GFP_KERNEL);
814 if (!port->read_urb) { 832 if (!port->read_urb) {
815 dev_err(&interface->dev, "No free urbs available\n"); 833 dev_err(&interface->dev, "No free urbs available\n");
816 goto probe_error; 834 goto probe_error;
@@ -818,17 +836,17 @@ int usb_serial_probe(struct usb_interface *interface,
818 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 836 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
819 port->bulk_in_size = buffer_size; 837 port->bulk_in_size = buffer_size;
820 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 838 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
821 port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 839 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
822 if (!port->bulk_in_buffer) { 840 if (!port->bulk_in_buffer) {
823 dev_err(&interface->dev, "Couldn't allocate bulk_in_buffer\n"); 841 dev_err(&interface->dev,
842 "Couldn't allocate bulk_in_buffer\n");
824 goto probe_error; 843 goto probe_error;
825 } 844 }
826 usb_fill_bulk_urb (port->read_urb, dev, 845 usb_fill_bulk_urb(port->read_urb, dev,
827 usb_rcvbulkpipe (dev, 846 usb_rcvbulkpipe(dev,
828 endpoint->bEndpointAddress), 847 endpoint->bEndpointAddress),
829 port->bulk_in_buffer, buffer_size, 848 port->bulk_in_buffer, buffer_size,
830 serial->type->read_bulk_callback, 849 serial->type->read_bulk_callback, port);
831 port);
832 } 850 }
833 851
834 for (i = 0; i < num_bulk_out; ++i) { 852 for (i = 0; i < num_bulk_out; ++i) {
@@ -842,17 +860,17 @@ int usb_serial_probe(struct usb_interface *interface,
842 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 860 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
843 port->bulk_out_size = buffer_size; 861 port->bulk_out_size = buffer_size;
844 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 862 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
845 port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 863 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
846 if (!port->bulk_out_buffer) { 864 if (!port->bulk_out_buffer) {
847 dev_err(&interface->dev, "Couldn't allocate bulk_out_buffer\n"); 865 dev_err(&interface->dev,
866 "Couldn't allocate bulk_out_buffer\n");
848 goto probe_error; 867 goto probe_error;
849 } 868 }
850 usb_fill_bulk_urb (port->write_urb, dev, 869 usb_fill_bulk_urb(port->write_urb, dev,
851 usb_sndbulkpipe (dev, 870 usb_sndbulkpipe(dev,
852 endpoint->bEndpointAddress), 871 endpoint->bEndpointAddress),
853 port->bulk_out_buffer, buffer_size, 872 port->bulk_out_buffer, buffer_size,
854 serial->type->write_bulk_callback, 873 serial->type->write_bulk_callback, port);
855 port);
856 } 874 }
857 875
858 if (serial->type->read_int_callback) { 876 if (serial->type->read_int_callback) {
@@ -861,73 +879,82 @@ int usb_serial_probe(struct usb_interface *interface,
861 port = serial->port[i]; 879 port = serial->port[i];
862 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 880 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
863 if (!port->interrupt_in_urb) { 881 if (!port->interrupt_in_urb) {
864 dev_err(&interface->dev, "No free urbs available\n"); 882 dev_err(&interface->dev,
883 "No free urbs available\n");
865 goto probe_error; 884 goto probe_error;
866 } 885 }
867 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 886 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
868 port->interrupt_in_endpointAddress = endpoint->bEndpointAddress; 887 port->interrupt_in_endpointAddress =
869 port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL); 888 endpoint->bEndpointAddress;
889 port->interrupt_in_buffer = kmalloc(buffer_size,
890 GFP_KERNEL);
870 if (!port->interrupt_in_buffer) { 891 if (!port->interrupt_in_buffer) {
871 dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n"); 892 dev_err(&interface->dev,
893 "Couldn't allocate interrupt_in_buffer\n");
872 goto probe_error; 894 goto probe_error;
873 } 895 }
874 usb_fill_int_urb (port->interrupt_in_urb, dev, 896 usb_fill_int_urb(port->interrupt_in_urb, dev,
875 usb_rcvintpipe (dev, 897 usb_rcvintpipe(dev,
876 endpoint->bEndpointAddress), 898 endpoint->bEndpointAddress),
877 port->interrupt_in_buffer, buffer_size, 899 port->interrupt_in_buffer, buffer_size,
878 serial->type->read_int_callback, port, 900 serial->type->read_int_callback, port,
879 endpoint->bInterval); 901 endpoint->bInterval);
880 } 902 }
881 } else if (num_interrupt_in) { 903 } else if (num_interrupt_in) {
882 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined"); 904 dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined");
883 } 905 }
884 906
885 if (serial->type->write_int_callback) { 907 if (serial->type->write_int_callback) {
886 for (i = 0; i < num_interrupt_out; ++i) { 908 for (i = 0; i < num_interrupt_out; ++i) {
887 endpoint = interrupt_out_endpoint[i]; 909 endpoint = interrupt_out_endpoint[i];
888 port = serial->port[i]; 910 port = serial->port[i];
889 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 911 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
890 if (!port->interrupt_out_urb) { 912 if (!port->interrupt_out_urb) {
891 dev_err(&interface->dev, "No free urbs available\n"); 913 dev_err(&interface->dev,
914 "No free urbs available\n");
892 goto probe_error; 915 goto probe_error;
893 } 916 }
894 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 917 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
895 port->interrupt_out_size = buffer_size; 918 port->interrupt_out_size = buffer_size;
896 port->interrupt_out_endpointAddress = endpoint->bEndpointAddress; 919 port->interrupt_out_endpointAddress =
897 port->interrupt_out_buffer = kmalloc (buffer_size, GFP_KERNEL); 920 endpoint->bEndpointAddress;
921 port->interrupt_out_buffer = kmalloc(buffer_size,
922 GFP_KERNEL);
898 if (!port->interrupt_out_buffer) { 923 if (!port->interrupt_out_buffer) {
899 dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n"); 924 dev_err(&interface->dev,
925 "Couldn't allocate interrupt_out_buffer\n");
900 goto probe_error; 926 goto probe_error;
901 } 927 }
902 usb_fill_int_urb (port->interrupt_out_urb, dev, 928 usb_fill_int_urb(port->interrupt_out_urb, dev,
903 usb_sndintpipe (dev, 929 usb_sndintpipe(dev,
904 endpoint->bEndpointAddress), 930 endpoint->bEndpointAddress),
905 port->interrupt_out_buffer, buffer_size, 931 port->interrupt_out_buffer, buffer_size,
906 serial->type->write_int_callback, port, 932 serial->type->write_int_callback, port,
907 endpoint->bInterval); 933 endpoint->bInterval);
908 } 934 }
909 } else if (num_interrupt_out) { 935 } else if (num_interrupt_out) {
910 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined"); 936 dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined");
911 } 937 }
912 938
913 /* if this device type has an attach function, call it */ 939 /* if this device type has an attach function, call it */
914 if (type->attach) { 940 if (type->attach) {
915 if (!try_module_get(type->driver.owner)) { 941 if (!try_module_get(type->driver.owner)) {
916 dev_err(&interface->dev, "module get failed, exiting\n"); 942 dev_err(&interface->dev,
943 "module get failed, exiting\n");
917 goto probe_error; 944 goto probe_error;
918 } 945 }
919 retval = type->attach (serial); 946 retval = type->attach(serial);
920 module_put(type->driver.owner); 947 module_put(type->driver.owner);
921 if (retval < 0) 948 if (retval < 0)
922 goto probe_error; 949 goto probe_error;
923 if (retval > 0) { 950 if (retval > 0) {
924 /* quietly accept this device, but don't bind to a serial port 951 /* quietly accept this device, but don't bind to a
925 * as it's about to disappear */ 952 serial port as it's about to disappear */
926 goto exit; 953 goto exit;
927 } 954 }
928 } 955 }
929 956
930 if (get_free_serial (serial, num_ports, &minor) == NULL) { 957 if (get_free_serial(serial, num_ports, &minor) == NULL) {
931 dev_err(&interface->dev, "No more free serial devices\n"); 958 dev_err(&interface->dev, "No more free serial devices\n");
932 goto probe_error; 959 goto probe_error;
933 } 960 }
@@ -949,11 +976,11 @@ int usb_serial_probe(struct usb_interface *interface,
949 "continuing\n"); 976 "continuing\n");
950 } 977 }
951 978
952 usb_serial_console_init (debug, minor); 979 usb_serial_console_init(debug, minor);
953 980
954exit: 981exit:
955 /* success */ 982 /* success */
956 usb_set_intfdata (interface, serial); 983 usb_set_intfdata(interface, serial);
957 return 0; 984 return 0;
958 985
959probe_error: 986probe_error:
@@ -989,22 +1016,23 @@ probe_error:
989 /* free up any memory that we allocated */ 1016 /* free up any memory that we allocated */
990 for (i = 0; i < serial->num_port_pointers; ++i) 1017 for (i = 0; i < serial->num_port_pointers; ++i)
991 kfree(serial->port[i]); 1018 kfree(serial->port[i]);
992 kfree (serial); 1019 kfree(serial);
993 return -EIO; 1020 return -EIO;
994} 1021}
1022EXPORT_SYMBOL_GPL(usb_serial_probe);
995 1023
996void usb_serial_disconnect(struct usb_interface *interface) 1024void usb_serial_disconnect(struct usb_interface *interface)
997{ 1025{
998 int i; 1026 int i;
999 struct usb_serial *serial = usb_get_intfdata (interface); 1027 struct usb_serial *serial = usb_get_intfdata(interface);
1000 struct device *dev = &interface->dev; 1028 struct device *dev = &interface->dev;
1001 struct usb_serial_port *port; 1029 struct usb_serial_port *port;
1002 1030
1003 usb_serial_console_disconnect(serial); 1031 usb_serial_console_disconnect(serial);
1004 dbg ("%s", __func__); 1032 dbg("%s", __func__);
1005 1033
1006 mutex_lock(&serial->disc_mutex); 1034 mutex_lock(&serial->disc_mutex);
1007 usb_set_intfdata (interface, NULL); 1035 usb_set_intfdata(interface, NULL);
1008 /* must set a flag, to signal subdrivers */ 1036 /* must set a flag, to signal subdrivers */
1009 serial->disconnected = 1; 1037 serial->disconnected = 1;
1010 for (i = 0; i < serial->num_ports; ++i) { 1038 for (i = 0; i < serial->num_ports; ++i) {
@@ -1021,6 +1049,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1021 usb_serial_put(serial); 1049 usb_serial_put(serial);
1022 dev_info(dev, "device disconnected\n"); 1050 dev_info(dev, "device disconnected\n");
1023} 1051}
1052EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1024 1053
1025int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) 1054int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1026{ 1055{
@@ -1079,9 +1108,8 @@ static int __init usb_serial_init(void)
1079 return -ENOMEM; 1108 return -ENOMEM;
1080 1109
1081 /* Initialize our global data */ 1110 /* Initialize our global data */
1082 for (i = 0; i < SERIAL_TTY_MINORS; ++i) { 1111 for (i = 0; i < SERIAL_TTY_MINORS; ++i)
1083 serial_table[i] = NULL; 1112 serial_table[i] = NULL;
1084 }
1085 1113
1086 result = bus_register(&usb_serial_bus_type); 1114 result = bus_register(&usb_serial_bus_type);
1087 if (result) { 1115 if (result) {
@@ -1096,9 +1124,11 @@ static int __init usb_serial_init(void)
1096 usb_serial_tty_driver->minor_start = 0; 1124 usb_serial_tty_driver->minor_start = 0;
1097 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 1125 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1098 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1126 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1099 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1127 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW |
1128 TTY_DRIVER_DYNAMIC_DEV;
1100 usb_serial_tty_driver->init_termios = tty_std_termios; 1129 usb_serial_tty_driver->init_termios = tty_std_termios;
1101 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1130 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD
1131 | HUPCL | CLOCAL;
1102 usb_serial_tty_driver->init_termios.c_ispeed = 9600; 1132 usb_serial_tty_driver->init_termios.c_ispeed = 9600;
1103 usb_serial_tty_driver->init_termios.c_ospeed = 9600; 1133 usb_serial_tty_driver->init_termios.c_ospeed = 9600;
1104 tty_set_operations(usb_serial_tty_driver, &serial_ops); 1134 tty_set_operations(usb_serial_tty_driver, &serial_ops);
@@ -1136,7 +1166,7 @@ exit_reg_driver:
1136 bus_unregister(&usb_serial_bus_type); 1166 bus_unregister(&usb_serial_bus_type);
1137 1167
1138exit_bus: 1168exit_bus:
1139 err ("%s - returning with error %d", __func__, result); 1169 err("%s - returning with error %d", __func__, result);
1140 put_tty_driver(usb_serial_tty_driver); 1170 put_tty_driver(usb_serial_tty_driver);
1141 return result; 1171 return result;
1142} 1172}
@@ -1163,7 +1193,7 @@ module_exit(usb_serial_exit);
1163 if (!type->function) { \ 1193 if (!type->function) { \
1164 type->function = usb_serial_generic_##function; \ 1194 type->function = usb_serial_generic_##function; \
1165 dbg("Had to override the " #function \ 1195 dbg("Had to override the " #function \
1166 " usb serial operation with the generic one.");\ 1196 " usb serial operation with the generic one.");\
1167 } \ 1197 } \
1168 } while (0) 1198 } while (0)
1169 1199
@@ -1180,8 +1210,9 @@ static void fixup_generic(struct usb_serial_driver *device)
1180 set_to_generic_if_null(device, resume); 1210 set_to_generic_if_null(device, resume);
1181} 1211}
1182 1212
1183int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ 1213int usb_serial_register(struct usb_serial_driver *driver)
1184{ 1214{
1215 /* must be called with BKL held */
1185 int retval; 1216 int retval;
1186 1217
1187 fixup_generic(driver); 1218 fixup_generic(driver);
@@ -1194,37 +1225,30 @@ int usb_serial_register(struct usb_serial_driver *driver) /* must be called with
1194 1225
1195 retval = usb_serial_bus_register(driver); 1226 retval = usb_serial_bus_register(driver);
1196 if (retval) { 1227 if (retval) {
1197 err("problem %d when registering driver %s", retval, driver->description); 1228 err("problem %d when registering driver %s",
1229 retval, driver->description);
1198 list_del(&driver->driver_list); 1230 list_del(&driver->driver_list);
1199 } 1231 } else
1200 else 1232 info("USB Serial support registered for %s",
1201 info("USB Serial support registered for %s", driver->description); 1233 driver->description);
1202 1234
1203 return retval; 1235 return retval;
1204} 1236}
1237EXPORT_SYMBOL_GPL(usb_serial_register);
1205 1238
1206 1239
1207void usb_serial_deregister(struct usb_serial_driver *device) /* must be called with BKL held */ 1240void usb_serial_deregister(struct usb_serial_driver *device)
1208{ 1241{
1242 /* must be called with BKL held */
1209 info("USB Serial deregistering driver %s", device->description); 1243 info("USB Serial deregistering driver %s", device->description);
1210 list_del(&device->driver_list); 1244 list_del(&device->driver_list);
1211 usb_serial_bus_deregister(device); 1245 usb_serial_bus_deregister(device);
1212} 1246}
1213
1214
1215
1216/* If the usb-serial core is built into the core, the usb-serial drivers
1217 need these symbols to load properly as modules. */
1218EXPORT_SYMBOL_GPL(usb_serial_register);
1219EXPORT_SYMBOL_GPL(usb_serial_deregister); 1247EXPORT_SYMBOL_GPL(usb_serial_deregister);
1220EXPORT_SYMBOL_GPL(usb_serial_probe);
1221EXPORT_SYMBOL_GPL(usb_serial_disconnect);
1222EXPORT_SYMBOL_GPL(usb_serial_port_softint);
1223
1224 1248
1225/* Module information */ 1249/* Module information */
1226MODULE_AUTHOR( DRIVER_AUTHOR ); 1250MODULE_AUTHOR(DRIVER_AUTHOR);
1227MODULE_DESCRIPTION( DRIVER_DESC ); 1251MODULE_DESCRIPTION(DRIVER_DESC);
1228MODULE_LICENSE("GPL"); 1252MODULE_LICENSE("GPL");
1229 1253
1230module_param(debug, bool, S_IRUGO | S_IWUSR); 1254module_param(debug, bool, S_IRUGO | S_IWUSR);