Skip to content

Commit eaa5199

Browse files
committed
Merge tag 'usb-serial-5.6-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next
Johan writes: Here are the USB-serial updates for 5.6-rc1, including: - a missing ir-usb endpoint sanity check - fixes for two long-standing regressions in ir-usb - opticon chars_in_buffer support Included are also various clean ups. All have been in linux-next with no reported issues. Signed-off-by: Johan Hovold <[email protected]> * tag 'usb-serial-5.6-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: USB: serial: cyberjack: fix spelling mistake "To" -> "Too" USB: serial: ir-usb: simplify endpoint check USB: serial: ir-usb: make set_termios synchronous USB: serial: ir-usb: fix IrLAP framing USB: serial: ir-usb: fix link-speed handling USB: serial: ir-usb: add missing endpoint sanity check USB: serial: garmin_gps: Use flexible-array member USB: serial: opticon: stop all I/O on close() USB: serial: opticon: add chars_in_buffer() implementation
2 parents 8800826 + 19c64e7 commit eaa5199

File tree

5 files changed

+172
-91
lines changed

5 files changed

+172
-91
lines changed

drivers/usb/serial/cyberjack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static void cyberjack_read_int_callback(struct urb *urb)
276276
old_rdtodo = priv->rdtodo;
277277

278278
if (old_rdtodo > SHRT_MAX - size) {
279-
dev_dbg(dev, "To many bulk_in urbs to do.\n");
279+
dev_dbg(dev, "Too many bulk_in urbs to do.\n");
280280
spin_unlock_irqrestore(&priv->lock, flags);
281281
goto resubmit;
282282
}

drivers/usb/serial/garmin_gps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct garmin_packet {
104104
int seq;
105105
/* the real size of the data array, always > 0 */
106106
int size;
107-
__u8 data[1];
107+
__u8 data[];
108108
};
109109

110110
/* structure used to keep the current state of the driver */

drivers/usb/serial/ir-usb.c

Lines changed: 114 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ static int buffer_size;
4545
static int xbof = -1;
4646

4747
static int ir_startup (struct usb_serial *serial);
48-
static int ir_open(struct tty_struct *tty, struct usb_serial_port *port);
49-
static int ir_prepare_write_buffer(struct usb_serial_port *port,
50-
void *dest, size_t size);
48+
static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
49+
const unsigned char *buf, int count);
50+
static int ir_write_room(struct tty_struct *tty);
51+
static void ir_write_bulk_callback(struct urb *urb);
5152
static void ir_process_read_urb(struct urb *urb);
5253
static void ir_set_termios(struct tty_struct *tty,
5354
struct usb_serial_port *port, struct ktermios *old_termios);
@@ -75,10 +76,13 @@ static struct usb_serial_driver ir_device = {
7576
.description = "IR Dongle",
7677
.id_table = ir_id_table,
7778
.num_ports = 1,
79+
.num_bulk_in = 1,
80+
.num_bulk_out = 1,
7881
.set_termios = ir_set_termios,
7982
.attach = ir_startup,
80-
.open = ir_open,
81-
.prepare_write_buffer = ir_prepare_write_buffer,
83+
.write = ir_write,
84+
.write_room = ir_write_room,
85+
.write_bulk_callback = ir_write_bulk_callback,
8286
.process_read_urb = ir_process_read_urb,
8387
};
8488

@@ -251,35 +255,102 @@ static int ir_startup(struct usb_serial *serial)
251255
return 0;
252256
}
253257

254-
static int ir_open(struct tty_struct *tty, struct usb_serial_port *port)
258+
static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
259+
const unsigned char *buf, int count)
255260
{
256-
int i;
261+
struct urb *urb = NULL;
262+
unsigned long flags;
263+
int ret;
257264

258-
for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
259-
port->write_urbs[i]->transfer_flags = URB_ZERO_PACKET;
265+
if (port->bulk_out_size == 0)
266+
return -EINVAL;
260267

261-
/* Start reading from the device */
262-
return usb_serial_generic_open(tty, port);
263-
}
268+
if (count == 0)
269+
return 0;
264270

265-
static int ir_prepare_write_buffer(struct usb_serial_port *port,
266-
void *dest, size_t size)
267-
{
268-
unsigned char *buf = dest;
269-
int count;
271+
count = min(count, port->bulk_out_size - 1);
272+
273+
spin_lock_irqsave(&port->lock, flags);
274+
if (__test_and_clear_bit(0, &port->write_urbs_free)) {
275+
urb = port->write_urbs[0];
276+
port->tx_bytes += count;
277+
}
278+
spin_unlock_irqrestore(&port->lock, flags);
279+
280+
if (!urb)
281+
return 0;
270282

271283
/*
272284
* The first byte of the packet we send to the device contains an
273-
* inbound header which indicates an additional number of BOFs and
285+
* outbound header which indicates an additional number of BOFs and
274286
* a baud rate change.
275287
*
276288
* See section 5.4.2.2 of the USB IrDA spec.
277289
*/
278-
*buf = ir_xbof | ir_baud;
290+
*(u8 *)urb->transfer_buffer = ir_xbof | ir_baud;
291+
292+
memcpy(urb->transfer_buffer + 1, buf, count);
293+
294+
urb->transfer_buffer_length = count + 1;
295+
urb->transfer_flags = URB_ZERO_PACKET;
296+
297+
ret = usb_submit_urb(urb, GFP_ATOMIC);
298+
if (ret) {
299+
dev_err(&port->dev, "failed to submit write urb: %d\n", ret);
300+
301+
spin_lock_irqsave(&port->lock, flags);
302+
__set_bit(0, &port->write_urbs_free);
303+
port->tx_bytes -= count;
304+
spin_unlock_irqrestore(&port->lock, flags);
305+
306+
return ret;
307+
}
308+
309+
return count;
310+
}
311+
312+
static void ir_write_bulk_callback(struct urb *urb)
313+
{
314+
struct usb_serial_port *port = urb->context;
315+
int status = urb->status;
316+
unsigned long flags;
317+
318+
spin_lock_irqsave(&port->lock, flags);
319+
__set_bit(0, &port->write_urbs_free);
320+
port->tx_bytes -= urb->transfer_buffer_length - 1;
321+
spin_unlock_irqrestore(&port->lock, flags);
322+
323+
switch (status) {
324+
case 0:
325+
break;
326+
case -ENOENT:
327+
case -ECONNRESET:
328+
case -ESHUTDOWN:
329+
dev_dbg(&port->dev, "write urb stopped: %d\n", status);
330+
return;
331+
case -EPIPE:
332+
dev_err(&port->dev, "write urb stopped: %d\n", status);
333+
return;
334+
default:
335+
dev_err(&port->dev, "nonzero write-urb status: %d\n", status);
336+
break;
337+
}
338+
339+
usb_serial_port_softint(port);
340+
}
279341

280-
count = kfifo_out_locked(&port->write_fifo, buf + 1, size - 1,
281-
&port->lock);
282-
return count + 1;
342+
static int ir_write_room(struct tty_struct *tty)
343+
{
344+
struct usb_serial_port *port = tty->driver_data;
345+
int count = 0;
346+
347+
if (port->bulk_out_size == 0)
348+
return 0;
349+
350+
if (test_bit(0, &port->write_urbs_free))
351+
count = port->bulk_out_size - 1;
352+
353+
return count;
283354
}
284355

285356
static void ir_process_read_urb(struct urb *urb)
@@ -304,23 +375,15 @@ static void ir_process_read_urb(struct urb *urb)
304375
tty_flip_buffer_push(&port->port);
305376
}
306377

307-
static void ir_set_termios_callback(struct urb *urb)
308-
{
309-
kfree(urb->transfer_buffer);
310-
311-
if (urb->status)
312-
dev_dbg(&urb->dev->dev, "%s - non-zero urb status: %d\n",
313-
__func__, urb->status);
314-
}
315-
316378
static void ir_set_termios(struct tty_struct *tty,
317379
struct usb_serial_port *port, struct ktermios *old_termios)
318380
{
319-
struct urb *urb;
381+
struct usb_device *udev = port->serial->dev;
320382
unsigned char *transfer_buffer;
321-
int result;
383+
int actual_length;
322384
speed_t baud;
323385
int ir_baud;
386+
int ret;
324387

325388
baud = tty_get_baud_rate(tty);
326389

@@ -332,34 +395,34 @@ static void ir_set_termios(struct tty_struct *tty,
332395

333396
switch (baud) {
334397
case 2400:
335-
ir_baud = USB_IRDA_BR_2400;
398+
ir_baud = USB_IRDA_LS_2400;
336399
break;
337400
case 9600:
338-
ir_baud = USB_IRDA_BR_9600;
401+
ir_baud = USB_IRDA_LS_9600;
339402
break;
340403
case 19200:
341-
ir_baud = USB_IRDA_BR_19200;
404+
ir_baud = USB_IRDA_LS_19200;
342405
break;
343406
case 38400:
344-
ir_baud = USB_IRDA_BR_38400;
407+
ir_baud = USB_IRDA_LS_38400;
345408
break;
346409
case 57600:
347-
ir_baud = USB_IRDA_BR_57600;
410+
ir_baud = USB_IRDA_LS_57600;
348411
break;
349412
case 115200:
350-
ir_baud = USB_IRDA_BR_115200;
413+
ir_baud = USB_IRDA_LS_115200;
351414
break;
352415
case 576000:
353-
ir_baud = USB_IRDA_BR_576000;
416+
ir_baud = USB_IRDA_LS_576000;
354417
break;
355418
case 1152000:
356-
ir_baud = USB_IRDA_BR_1152000;
419+
ir_baud = USB_IRDA_LS_1152000;
357420
break;
358421
case 4000000:
359-
ir_baud = USB_IRDA_BR_4000000;
422+
ir_baud = USB_IRDA_LS_4000000;
360423
break;
361424
default:
362-
ir_baud = USB_IRDA_BR_9600;
425+
ir_baud = USB_IRDA_LS_9600;
363426
baud = 9600;
364427
}
365428

@@ -375,42 +438,22 @@ static void ir_set_termios(struct tty_struct *tty,
375438
/*
376439
* send the baud change out on an "empty" data packet
377440
*/
378-
urb = usb_alloc_urb(0, GFP_KERNEL);
379-
if (!urb)
380-
return;
381-
382441
transfer_buffer = kmalloc(1, GFP_KERNEL);
383442
if (!transfer_buffer)
384-
goto err_buf;
443+
return;
385444

386445
*transfer_buffer = ir_xbof | ir_baud;
387446

388-
usb_fill_bulk_urb(
389-
urb,
390-
port->serial->dev,
391-
usb_sndbulkpipe(port->serial->dev,
392-
port->bulk_out_endpointAddress),
393-
transfer_buffer,
394-
1,
395-
ir_set_termios_callback,
396-
port);
397-
398-
urb->transfer_flags = URB_ZERO_PACKET;
399-
400-
result = usb_submit_urb(urb, GFP_KERNEL);
401-
if (result) {
402-
dev_err(&port->dev, "%s - failed to submit urb: %d\n",
403-
__func__, result);
404-
goto err_subm;
447+
ret = usb_bulk_msg(udev,
448+
usb_sndbulkpipe(udev, port->bulk_out_endpointAddress),
449+
transfer_buffer, 1, &actual_length, 5000);
450+
if (ret || actual_length != 1) {
451+
if (actual_length != 1)
452+
ret = -EIO;
453+
dev_err(&port->dev, "failed to change line speed: %d\n", ret);
405454
}
406455

407-
usb_free_urb(urb);
408-
409-
return;
410-
err_subm:
411456
kfree(transfer_buffer);
412-
err_buf:
413-
usb_free_urb(urb);
414457
}
415458

416459
static int __init ir_init(void)

0 commit comments

Comments
 (0)