diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 3f00b0b365..bd7e01567a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -775,14 +775,21 @@ static void tun_txavail_work(FAR void *arg) static int tun_txavail(FAR struct net_driver_s *dev) { FAR struct tun_device_s *priv = (FAR struct tun_device_s *)dev->d_private; + irqstate_t flags; - /* Schedule to perform the TX poll on the worker thread. */ + flags = enter_critical_section(); /* No interrupts */ - if (work_available(&priv->work)) + /* Schedule to perform the TX poll on the worker thread when priv->bifup + * is true. + */ + + if (priv->bifup && work_available(&priv->work)) { work_queue(TUNWORK, &priv->work, tun_txavail_work, priv, 0); } + leave_critical_section(flags); + return OK; } @@ -911,6 +918,8 @@ static void tun_dev_uninit(FAR struct tun_device_s *priv) tun_ifdown(&priv->dev); + work_cancel_sync(TUNWORK, &priv->work); + /* Remove the device from the OS */ netdev_unregister(&priv->dev);