diff options
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index cc274fdf2627..ce6c1a65a544 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -50,7 +50,7 @@ static struct usb_driver usb_serial_driver = { | |||
50 | .disconnect = usb_serial_disconnect, | 50 | .disconnect = usb_serial_disconnect, |
51 | .suspend = usb_serial_suspend, | 51 | .suspend = usb_serial_suspend, |
52 | .resume = usb_serial_resume, | 52 | .resume = usb_serial_resume, |
53 | .no_dynamic_id = 1, | 53 | .no_dynamic_id = 1, |
54 | .supports_autosuspend = 1, | 54 | .supports_autosuspend = 1, |
55 | }; | 55 | }; |
56 | 56 | ||
@@ -260,6 +260,10 @@ static int serial_activate(struct tty_port *tport, struct tty_struct *tty) | |||
260 | else | 260 | else |
261 | retval = port->serial->type->open(tty, port); | 261 | retval = port->serial->type->open(tty, port); |
262 | mutex_unlock(&serial->disc_mutex); | 262 | mutex_unlock(&serial->disc_mutex); |
263 | |||
264 | if (retval < 0) | ||
265 | retval = usb_translate_errors(retval); | ||
266 | |||
263 | return retval; | 267 | return retval; |
264 | } | 268 | } |
265 | 269 | ||
@@ -360,7 +364,8 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf, | |||
360 | 364 | ||
361 | /* pass on to the driver specific version of this function */ | 365 | /* pass on to the driver specific version of this function */ |
362 | retval = port->serial->type->write(tty, port, buf, count); | 366 | retval = port->serial->type->write(tty, port, buf, count); |
363 | 367 | if (retval < 0) | |
368 | retval = usb_translate_errors(retval); | ||
364 | exit: | 369 | exit: |
365 | return retval; | 370 | return retval; |
366 | } | 371 | } |
@@ -562,8 +567,8 @@ static void kill_traffic(struct usb_serial_port *port) | |||
562 | { | 567 | { |
563 | int i; | 568 | int i; |
564 | 569 | ||
565 | usb_kill_urb(port->read_urb); | 570 | for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) |
566 | usb_kill_urb(port->write_urb); | 571 | usb_kill_urb(port->read_urbs[i]); |
567 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) | 572 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) |
568 | usb_kill_urb(port->write_urbs[i]); | 573 | usb_kill_urb(port->write_urbs[i]); |
569 | /* | 574 | /* |
@@ -595,17 +600,17 @@ static void port_release(struct device *dev) | |||
595 | kill_traffic(port); | 600 | kill_traffic(port); |
596 | cancel_work_sync(&port->work); | 601 | cancel_work_sync(&port->work); |
597 | 602 | ||
598 | usb_free_urb(port->read_urb); | ||
599 | usb_free_urb(port->write_urb); | ||
600 | usb_free_urb(port->interrupt_in_urb); | 603 | usb_free_urb(port->interrupt_in_urb); |
601 | usb_free_urb(port->interrupt_out_urb); | 604 | usb_free_urb(port->interrupt_out_urb); |
605 | for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { | ||
606 | usb_free_urb(port->read_urbs[i]); | ||
607 | kfree(port->bulk_in_buffers[i]); | ||
608 | } | ||
602 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { | 609 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { |
603 | usb_free_urb(port->write_urbs[i]); | 610 | usb_free_urb(port->write_urbs[i]); |
604 | kfree(port->bulk_out_buffers[i]); | 611 | kfree(port->bulk_out_buffers[i]); |
605 | } | 612 | } |
606 | kfifo_free(&port->write_fifo); | 613 | kfifo_free(&port->write_fifo); |
607 | kfree(port->bulk_in_buffer); | ||
608 | kfree(port->bulk_out_buffer); | ||
609 | kfree(port->interrupt_in_buffer); | 614 | kfree(port->interrupt_in_buffer); |
610 | kfree(port->interrupt_out_buffer); | 615 | kfree(port->interrupt_out_buffer); |
611 | kfree(port); | 616 | kfree(port); |
@@ -686,16 +691,18 @@ static int serial_carrier_raised(struct tty_port *port) | |||
686 | { | 691 | { |
687 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | 692 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); |
688 | struct usb_serial_driver *drv = p->serial->type; | 693 | struct usb_serial_driver *drv = p->serial->type; |
694 | |||
689 | if (drv->carrier_raised) | 695 | if (drv->carrier_raised) |
690 | return drv->carrier_raised(p); | 696 | return drv->carrier_raised(p); |
691 | /* No carrier control - don't block */ | 697 | /* No carrier control - don't block */ |
692 | return 1; | 698 | return 1; |
693 | } | 699 | } |
694 | 700 | ||
695 | static void serial_dtr_rts(struct tty_port *port, int on) | 701 | static void serial_dtr_rts(struct tty_port *port, int on) |
696 | { | 702 | { |
697 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); | 703 | struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); |
698 | struct usb_serial_driver *drv = p->serial->type; | 704 | struct usb_serial_driver *drv = p->serial->type; |
705 | |||
699 | if (drv->dtr_rts) | 706 | if (drv->dtr_rts) |
700 | drv->dtr_rts(p, on); | 707 | drv->dtr_rts(p, on); |
701 | } | 708 | } |
@@ -724,6 +731,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
724 | unsigned int minor; | 731 | unsigned int minor; |
725 | int buffer_size; | 732 | int buffer_size; |
726 | int i; | 733 | int i; |
734 | int j; | ||
727 | int num_interrupt_in = 0; | 735 | int num_interrupt_in = 0; |
728 | int num_interrupt_out = 0; | 736 | int num_interrupt_out = 0; |
729 | int num_bulk_in = 0; | 737 | int num_bulk_in = 0; |
@@ -906,38 +914,41 @@ int usb_serial_probe(struct usb_interface *interface, | |||
906 | for (i = 0; i < num_bulk_in; ++i) { | 914 | for (i = 0; i < num_bulk_in; ++i) { |
907 | endpoint = bulk_in_endpoint[i]; | 915 | endpoint = bulk_in_endpoint[i]; |
908 | port = serial->port[i]; | 916 | port = serial->port[i]; |
909 | port->read_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
910 | if (!port->read_urb) { | ||
911 | dev_err(&interface->dev, "No free urbs available\n"); | ||
912 | goto probe_error; | ||
913 | } | ||
914 | buffer_size = max_t(int, serial->type->bulk_in_size, | 917 | buffer_size = max_t(int, serial->type->bulk_in_size, |
915 | usb_endpoint_maxp(endpoint)); | 918 | usb_endpoint_maxp(endpoint)); |
916 | port->bulk_in_size = buffer_size; | 919 | port->bulk_in_size = buffer_size; |
917 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; | 920 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; |
918 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | 921 | |
919 | if (!port->bulk_in_buffer) { | 922 | for (j = 0; j < ARRAY_SIZE(port->read_urbs); ++j) { |
920 | dev_err(&interface->dev, | 923 | set_bit(j, &port->read_urbs_free); |
924 | port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); | ||
925 | if (!port->read_urbs[j]) { | ||
926 | dev_err(&interface->dev, | ||
927 | "No free urbs available\n"); | ||
928 | goto probe_error; | ||
929 | } | ||
930 | port->bulk_in_buffers[j] = kmalloc(buffer_size, | ||
931 | GFP_KERNEL); | ||
932 | if (!port->bulk_in_buffers[j]) { | ||
933 | dev_err(&interface->dev, | ||
921 | "Couldn't allocate bulk_in_buffer\n"); | 934 | "Couldn't allocate bulk_in_buffer\n"); |
922 | goto probe_error; | 935 | goto probe_error; |
923 | } | 936 | } |
924 | usb_fill_bulk_urb(port->read_urb, dev, | 937 | usb_fill_bulk_urb(port->read_urbs[j], dev, |
925 | usb_rcvbulkpipe(dev, | 938 | usb_rcvbulkpipe(dev, |
926 | endpoint->bEndpointAddress), | 939 | endpoint->bEndpointAddress), |
927 | port->bulk_in_buffer, buffer_size, | 940 | port->bulk_in_buffers[j], buffer_size, |
928 | serial->type->read_bulk_callback, port); | 941 | serial->type->read_bulk_callback, |
942 | port); | ||
943 | } | ||
944 | |||
945 | port->read_urb = port->read_urbs[0]; | ||
946 | port->bulk_in_buffer = port->bulk_in_buffers[0]; | ||
929 | } | 947 | } |
930 | 948 | ||
931 | for (i = 0; i < num_bulk_out; ++i) { | 949 | for (i = 0; i < num_bulk_out; ++i) { |
932 | int j; | ||
933 | |||
934 | endpoint = bulk_out_endpoint[i]; | 950 | endpoint = bulk_out_endpoint[i]; |
935 | port = serial->port[i]; | 951 | port = serial->port[i]; |
936 | port->write_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
937 | if (!port->write_urb) { | ||
938 | dev_err(&interface->dev, "No free urbs available\n"); | ||
939 | goto probe_error; | ||
940 | } | ||
941 | if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) | 952 | if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) |
942 | goto probe_error; | 953 | goto probe_error; |
943 | buffer_size = serial->type->bulk_out_size; | 954 | buffer_size = serial->type->bulk_out_size; |
@@ -945,17 +956,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
945 | buffer_size = usb_endpoint_maxp(endpoint); | 956 | buffer_size = usb_endpoint_maxp(endpoint); |
946 | port->bulk_out_size = buffer_size; | 957 | port->bulk_out_size = buffer_size; |
947 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | 958 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; |
948 | port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); | 959 | |
949 | if (!port->bulk_out_buffer) { | ||
950 | dev_err(&interface->dev, | ||
951 | "Couldn't allocate bulk_out_buffer\n"); | ||
952 | goto probe_error; | ||
953 | } | ||
954 | usb_fill_bulk_urb(port->write_urb, dev, | ||
955 | usb_sndbulkpipe(dev, | ||
956 | endpoint->bEndpointAddress), | ||
957 | port->bulk_out_buffer, buffer_size, | ||
958 | serial->type->write_bulk_callback, port); | ||
959 | for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { | 960 | for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { |
960 | set_bit(j, &port->write_urbs_free); | 961 | set_bit(j, &port->write_urbs_free); |
961 | port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); | 962 | port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); |
@@ -978,6 +979,9 @@ int usb_serial_probe(struct usb_interface *interface, | |||
978 | serial->type->write_bulk_callback, | 979 | serial->type->write_bulk_callback, |
979 | port); | 980 | port); |
980 | } | 981 | } |
982 | |||
983 | port->write_urb = port->write_urbs[0]; | ||
984 | port->bulk_out_buffer = port->bulk_out_buffers[0]; | ||
981 | } | 985 | } |
982 | 986 | ||
983 | if (serial->type->read_int_callback) { | 987 | if (serial->type->read_int_callback) { |
@@ -1196,7 +1200,7 @@ static const struct tty_operations serial_ops = { | |||
1196 | .open = serial_open, | 1200 | .open = serial_open, |
1197 | .close = serial_close, | 1201 | .close = serial_close, |
1198 | .write = serial_write, | 1202 | .write = serial_write, |
1199 | .hangup = serial_hangup, | 1203 | .hangup = serial_hangup, |
1200 | .write_room = serial_write_room, | 1204 | .write_room = serial_write_room, |
1201 | .ioctl = serial_ioctl, | 1205 | .ioctl = serial_ioctl, |
1202 | .set_termios = serial_set_termios, | 1206 | .set_termios = serial_set_termios, |
@@ -1206,9 +1210,9 @@ static const struct tty_operations serial_ops = { | |||
1206 | .chars_in_buffer = serial_chars_in_buffer, | 1210 | .chars_in_buffer = serial_chars_in_buffer, |
1207 | .tiocmget = serial_tiocmget, | 1211 | .tiocmget = serial_tiocmget, |
1208 | .tiocmset = serial_tiocmset, | 1212 | .tiocmset = serial_tiocmset, |
1209 | .get_icount = serial_get_icount, | 1213 | .get_icount = serial_get_icount, |
1210 | .cleanup = serial_cleanup, | 1214 | .cleanup = serial_cleanup, |
1211 | .install = serial_install, | 1215 | .install = serial_install, |
1212 | .proc_fops = &serial_proc_fops, | 1216 | .proc_fops = &serial_proc_fops, |
1213 | }; | 1217 | }; |
1214 | 1218 | ||
@@ -1237,7 +1241,7 @@ static int __init usb_serial_init(void) | |||
1237 | 1241 | ||
1238 | usb_serial_tty_driver->owner = THIS_MODULE; | 1242 | usb_serial_tty_driver->owner = THIS_MODULE; |
1239 | usb_serial_tty_driver->driver_name = "usbserial"; | 1243 | usb_serial_tty_driver->driver_name = "usbserial"; |
1240 | usb_serial_tty_driver->name = "ttyUSB"; | 1244 | usb_serial_tty_driver->name = "ttyUSB"; |
1241 | usb_serial_tty_driver->major = SERIAL_TTY_MAJOR; | 1245 | usb_serial_tty_driver->major = SERIAL_TTY_MAJOR; |
1242 | usb_serial_tty_driver->minor_start = 0; | 1246 | usb_serial_tty_driver->minor_start = 0; |
1243 | usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; | 1247 | usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
@@ -1336,7 +1340,6 @@ static void fixup_generic(struct usb_serial_driver *device) | |||
1336 | 1340 | ||
1337 | int usb_serial_register(struct usb_serial_driver *driver) | 1341 | int usb_serial_register(struct usb_serial_driver *driver) |
1338 | { | 1342 | { |
1339 | /* must be called with BKL held */ | ||
1340 | int retval; | 1343 | int retval; |
1341 | 1344 | ||
1342 | if (usb_disabled()) | 1345 | if (usb_disabled()) |
@@ -1374,7 +1377,6 @@ EXPORT_SYMBOL_GPL(usb_serial_register); | |||
1374 | 1377 | ||
1375 | void usb_serial_deregister(struct usb_serial_driver *device) | 1378 | void usb_serial_deregister(struct usb_serial_driver *device) |
1376 | { | 1379 | { |
1377 | /* must be called with BKL held */ | ||
1378 | printk(KERN_INFO "USB Serial deregistering driver %s\n", | 1380 | printk(KERN_INFO "USB Serial deregistering driver %s\n", |
1379 | device->description); | 1381 | device->description); |
1380 | mutex_lock(&table_lock); | 1382 | mutex_lock(&table_lock); |