This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5374af077bf22dd00fedfb8f621d214202c09960
Author: zhanghongyu <zhanghon...@xiaomi.com>
AuthorDate: Fri Oct 20 15:17:48 2023 +0800

    tun: Fix the error of calling tun_close when tun_txavail or 
tun_txavail_work is executed
    
    When tun_txavail_work is running, switch to tun_close thread and priv->lock 
will be destroyed, then switch back to tun_txavail_work thread, an error will 
occur when nxmutex_unlock(&priv->lock)
    
    Signed-off-by: zhanghongyu <zhanghon...@xiaomi.com>
---
 drivers/net/tun.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

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;
+
+  flags = enter_critical_section(); /* No interrupts */
 
-  /* Schedule to perform the TX poll on the worker thread. */
+  /* Schedule to perform the TX poll on the worker thread when priv->bifup
+   * is true.
+   */
 
-  if (work_available(&priv->work))
+  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);

Reply via email to