usb: gadget: f_ncm: remove spurious boolean timer_stopping
authorMaciej Żenczykowski <maze@google.com>
Thu, 1 Jul 2021 11:48:30 +0000 (04:48 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Jul 2021 08:04:19 +0000 (10:04 +0200)
It is equivalent to ncm->netdev being NULL.

Cc: Brooke Basile <brookebasile@gmail.com>
Cc: "Bryan O'Donoghue" <bryan.odonoghue@linaro.org>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Link: https://lore.kernel.org/r/20210701114834.884597-2-zenczykowski@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_ncm.c

index afbe70b..e45a938 100644 (file)
@@ -73,7 +73,6 @@ struct f_ncm {
        struct sk_buff                  *skb_tx_ndp;
        u16                             ndp_dgram_count;
        struct hrtimer                  task_timer;
-       bool                            timer_stopping;
 };
 
 static inline struct f_ncm *func_to_ncm(struct usb_function *f)
@@ -889,7 +888,6 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 
                if (ncm->port.in_ep->enabled) {
                        DBG(cdev, "reset ncm\n");
-                       ncm->timer_stopping = true;
                        ncm->netdev = NULL;
                        gether_disconnect(&ncm->port);
                        ncm_reset_values(ncm);
@@ -927,7 +925,6 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
                        if (IS_ERR(net))
                                return PTR_ERR(net);
                        ncm->netdev = net;
-                       ncm->timer_stopping = false;
                }
 
                spin_lock(&ncm->lock);
@@ -1157,16 +1154,19 @@ err:
 static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
 {
        struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
+       struct net_device *netdev = READ_ONCE(ncm->netdev);
 
        /* Only send if data is available. */
-       if (!ncm->timer_stopping && ncm->skb_tx_data) {
+       if (netdev && ncm->skb_tx_data) {
                /* XXX This allowance of a NULL skb argument to ndo_start_xmit
                 * XXX is not sane.  The gadget layer should be redesigned so
                 * XXX that the dev->wrap() invocations to build SKBs is transparent
                 * XXX and performed in some way outside of the ndo_start_xmit
                 * XXX interface.
+                *
+                * This will call directly into u_ether's eth_start_xmit()
                 */
-               ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev);
+               netdev->netdev_ops->ndo_start_xmit(NULL, netdev);
        }
        return HRTIMER_NORESTART;
 }
@@ -1355,7 +1355,6 @@ static void ncm_disable(struct usb_function *f)
        DBG(cdev, "ncm deactivated\n");
 
        if (ncm->port.in_ep->enabled) {
-               ncm->timer_stopping = true;
                ncm->netdev = NULL;
                gether_disconnect(&ncm->port);
        }