diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2013-06-15 10:04:23 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-23 20:02:21 -0400 |
commit | 862eeffef1b465a12412f4ae6e5987ae292c968d (patch) | |
tree | 4fc9ae42e841d6402906a12bf1dbd1594c179b3a | |
parent | addaebccf63a8c9f7c7a62ce1ceb9da4307c5a1c (diff) |
n_tty: Replace echo_cnt with computed value
Prepare for lockless echo_buf handling; compute current byte count
of echo_buf from head and tail indices.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/n_tty.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 18d72a0258ce..8406a23ee920 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c | |||
@@ -110,7 +110,6 @@ struct n_tty_data { | |||
110 | unsigned char *echo_buf; | 110 | unsigned char *echo_buf; |
111 | size_t echo_head; | 111 | size_t echo_head; |
112 | size_t echo_tail; | 112 | size_t echo_tail; |
113 | unsigned int echo_cnt; | ||
114 | 113 | ||
115 | /* protected by output lock */ | 114 | /* protected by output lock */ |
116 | unsigned int column; | 115 | unsigned int column; |
@@ -336,7 +335,7 @@ static void reset_buffer_flags(struct n_tty_data *ldata) | |||
336 | ldata->read_head = ldata->canon_head = ldata->read_tail = 0; | 335 | ldata->read_head = ldata->canon_head = ldata->read_tail = 0; |
337 | 336 | ||
338 | mutex_lock(&ldata->echo_lock); | 337 | mutex_lock(&ldata->echo_lock); |
339 | ldata->echo_head = ldata->echo_tail = ldata->echo_cnt = 0; | 338 | ldata->echo_head = ldata->echo_tail = 0; |
340 | mutex_unlock(&ldata->echo_lock); | 339 | mutex_unlock(&ldata->echo_lock); |
341 | 340 | ||
342 | ldata->erasing = 0; | 341 | ldata->erasing = 0; |
@@ -654,7 +653,7 @@ static void process_echoes(struct tty_struct *tty) | |||
654 | size_t tail; | 653 | size_t tail; |
655 | unsigned char c; | 654 | unsigned char c; |
656 | 655 | ||
657 | if (!ldata->echo_cnt) | 656 | if (ldata->echo_head == ldata->echo_tail) |
658 | return; | 657 | return; |
659 | 658 | ||
660 | mutex_lock(&ldata->output_lock); | 659 | mutex_lock(&ldata->output_lock); |
@@ -663,7 +662,7 @@ static void process_echoes(struct tty_struct *tty) | |||
663 | space = tty_write_room(tty); | 662 | space = tty_write_room(tty); |
664 | 663 | ||
665 | tail = ldata->echo_tail; | 664 | tail = ldata->echo_tail; |
666 | nr = ldata->echo_cnt; | 665 | nr = ldata->echo_head - ldata->echo_tail; |
667 | while (nr > 0) { | 666 | while (nr > 0) { |
668 | c = echo_buf(ldata, tail); | 667 | c = echo_buf(ldata, tail); |
669 | if (c == ECHO_OP_START) { | 668 | if (c == ECHO_OP_START) { |
@@ -779,7 +778,6 @@ static void process_echoes(struct tty_struct *tty) | |||
779 | } | 778 | } |
780 | 779 | ||
781 | ldata->echo_tail = tail; | 780 | ldata->echo_tail = tail; |
782 | ldata->echo_cnt = nr; | ||
783 | 781 | ||
784 | mutex_unlock(&ldata->echo_lock); | 782 | mutex_unlock(&ldata->echo_lock); |
785 | mutex_unlock(&ldata->output_lock); | 783 | mutex_unlock(&ldata->output_lock); |
@@ -800,24 +798,20 @@ static void process_echoes(struct tty_struct *tty) | |||
800 | 798 | ||
801 | static void add_echo_byte(unsigned char c, struct n_tty_data *ldata) | 799 | static void add_echo_byte(unsigned char c, struct n_tty_data *ldata) |
802 | { | 800 | { |
803 | if (ldata->echo_cnt == N_TTY_BUF_SIZE) { | 801 | if (ldata->echo_head - ldata->echo_tail == N_TTY_BUF_SIZE) { |
804 | size_t head = ldata->echo_head; | 802 | size_t head = ldata->echo_head; |
805 | /* | 803 | /* |
806 | * Since the buffer start position needs to be advanced, | 804 | * Since the buffer start position needs to be advanced, |
807 | * be sure to step by a whole operation byte group. | 805 | * be sure to step by a whole operation byte group. |
808 | */ | 806 | */ |
809 | if (echo_buf(ldata, head) == ECHO_OP_START) { | 807 | if (echo_buf(ldata, head) == ECHO_OP_START) { |
810 | if (echo_buf(ldata, head + 1) == ECHO_OP_ERASE_TAB) { | 808 | if (echo_buf(ldata, head + 1) == ECHO_OP_ERASE_TAB) |
811 | ldata->echo_tail += 3; | 809 | ldata->echo_tail += 3; |
812 | ldata->echo_cnt -= 2; | 810 | else |
813 | } else { | ||
814 | ldata->echo_tail += 2; | 811 | ldata->echo_tail += 2; |
815 | ldata->echo_cnt -= 1; | ||
816 | } | ||
817 | } else | 812 | } else |
818 | ldata->echo_tail++; | 813 | ldata->echo_tail++; |
819 | } else | 814 | } |
820 | ldata->echo_cnt++; | ||
821 | 815 | ||
822 | *echo_buf_addr(ldata, ldata->echo_head++) = c; | 816 | *echo_buf_addr(ldata, ldata->echo_head++) = c; |
823 | } | 817 | } |