aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_buffer.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2011-03-21 06:25:08 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-04-22 20:31:53 -0400
commitb1c43f82c5aa265442f82dba31ce985ebb7aa71c (patch)
tree8b344d8d5355b30e8deff901180edc708a653227 /drivers/tty/tty_buffer.c
parente9a470f445271eb157ee860a93b062324402fc3a (diff)
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>
Diffstat (limited to 'drivers/tty/tty_buffer.c')
-rw-r--r--drivers/tty/tty_buffer.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index f1a7918d71a..46de2e075da 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -416,6 +416,7 @@ static void flush_to_ldisc(struct work_struct *work)
416 struct tty_buffer *head, *tail = tty->buf.tail; 416 struct tty_buffer *head, *tail = tty->buf.tail;
417 int seen_tail = 0; 417 int seen_tail = 0;
418 while ((head = tty->buf.head) != NULL) { 418 while ((head = tty->buf.head) != NULL) {
419 int copied;
419 int count; 420 int count;
420 char *char_buf; 421 char *char_buf;
421 unsigned char *flag_buf; 422 unsigned char *flag_buf;
@@ -442,17 +443,19 @@ static void flush_to_ldisc(struct work_struct *work)
442 line discipline as we want to empty the queue */ 443 line discipline as we want to empty the queue */
443 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) 444 if (test_bit(TTY_FLUSHPENDING, &tty->flags))
444 break; 445 break;
445 if (!tty->receive_room || seen_tail)
446 break;
447 if (count > tty->receive_room)
448 count = tty->receive_room;
449 char_buf = head->char_buf_ptr + head->read; 446 char_buf = head->char_buf_ptr + head->read;
450 flag_buf = head->flag_buf_ptr + head->read; 447 flag_buf = head->flag_buf_ptr + head->read;
451 head->read += count;
452 spin_unlock_irqrestore(&tty->buf.lock, flags); 448 spin_unlock_irqrestore(&tty->buf.lock, flags);
453 disc->ops->receive_buf(tty, char_buf, 449 copied = disc->ops->receive_buf(tty, char_buf,
454 flag_buf, count); 450 flag_buf, count);
455 spin_lock_irqsave(&tty->buf.lock, flags); 451 spin_lock_irqsave(&tty->buf.lock, flags);
452
453 head->read += copied;
454
455 if (copied == 0 || seen_tail) {
456 schedule_work(&tty->buf.work);
457 break;
458 }
456 } 459 }
457 clear_bit(TTY_FLUSHING, &tty->flags); 460 clear_bit(TTY_FLUSHING, &tty->flags);
458 } 461 }