Loading drivers/usb/serial/generic.c +49 −38 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <linux/moduleparam.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <asm/uaccess.h> #include <linux/uaccess.h> static int debug; Loading Loading @@ -89,7 +89,8 @@ int usb_serial_generic_register (int _debug) #ifdef CONFIG_USB_SERIAL_GENERIC generic_device_ids[0].idVendor = vendor; generic_device_ids[0].idProduct = product; generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; /* register our generic driver with ourselves */ retval = usb_serial_register(&usb_serial_generic_device); Loading Loading @@ -121,9 +122,9 @@ int usb_serial_generic_open(struct tty_struct *tty, dbg("%s - port %d", __func__, port->number); /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ if (tty) tty->low_latency = 1; Loading @@ -137,7 +138,8 @@ int usb_serial_generic_open(struct tty_struct *tty, if (serial->num_bulk_in) { /* Start reading from the device */ usb_fill_bulk_urb(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ((serial->type->read_bulk_callback) ? Loading @@ -146,7 +148,9 @@ int usb_serial_generic_open(struct tty_struct *tty, port); result = usb_submit_urb(port->read_urb, GFP_KERNEL); if (result) dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); } return result; Loading Loading @@ -211,7 +215,7 @@ int usb_serial_generic_write(struct tty_struct *tty, if (count == 0) { dbg("%s - write request of 0 bytes", __func__); return (0); return 0; } /* only do something if we have a bulk out endpoint */ Loading @@ -226,7 +230,8 @@ int usb_serial_generic_write(struct tty_struct *tty, port->write_urb_busy = 1; spin_unlock_irqrestore(&port->lock, flags); count = (count > port->bulk_out_size) ? port->bulk_out_size : count; count = (count > port->bulk_out_size) ? port->bulk_out_size : count; memcpy(port->write_urb->transfer_buffer, buf, count); data = port->write_urb->transfer_buffer; Loading @@ -239,14 +244,18 @@ int usb_serial_generic_write(struct tty_struct *tty, port->write_urb->transfer_buffer, count, ((serial->type->write_bulk_callback) ? serial->type->write_bulk_callback : usb_serial_generic_write_bulk_callback), port); usb_serial_generic_write_bulk_callback), port); /* send the data out the bulk port */ port->write_urb_busy = 1; result = usb_submit_urb(port->write_urb, GFP_ATOMIC); if (result) { dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); /* don't have to grab the lock here, as we will retry if != 0 */ dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); /* don't have to grab the lock here, as we will retry if != 0 */ port->write_urb_busy = 0; } else result = count; Loading Loading @@ -312,7 +321,9 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) usb_serial_generic_read_bulk_callback), port); result = usb_submit_urb(urb, mem_flags); if (result) dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); } /* Push data to tty layer and resubmit the bulk read URB */ Loading Loading @@ -349,17 +360,18 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb) return; } usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); /* Throttle the device if requested by tty */ spin_lock_irqsave(&port->lock, flags); if (!(port->throttled = port->throttle_req)) { port->throttled = port->throttle_req; if (!port->throttled) { spin_unlock_irqrestore(&port->lock, flags); flush_and_resubmit_read_urb(port); } else { } else spin_unlock_irqrestore(&port->lock, flags); } } EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); void usb_serial_generic_write_bulk_callback(struct urb *urb) Loading Loading @@ -420,8 +432,7 @@ void usb_serial_generic_shutdown (struct usb_serial *serial) dbg("%s", __func__); /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) generic_cleanup(serial->port[i]); } } Loading
drivers/usb/serial/generic.c +49 −38 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <linux/moduleparam.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <asm/uaccess.h> #include <linux/uaccess.h> static int debug; Loading Loading @@ -89,7 +89,8 @@ int usb_serial_generic_register (int _debug) #ifdef CONFIG_USB_SERIAL_GENERIC generic_device_ids[0].idVendor = vendor; generic_device_ids[0].idProduct = product; generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; /* register our generic driver with ourselves */ retval = usb_serial_register(&usb_serial_generic_device); Loading Loading @@ -121,9 +122,9 @@ int usb_serial_generic_open(struct tty_struct *tty, dbg("%s - port %d", __func__, port->number); /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ /* force low_latency on so that our tty_push actually forces the data through, otherwise it is scheduled, and with high data rates (like with OHCI) data can get lost. */ if (tty) tty->low_latency = 1; Loading @@ -137,7 +138,8 @@ int usb_serial_generic_open(struct tty_struct *tty, if (serial->num_bulk_in) { /* Start reading from the device */ usb_fill_bulk_urb(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ((serial->type->read_bulk_callback) ? Loading @@ -146,7 +148,9 @@ int usb_serial_generic_open(struct tty_struct *tty, port); result = usb_submit_urb(port->read_urb, GFP_KERNEL); if (result) dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); } return result; Loading Loading @@ -211,7 +215,7 @@ int usb_serial_generic_write(struct tty_struct *tty, if (count == 0) { dbg("%s - write request of 0 bytes", __func__); return (0); return 0; } /* only do something if we have a bulk out endpoint */ Loading @@ -226,7 +230,8 @@ int usb_serial_generic_write(struct tty_struct *tty, port->write_urb_busy = 1; spin_unlock_irqrestore(&port->lock, flags); count = (count > port->bulk_out_size) ? port->bulk_out_size : count; count = (count > port->bulk_out_size) ? port->bulk_out_size : count; memcpy(port->write_urb->transfer_buffer, buf, count); data = port->write_urb->transfer_buffer; Loading @@ -239,14 +244,18 @@ int usb_serial_generic_write(struct tty_struct *tty, port->write_urb->transfer_buffer, count, ((serial->type->write_bulk_callback) ? serial->type->write_bulk_callback : usb_serial_generic_write_bulk_callback), port); usb_serial_generic_write_bulk_callback), port); /* send the data out the bulk port */ port->write_urb_busy = 1; result = usb_submit_urb(port->write_urb, GFP_ATOMIC); if (result) { dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); /* don't have to grab the lock here, as we will retry if != 0 */ dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); /* don't have to grab the lock here, as we will retry if != 0 */ port->write_urb_busy = 0; } else result = count; Loading Loading @@ -312,7 +321,9 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) usb_serial_generic_read_bulk_callback), port); result = usb_submit_urb(urb, mem_flags); if (result) dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); } /* Push data to tty layer and resubmit the bulk read URB */ Loading Loading @@ -349,17 +360,18 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb) return; } usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); /* Throttle the device if requested by tty */ spin_lock_irqsave(&port->lock, flags); if (!(port->throttled = port->throttle_req)) { port->throttled = port->throttle_req; if (!port->throttled) { spin_unlock_irqrestore(&port->lock, flags); flush_and_resubmit_read_urb(port); } else { } else spin_unlock_irqrestore(&port->lock, flags); } } EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); void usb_serial_generic_write_bulk_callback(struct urb *urb) Loading Loading @@ -420,8 +432,7 @@ void usb_serial_generic_shutdown (struct usb_serial *serial) dbg("%s", __func__); /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) generic_cleanup(serial->port[i]); } }