* The reason to use strings is so we can easily include them in the C code,
* and to avoid hardcoding lengths.
*/
-static inline int elm327_rxbuf_cmp(const u8 *buf, size_t nbytes, const char *reference)
+static inline bool elm327_rxbuf_cmp(const u8 *buf, size_t nbytes, const char *reference)
{
size_t ref_len = strlen(reference);
if (can_dropped_invalid_skb(dev, skb))
return NETDEV_TX_OK;
- /* BHs are already disabled, so no spin_lock_bh().
- * See Documentation/networking/netdevices.txt
+ /* This check will be part of can_dropped_invalid_skb()
+ * in future kernels.
*/
- spin_lock(&elm->lock);
+ if (elm->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+ goto out;
/* We shouldn't get here after a hardware fault:
* can_bus_off() calls netif_carrier_off()
*/
- WARN_ON_ONCE(elm->uart_side_failure);
-
- if (!elm->tty ||
- elm->uart_side_failure ||
- elm->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
- spin_unlock(&elm->lock);
+ if (elm->uart_side_failure) {
+ WARN_ON_ONCE(elm->uart_side_failure);
goto out;
}
netif_stop_queue(dev);
+ /* BHs are already disabled, so no spin_lock_bh().
+ * See Documentation/networking/netdevices.txt
+ */
+ spin_lock(&elm->lock);
elm327_send_frame(elm, frame);
spin_unlock(&elm->lock);
.ndo_change_mtu = can_change_mtu,
};
-static bool can327_is_valid_rx_char(char c)
+static bool can327_is_valid_rx_char(u8 c)
{
- return (isdigit(c) ||
- isupper(c) ||
- c == ELM327_DUMMY_CHAR ||
- c == ELM327_READY_CHAR ||
- c == '<' ||
- c == 'a' ||
- c == 'b' ||
- c == 'v' ||
- c == '.' ||
- c == '?' ||
- c == '\r' ||
- c == ' ');
+ static const bool lut_char_is_valid['z'] = {
+ ['\r'] = true,
+ [' '] = true,
+ ['.'] = true,
+ ['0'] = true, true, true, true, true,
+ ['5'] = true, true, true, true, true,
+ ['<'] = true,
+ [ELM327_READY_CHAR] = true,
+ ['?'] = true,
+ ['A'] = true, true, true, true, true, true, true,
+ ['H'] = true, true, true, true, true, true, true,
+ ['O'] = true, true, true, true, true, true, true,
+ ['V'] = true, true, true, true, true,
+ ['a'] = true,
+ ['b'] = true,
+ ['v'] = true,
+ [ELM327_DUMMY_CHAR] = true,
+ };
+ BUILD_BUG_ON(ELM327_DUMMY_CHAR >= 'z');
+
+ return (c < ARRAY_SIZE(lut_char_is_valid) &&
+ lut_char_is_valid[c]);
}
/* Handle incoming ELM327 ASCII data.
{
struct can327 *elm = (struct can327 *)tty->disc_data;
- spin_lock_bh(&elm->lock);
-
if (elm->uart_side_failure)
- goto out;
+ return;
+
+ spin_lock_bh(&elm->lock);
while (count-- && elm->rxfill < ELM327_SIZE_RXBUF) {
if (fp && *fp++) {
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
/* Ignore NUL characters, which the PIC microcontroller may
*cp);
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
elm->rxbuf[elm->rxfill++] = *cp;
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
elm327_parse_rxbuf(elm);
-
-out:
spin_unlock_bh(&elm->lock);
}
"Failed to write to tty %s.\n",
elm->tty->name);
elm327_uart_side_failure(elm);
+
spin_unlock_bh(&elm->lock);
return;
}
elm->txhead += written;
}
- if (!elm->txleft) {
+ if (!elm->txleft)
clear_bit(TTY_DO_WRITE_WAKEUP, &elm->tty->flags);
- spin_unlock_bh(&elm->lock);
- } else {
- spin_unlock_bh(&elm->lock);
- }
+
+ spin_unlock_bh(&elm->lock);
}
/* Called by the driver when there's room for more data. */
/* Let 'er rip */
err = register_candev(elm->dev);
- if (err)
- goto out_err;
+ if (err) {
+ free_candev(elm->dev);
+ return err;
+ }
netdev_info(elm->dev, "can327 on %s.\n", tty->name);
return 0;
-
-out_err:
- free_candev(elm->dev);
- return err;
}
/* Close down a can327 channel.