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

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

commit a686004f0a3a1657f1b410273e93cd20ec7358a8
Author: gaohedong <[email protected]>
AuthorDate: Thu Apr 30 14:31:41 2026 +0800

    net/upperhalf: only re-queue tx packet on EBUSY, drop on other errors.
    
    Align transmit failure handling with Linux behavior.  Previously all
    transmit errors triggered a re-queue to txq head, which could cause
    infinite retry on permanent failures (e.g. hardware fault).
    
    Now only -EBUSY (transient, device busy) triggers re-queue for retry.
    All other errors are treated as permanent: bump TXERRORS counter and
    drop the packet via netpkt_put().
    
    Signed-off-by: gaohedong <[email protected]>
---
 drivers/net/netdev_upperhalf.c | 55 ++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index 50b60ef5a52..372e6b596db 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -326,36 +326,43 @@ static int netdev_upper_txpoll(FAR struct net_driver_s 
*dev)
   if (netpkt_getdatalen(lower, pkt) > NETDEV_PKTSIZE(dev))
     {
       nerr("ERROR: Packet too long to send!, dropping\n");
+      goto drop;
+    }
 
-      /* Permanent error -- drop the packet to avoid infinite retry.
-       * netpkt_put() restores quota and places pkt back into
-       * dev->d_iob so the caller can release it.
-       */
+  ret = lower->ops->transmit(lower, pkt);
 
-      NETDEV_TXERRORS(dev);
-      netpkt_put(dev, pkt, NETPKT_TX);
+  if (ret == OK)
+    {
+      return NETDEV_TX_CONTINUE;
     }
-  else
+
+  if (ret == -EBUSY)
     {
-      ret = lower->ops->transmit(lower, pkt);
-      if (ret != OK)
-        {
-          /* Transient error -- re-queue to txq head for retry.
-           * Head-insert preserves packet ordering.  The retry will be
-           * driven by txdone callback from the lower half driver.
-           *
-           * Note: We manually restore quota instead of using netpkt_put()
-           * because the pkt is moved to txq, not back to dev->d_iob.
-           * After netpkt_get(), dev->d_iob is already NULL.
-           */
-
-          nwarn("WARNING: Transmit failed: %d, re-queue pkt\n", ret);
-          iob_add_queue_head(pkt, &upper->txq);
-          atomic_add(&upper->lower->quota_ptr[NETPKT_TX], 1);
-          return ret;
-        }
+      /* Transient error -- re-queue to txq head for retry.  Head-insert
+       * preserves packet ordering.  The retry will be driven by the
+       * txdone callback from the lower half driver.
+       *
+       * Note: We manually restore quota instead of using netpkt_put()
+       * because the pkt is moved to txq, not back to dev->d_iob.
+       * After netpkt_get(), dev->d_iob is already NULL.
+       */
+
+      nwarn("WARNING: Transmit busy (%d), re-queue pkt\n", ret);
+      iob_add_queue_head(pkt, &upper->txq);
+      atomic_add(&upper->lower->quota_ptr[NETPKT_TX], 1);
+      return ret;
     }
 
+  nerr("ERROR: Transmit failed: %d, dropping pkt\n", ret);
+
+  /* Permanent error -- drop the packet to avoid infinite retry.
+   * netpkt_put() restores quota and places pkt back into dev->d_iob so
+   * the caller can release it.
+   */
+
+drop:
+  NETDEV_TXERRORS(dev);
+  netpkt_put(dev, pkt, NETPKT_TX);
   return NETDEV_TX_CONTINUE;
 }
 

Reply via email to