Skip to content

Commit 1ce7b93

Browse files
jhovoldgregkh
authored andcommitted
USB: serial: reuse generic write urb and bulk-out buffer
Reuse first write urb and bulk-out buffer of the generic write implementation for drivers that rely on port->write_urb rather than allocating them separately. Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fd11961 commit 1ce7b93

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

drivers/usb/serial/usb-serial.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ static void kill_traffic(struct usb_serial_port *port)
563563
int i;
564564

565565
usb_kill_urb(port->read_urb);
566-
usb_kill_urb(port->write_urb);
567566
for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
568567
usb_kill_urb(port->write_urbs[i]);
569568
/*
@@ -596,7 +595,6 @@ static void port_release(struct device *dev)
596595
cancel_work_sync(&port->work);
597596

598597
usb_free_urb(port->read_urb);
599-
usb_free_urb(port->write_urb);
600598
usb_free_urb(port->interrupt_in_urb);
601599
usb_free_urb(port->interrupt_out_urb);
602600
for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) {
@@ -605,7 +603,6 @@ static void port_release(struct device *dev)
605603
}
606604
kfifo_free(&port->write_fifo);
607605
kfree(port->bulk_in_buffer);
608-
kfree(port->bulk_out_buffer);
609606
kfree(port->interrupt_in_buffer);
610607
kfree(port->interrupt_out_buffer);
611608
kfree(port);
@@ -933,29 +930,14 @@ int usb_serial_probe(struct usb_interface *interface,
933930

934931
endpoint = bulk_out_endpoint[i];
935932
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-
}
941933
if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL))
942934
goto probe_error;
943935
buffer_size = serial->type->bulk_out_size;
944936
if (!buffer_size)
945937
buffer_size = usb_endpoint_maxp(endpoint);
946938
port->bulk_out_size = buffer_size;
947939
port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
948-
port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
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);
940+
959941
for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) {
960942
set_bit(j, &port->write_urbs_free);
961943
port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
@@ -978,6 +960,9 @@ int usb_serial_probe(struct usb_interface *interface,
978960
serial->type->write_bulk_callback,
979961
port);
980962
}
963+
964+
port->write_urb = port->write_urbs[0];
965+
port->bulk_out_buffer = port->bulk_out_buffers[0];
981966
}
982967

983968
if (serial->type->read_int_callback) {

0 commit comments

Comments
 (0)