Silence unused parameter in elmcan_do_set_bittiming()
[elmcan.git] / module / elmcan.c
index b85c1c21b73d9f0acfdaf26eceeef393bd3849ab..07899f7e982dadb94a0d42e58b5597537d741a7a 100644 (file)
@@ -194,7 +194,11 @@ static void elm327_send(struct elmcan *elm, const void *buf, size_t len)
 }
 
 
-/* Take the ELM327 out of almost any state and back into command mode. */
+/* Take the ELM327 out of almost any state and back into command mode.
+ * We send ELM327_MAGIC_CHAR which will either abort any running
+ * operation, or be echoed back to us in case we're already in command
+ * mode.
+ */
 static void elm327_kick_into_cmd_mode(struct elmcan *elm)
 {
        if (elm->state != ELM_GETMAGICCHAR && elm->state != ELM_GETPROMPT) {
@@ -694,7 +698,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
        switch (elm->state) {
        case ELM_NOTINIT:
                elm->rxfill = 0;
-               return;
+               break;
 
        case ELM_GETMAGICCHAR:
        {
@@ -716,7 +720,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
 
                elm327_drop_bytes(elm, i);
 
-               return;
+               break;
        }
 
        case ELM_GETPROMPT:
@@ -725,7 +729,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
                        elm327_handle_prompt(elm);
 
                elm->rxfill = 0;
-               return;
+               break;
 
        case ELM_RECEIVING:
                /* Find <CR> delimiting feedback lines. */
@@ -742,7 +746,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
                        netdev_err(elm->dev,
                                "RX buffer overflow. Faulty ELM327 or UART?\n");
                        elm327_hw_failure(elm);
-                       return;
+                       break;
                } else if (len == elm->rxfill) {
                        if (elm327_is_ready_char(elm->rxbuf[elm->rxfill - 1])) {
                                /* The ELM327's AT ST response timeout ran out,
@@ -752,13 +756,13 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
                                elm->rxfill = 0;
 
                                elm327_handle_prompt(elm);
-                               return;
+                               break;
                        }
 
                        /* No <CR> found - we haven't received a full line yet.
                         * Wait for more data.
                         */
-                       return;
+                       break;
                }
 
                /* We have a full line to parse. */
@@ -893,16 +897,12 @@ out:
        return NETDEV_TX_OK;
 }
 
-static int elmcan_netdev_change_mtu(struct net_device *dev, int new_mtu)
-{
-       return -EINVAL;
-}
 
 static const struct net_device_ops elmcan_netdev_ops = {
        .ndo_open       = elmcan_netdev_open,
        .ndo_stop       = elmcan_netdev_close,
        .ndo_start_xmit = elmcan_netdev_start_xmit,
-       .ndo_change_mtu = elmcan_netdev_change_mtu,
+       .ndo_change_mtu = can_change_mtu,
 };
 
 
@@ -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.
@@ -962,11 +979,9 @@ static void elmcan_ldisc_rx(struct tty_struct *tty,
                return;
 
        spin_lock_bh(&elm->lock);
-       if (elm->hw_failure) {
-               spin_unlock_bh(&elm->lock);
 
-               put_elm(elm);
-               return;
+       if (elm->hw_failure) {
+               goto out;
        }
 
        while (count-- && elm->rxfill < sizeof(elm->rxbuf)) {
@@ -974,10 +989,8 @@ static void elmcan_ldisc_rx(struct tty_struct *tty,
                        netdev_err(elm->dev, "Error in received character stream. Check your wiring.");
 
                        elm327_hw_failure(elm);
-                       spin_unlock_bh(&elm->lock);
 
-                       put_elm(elm);
-                       return;
+                       goto out;
                }
 
                /* Ignore NUL characters, which the PIC microcontroller may
@@ -989,27 +1002,13 @@ 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);
                                elm327_hw_failure(elm);
-                               spin_unlock_bh(&elm->lock);
 
-                               put_elm(elm);
-                               return;
+                               goto out;
                        }
 
                        elm->rxbuf[elm->rxfill++] = *cp;
@@ -1022,15 +1021,14 @@ static void elmcan_ldisc_rx(struct tty_struct *tty,
                netdev_err(elm->dev, "Receive buffer overflowed. Bad chip or wiring?");
 
                elm327_hw_failure(elm);
-               spin_unlock_bh(&elm->lock);
 
-               put_elm(elm);
-               return;
+               goto out;
        }
 
        elm327_parse_rxbuf(elm);
-       spin_unlock_bh(&elm->lock);
 
+out:
+       spin_unlock_bh(&elm->lock);
        put_elm(elm);
 }
 
@@ -1115,6 +1113,8 @@ static const u32 elmcan_bitrate_const[64] = {
 /* Dummy needed to use bitrate_const */
 static int elmcan_do_set_bittiming(struct net_device *netdev)
 {
+       (void)netdev;
+
        return 0;
 }
 
@@ -1265,12 +1265,6 @@ static struct tty_ldisc_ops elmcan_ldisc = {
 
 
 
-
-
- /************************************************************************
-  *            Module init/exit                                *
-  ************************************************************************/
-
 static int __init elmcan_init(void)
 {
        int status;