Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 810360a0 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman
Browse files

USB: serial: grab disconnect mutex in chars_in_buffer



Grab disconnect mutex in chars_in_buffer before checking disconnected
flag or calling driver specific function.

This allows subdrivers to query any hardware buffer status without
having to handle the locking themselves.

Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fcdb6a21
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -361,15 +361,21 @@ static int serial_write_room(struct tty_struct *tty)
static int serial_chars_in_buffer(struct tty_struct *tty)
{
	struct usb_serial_port *port = tty->driver_data;
	struct usb_serial *serial = port->serial;
	int count = 0;

	dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);

	mutex_lock(&serial->disc_mutex);
	/* if the device was unplugged then any remaining characters
	   fell out of the connector ;) */
	if (port->serial->disconnected)
		return 0;
	/* pass on to the driver specific version of this function */
	return port->serial->type->chars_in_buffer(tty);
	if (serial->disconnected)
		count = 0;
	else
		count = serial->type->chars_in_buffer(tty);
	mutex_unlock(&serial->disc_mutex);

	return count;
}

static void serial_throttle(struct tty_struct *tty)