From 52e49620d7faaa7293c6f5df5268738276a0e84e Mon Sep 17 00:00:00 2001
From: Yegor Yefremov <yegorslists@googlemail.com>
Date: Thu, 5 Jan 2017 10:29:07 +0100
Subject: [PATCH] tty: rework flush echo handling

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
 drivers/tty/n_tty.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index f9c584244f72..ff92f7453ea7 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -816,18 +816,19 @@ static void process_echoes(struct tty_struct *tty)
 }
 
 /* NB: echo_mark and echo_head should be equivalent here */
-static void flush_echoes(struct tty_struct *tty)
+static int flush_echoes(struct tty_struct *tty)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
 	if ((!L_ECHO(tty) && !L_ECHONL(tty)) ||
 	    ldata->echo_commit == ldata->echo_head)
-		return;
+		return 0;
 
 	mutex_lock(&ldata->output_lock);
 	ldata->echo_commit = ldata->echo_head;
 	__process_echoes(tty);
 	mutex_unlock(&ldata->output_lock);
+	return 1;
 }
 
 /**
@@ -1645,8 +1646,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
 		else
 			n_tty_receive_buf_standard(tty, cp, fp, count);
 
-		flush_echoes(tty);
-		if (tty->ops->flush_chars)
+		if (flush_echoes(tty) && tty->ops->flush_chars)
 			tty->ops->flush_chars(tty);
 	}
 
-- 
2.17.0

