summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2019-02-25 16:35:52 +0100
committernorly <ny-git@enpas.org>2019-02-25 16:35:52 +0100
commit09f98cc94e56158bdc4ab6c317bdd6570f5724b7 (patch)
tree57baeafc04ece5544099c6182fcdc12fe1337ce6
parent7f51e65e33fc33e3d10421648f64eb750a721403 (diff)
Extract RX sanity checker into separate function
-rw-r--r--module/elmcan.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/module/elmcan.c b/module/elmcan.c
index ef6fc6d..239970d 100644
--- a/module/elmcan.c
+++ b/module/elmcan.c
@@ -949,6 +949,23 @@ static void put_elm(struct elmcan *elm)
}
+static bool elmcan_is_valid_rx_char(char c)
+{
+ return (accept_flaky_uart
+ || isdigit(c)
+ || isupper(c)
+ || ELM327_MAGIC_CHAR == c
+ || ELM327_READY_CHAR == c
+ || '<' == c
+ || 'a' == c
+ || 'b' == c
+ || 'v' == c
+ || '.' == c
+ || '?' == c
+ || '\r' == c
+ || ' ' == c);
+}
+
/* Handle incoming ELM327 ASCII data.
* This will not be re-entered while running, but other ldisc
* functions may be called in parallel.
@@ -985,19 +1002,7 @@ static void elmcan_ldisc_rx(struct tty_struct *tty,
/* Check for stray characters on the UART line.
* Likely caused by bad hardware.
*/
- if (!accept_flaky_uart
- && !isdigit(*cp)
- && !isupper(*cp)
- && ELM327_MAGIC_CHAR != *cp
- && ELM327_READY_CHAR != *cp
- && '<' != *cp
- && 'a' != *cp
- && 'b' != *cp
- && 'v' != *cp
- && '.' != *cp
- && '?' != *cp
- && '\r' != *cp
- && ' ' != *cp) {
+ if (!elmcan_is_valid_rx_char(*cp)) {
netdev_err(elm->dev,
"Received illegal character %02x.\n",
*cp);