Skip to content

Commit e642158

Browse files
committed
USB: serial: opticon: stop all I/O on close()
Make sure to stop any submitted write URBs on close(). Note that the tty layer will wait up to 30 seconds for the buffers to drain before close() is called. Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent a00e718 commit e642158

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/usb/serial/opticon.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ struct opticon_private {
4242
bool cts;
4343
int outstanding_urbs;
4444
int outstanding_bytes;
45+
46+
struct usb_anchor anchor;
4547
};
4648

4749

@@ -150,6 +152,15 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
150152
return res;
151153
}
152154

155+
static void opticon_close(struct usb_serial_port *port)
156+
{
157+
struct opticon_private *priv = usb_get_serial_port_data(port);
158+
159+
usb_kill_anchored_urbs(&priv->anchor);
160+
161+
usb_serial_generic_close(port);
162+
}
163+
153164
static void opticon_write_control_callback(struct urb *urb)
154165
{
155166
struct usb_serial_port *port = urb->context;
@@ -226,10 +237,13 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
226237
(unsigned char *)dr, buffer, count,
227238
opticon_write_control_callback, port);
228239

240+
usb_anchor_urb(urb, &priv->anchor);
241+
229242
/* send it down the pipe */
230243
ret = usb_submit_urb(urb, GFP_ATOMIC);
231244
if (ret) {
232245
dev_err(&port->dev, "failed to submit write urb: %d\n", ret);
246+
usb_unanchor_urb(urb);
233247
goto error;
234248
}
235249

@@ -364,6 +378,7 @@ static int opticon_port_probe(struct usb_serial_port *port)
364378
return -ENOMEM;
365379

366380
spin_lock_init(&priv->lock);
381+
init_usb_anchor(&priv->anchor);
367382

368383
usb_set_serial_port_data(port, priv);
369384

@@ -391,6 +406,7 @@ static struct usb_serial_driver opticon_device = {
391406
.port_probe = opticon_port_probe,
392407
.port_remove = opticon_port_remove,
393408
.open = opticon_open,
409+
.close = opticon_close,
394410
.write = opticon_write,
395411
.write_room = opticon_write_room,
396412
.chars_in_buffer = opticon_chars_in_buffer,

0 commit comments

Comments
 (0)