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

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

commit 58b2989c64d6d4839909de711694771554d22ba5
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Sat Oct 3 22:16:55 2026 -0300

    arch/mips/pic32mz: re-initialize the Ethernet free buffer list on ifup.
    
    pic32mz_bufferinit() appended every buffer to pd_freebuffers without
    emptying the list first.  On the first ifup the list is empty (the
    driver structure was cleared), but on later ones it still holds the
    buffers that were free at ifdown.  Appending them again truncates the
    list and loses buffers, depending on which ones were free.  With too few
    buffers left the driver could no longer transmit or replace RX buffers,
    so after ifdown/ifup the interface stayed up without answering (not
    even ARP) until the next ifdown/ifup.
    
    Reproduced with ifdown/ifup from NSH while pinging the board every
    10 ms: 3 of 10 cycles left the interface dead before the fix, none
    after it.  This also happens on cable reconnection with
    CONFIG_NETINIT_MONITOR, which takes the interface down and up.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Daniel P. Carvalho <[email protected]>
---
 arch/mips/src/pic32mz/pic32mz_ethernet.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/mips/src/pic32mz/pic32mz_ethernet.c 
b/arch/mips/src/pic32mz/pic32mz_ethernet.c
index 27ee10ed6e7..24f2c509184 100644
--- a/arch/mips/src/pic32mz/pic32mz_ethernet.c
+++ b/arch/mips/src/pic32mz/pic32mz_ethernet.c
@@ -712,7 +712,9 @@ static void pic32mz_dumprxdesc(struct pic32mz_rxdesc_s 
*rxdesc,
  * Function: pic32mz_bufferinit
  *
  * Description:
- *   Initialize the buffers by placing them all in a free list
+ *   Initialize the buffers by placing them all in an empty free list.  The
+ *   list is re-initialized on every ifup, when it may still hold the
+ *   buffers that were free when the interface was taken down.
  *
  * Input Parameters:
  *   priv - Pointer to EMAC device driver structure
@@ -727,6 +729,8 @@ static inline void pic32mz_bufferinit(struct 
pic32mz_driver_s *priv)
   uint8_t *buffer;
   int i;
 
+  sq_init(&priv->pd_freebuffers);
+
   for (i = 0, buffer = g_buffers; i < PIC32MZ_NBUFFERS; i++)
     {
       /* Add the buffer to the end of the list of free buffers */

Reply via email to