Don't count RTR DLC as sent bytes
[elmcan.git] / module / can327.c
index 2d9c44e1df9d81e04b66b707c01e98c2c3a29057..82dbc668271e21f4696f1c9de7eb812d3cc4347b 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
-#include <linux/can/led.h>
 #include <linux/can/rx-offload.h>
 
 /* Line discipline ID number.
@@ -53,8 +52,8 @@
 
 #define ELM327_NAPI_WEIGHT 4
 
-#define ELM327_SIZE_RXBUF 992
 #define ELM327_SIZE_TXBUF 32
+#define ELM327_SIZE_RXBUF 1024
 
 #define ELM327_CAN_CONFIG_SEND_SFF           0x8000
 #define ELM327_CAN_CONFIG_VARIABLE_DLC       0x4000
@@ -85,8 +84,8 @@ struct can327 {
        struct can_rx_offload offload;
 
        /* TTY buffers */
-       u8 rxbuf[ELM327_SIZE_RXBUF];
        u8 txbuf[ELM327_SIZE_TXBUF];
+       u8 rxbuf[ELM327_SIZE_RXBUF];
 
        /* Per-channel lock */
        spinlock_t lock;
@@ -256,7 +255,7 @@ static void elm327_init(struct can327 *elm)
        elm->drop_next_line = 0;
 
        /* We can only set the bitrate as a fraction of 500000.
-        * The bit timing constants in can327_bittiming_const will
+        * The bitrates listed in can327_bitrate_const will
         * limit the user to the right values.
         */
        elm->can_bitrate_divisor = 500000 / elm->can.bittiming.bitrate;
@@ -440,6 +439,7 @@ static int elm327_parse_frame(struct can327 *elm, size_t len)
                /* The line is likely garbled anyway, so bail.
                 * The main code will restart listening.
                 */
+               kfree_skb(skb);
                return -ENODATA;
        }
 
@@ -458,6 +458,7 @@ static int elm327_parse_frame(struct can327 *elm, size_t len)
                /* This is not a well-formatted data line.
                 * Assume it's an error message.
                 */
+               kfree_skb(skb);
                return -ENODATA;
        }
 
@@ -465,6 +466,7 @@ static int elm327_parse_frame(struct can327 *elm, size_t len)
                /* The line is too short to be a valid frame hex dump.
                 * Something interrupted the hex dump or it is invalid.
                 */
+               kfree_skb(skb);
                return -ENODATA;
        }
 
@@ -516,6 +518,7 @@ static int elm327_parse_frame(struct can327 *elm, size_t len)
                 * However, this will correctly drop the state machine back into
                 * command mode.
                 */
+               kfree_skb(skb);
                return -ENODATA;
        }
 
@@ -821,7 +824,6 @@ static int can327_netdev_open(struct net_device *dev)
 
        can_rx_offload_enable(&elm->offload);
 
-       can_led_event(dev, CAN_LED_EVENT_OPEN);
        elm->can.state = CAN_STATE_ERROR_ACTIVE;
        netif_start_queue(dev);
 
@@ -847,7 +849,6 @@ static int can327_netdev_close(struct net_device *dev)
        elm->can.state = CAN_STATE_STOPPED;
        can_rx_offload_del(&elm->offload);
        close_candev(dev);
-       can_led_event(dev, CAN_LED_EVENT_STOP);
 
        return 0;
 }
@@ -886,9 +887,7 @@ static netdev_tx_t can327_netdev_start_xmit(struct sk_buff *skb,
        spin_unlock(&elm->lock);
 
        dev->stats.tx_packets++;
-       dev->stats.tx_bytes += frame->len;
-
-       can_led_event(dev, CAN_LED_EVENT_TX);
+       dev->stats.tx_bytes += frame->can_id & CAN_RTR_FLAG ? 0 : frame->len;
 
 out:
        kfree_skb(skb);
@@ -1048,7 +1047,7 @@ static void can327_ldisc_tx_wakeup(struct tty_struct *tty)
  * or 7/8 of that. Divisors are 1 to 64.
  * Currently we don't implement support for 7/8 rates.
  */
-static const u32 can327_bitrate_const[64] = {
+static const u32 can327_bitrate_const[] = {
         7812,  7936,  8064,  8196,  8333,  8474,  8620,  8771,
         8928,  9090,  9259,  9433,  9615,  9803, 10000, 10204,
        10416, 10638, 10869, 11111, 11363, 11627, 11904, 12195,
@@ -1101,8 +1100,6 @@ static int can327_ldisc_open(struct tty_struct *tty)
        elm->tty = tty;
        tty->disc_data = elm;
 
-       devm_can_led_init(elm->dev);
-
        /* Let 'er rip */
        err = register_candev(elm->dev);
        if (err) {