tty: make receive_buf() return the amout of bytes received
it makes it simpler to keep track of the amount of bytes received and simplifies how flush_to_ldisc counts the remaining bytes. It also fixes a bug of lost bytes on n_tty when flushing too many bytes via the USB serial gadget driver. Tested-by: Stefan Bigler <stefan.bigler@keymile.com> Tested-by: Toby Gray <toby.gray@realvnc.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
e9a470f445
commit
b1c43f82c5
@ -416,6 +416,7 @@ static void flush_to_ldisc(struct work_struct *work)
|
||||
struct tty_buffer *head, *tail = tty->buf.tail;
|
||||
int seen_tail = 0;
|
||||
while ((head = tty->buf.head) != NULL) {
|
||||
int copied;
|
||||
int count;
|
||||
char *char_buf;
|
||||
unsigned char *flag_buf;
|
||||
@ -442,17 +443,19 @@ static void flush_to_ldisc(struct work_struct *work)
|
||||
line discipline as we want to empty the queue */
|
||||
if (test_bit(TTY_FLUSHPENDING, &tty->flags))
|
||||
break;
|
||||
if (!tty->receive_room || seen_tail)
|
||||
break;
|
||||
if (count > tty->receive_room)
|
||||
count = tty->receive_room;
|
||||
char_buf = head->char_buf_ptr + head->read;
|
||||
flag_buf = head->flag_buf_ptr + head->read;
|
||||
head->read += count;
|
||||
spin_unlock_irqrestore(&tty->buf.lock, flags);
|
||||
disc->ops->receive_buf(tty, char_buf,
|
||||
copied = disc->ops->receive_buf(tty, char_buf,
|
||||
flag_buf, count);
|
||||
spin_lock_irqsave(&tty->buf.lock, flags);
|
||||
|
||||
head->read += copied;
|
||||
|
||||
if (copied == 0 || seen_tail) {
|
||||
schedule_work(&tty->buf.work);
|
||||
break;
|
||||
}
|
||||
}
|
||||
clear_bit(TTY_FLUSHING, &tty->flags);
|
||||
}
|
||||
|
Reference in New Issue
Block a user