[PATCH v3 2/5] tty: Simplify receive flow control char logic

From: Ilpo Järvinen
Date: Mon Apr 11 2022 - 05:50:05 EST


Add a helper to check if the character is a flow control one.
Reorder return places, add else for the case where START_CHAR
and STOP_CHAR are the same, w/o else both would match.

This seems cleanest approach once skipping due to lookahead
is added by the next patch. Its downside is the duplicated
START_CHAR and STOP_CHAR checks.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
---
drivers/tty/n_tty.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index c7edfc001fd0..90b3e06cbeb1 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1220,20 +1220,25 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)
process_echoes(tty);
}

+static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c)
+{
+ return c == START_CHAR(tty) || c == STOP_CHAR(tty);
+}
+
/* Returns true if c is consumed as flow-control character */
static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, unsigned char c)
{
+ if (!n_tty_is_char_flow_ctrl(tty, c))
+ return false;
+
if (c == START_CHAR(tty)) {
start_tty(tty);
process_echoes(tty);
- return true;
- }
- if (c == STOP_CHAR(tty)) {
+ } else if (c == STOP_CHAR(tty)) {
stop_tty(tty);
- return true;
}

- return false;
+ return true;
}

static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
--
2.30.2