Skip to content

Commit bc5b1ec

Browse files
peterhurleygregkh
authored andcommitted
n_tty: Only flush echo output if actually output
Don't have the driver flush received echoes if no echoes were actually output. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cbfd034 commit bc5b1ec

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/tty/n_tty.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,14 @@ static ssize_t process_output_block(struct tty_struct *tty,
646646
* Locking: callers must hold output_lock
647647
*/
648648

649-
static void __process_echoes(struct tty_struct *tty)
649+
static size_t __process_echoes(struct tty_struct *tty)
650650
{
651651
struct n_tty_data *ldata = tty->disc_data;
652-
int space, nr;
652+
int space, old_space;
653653
size_t tail;
654654
unsigned char c;
655655

656-
space = tty_write_room(tty);
656+
old_space = space = tty_write_room(tty);
657657

658658
tail = ldata->echo_tail;
659659
nr = ldata->echo_commit - ldata->echo_tail;
@@ -785,12 +785,13 @@ static void __process_echoes(struct tty_struct *tty)
785785
}
786786

787787
ldata->echo_tail = tail;
788+
return old_space - space;
788789
}
789790

790791
static void commit_echoes(struct tty_struct *tty)
791792
{
792793
struct n_tty_data *ldata = tty->disc_data;
793-
size_t nr, old;
794+
size_t nr, old, echoed;
794795
size_t head;
795796

796797
head = ldata->echo_head;
@@ -805,25 +806,26 @@ static void commit_echoes(struct tty_struct *tty)
805806

806807
mutex_lock(&ldata->output_lock);
807808
ldata->echo_commit = head;
808-
__process_echoes(tty);
809+
echoed = __process_echoes(tty);
809810
mutex_unlock(&ldata->output_lock);
810811

811-
if (tty->ops->flush_chars)
812+
if (echoed && tty->ops->flush_chars)
812813
tty->ops->flush_chars(tty);
813814
}
814815

815816
static void process_echoes(struct tty_struct *tty)
816817
{
817818
struct n_tty_data *ldata = tty->disc_data;
819+
size_t echoed;
818820

819821
if (!L_ECHO(tty) || ldata->echo_commit == ldata->echo_tail)
820822
return;
821823

822824
mutex_lock(&ldata->output_lock);
823-
__process_echoes(tty);
825+
echoed = __process_echoes(tty);
824826
mutex_unlock(&ldata->output_lock);
825827

826-
if (tty->ops->flush_chars)
828+
if (echoed && tty->ops->flush_chars)
827829
tty->ops->flush_chars(tty);
828830
}
829831

0 commit comments

Comments
 (0)