Flush worker earlier, resolving the last to-do item.
[elmcan.git] / module / elmcan.c
index 7ac1f5466a052a3c6e889e830fc6927313fc8b42..33b0add55e8adb2dc3ed28c6fee21a5654a55bff 100644 (file)
@@ -119,7 +119,7 @@ struct elmcan {
        int                     txleft;         /* Bytes left to TX */
 
        /* TTY RX helpers */
-       unsigned char *rxbuf;
+       unsigned char rxbuf[ELM327_SIZE_RXBUF];
        int rxfill;
 
        /* State machine */
@@ -366,11 +366,11 @@ static inline void elm327_hw_failure(struct elmcan *elm)
 
 
 
- /************************************************************************
-  *            ELM327: Reception parser                        *
-  *                                                            *
-  * (assumes elm->lock taken)                                  *
-  ************************************************************************/
+ /***********************************************************************
+  *            ELM327: Reception parser                                *
+  *                                                                    *
+  * (assumes elm->lock taken)                                          *
+  ***********************************************************************/
 
 static void elm327_parse_error(struct elmcan *elm, int len)
 {
@@ -1140,9 +1140,8 @@ static int elmcan_ldisc_open(struct tty_struct *tty)
                return -ENFILE;
        elm = netdev_priv(dev);
 
-       elm->rxbuf = kmalloc(ELM327_SIZE_RXBUF, GFP_KERNEL);
        elm->txbuf = kmalloc(ELM327_SIZE_TXBUF, GFP_KERNEL);
-       if (!elm->rxbuf || !elm->txbuf) {
+       if (!elm->txbuf) {
                err = -ENOMEM;
                goto out_err;
        }
@@ -1183,8 +1182,6 @@ static int elmcan_ldisc_open(struct tty_struct *tty)
 out_err:
        if (elm->txbuf)
                kfree(elm->txbuf);
-       if (elm->rxbuf)
-               kfree(elm->rxbuf);
        free_candev(elm->dev);
        return err;
 }
@@ -1218,18 +1215,17 @@ static void elmcan_ldisc_close(struct tty_struct *tty)
 
        /* At this point, all ldisc calls to us have become no-ops. */
 
+       flush_work(&elm->tx_work);
+
        /* Mark channel as dead */
        spin_lock_bh(&elm->lock);
        tty->disc_data = NULL;
        elm->tty = NULL;
        spin_unlock_bh(&elm->lock);
 
-       flush_work(&elm->tx_work);
-
        netdev_info(elm->dev, "elmcan off %s.\n", tty->name);
 
        kfree(elm->txbuf);
-       kfree(elm->rxbuf);
        free_candev(elm->dev);
 }