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 0000f87f3720f71573c2d105a3411b1fef9537a6
Author: wangjinjing1 <[email protected]>
AuthorDate: Thu Jun 11 14:37:12 2026 +0800

    mm/iob: preserve queue flags when extending chain in iob_copyin.
    
    When iob_copyin_internal() extends a buffer chain by allocating a new
    tail IOB, it overwrote io_flink directly, which dropped the queue flag
    bits (e.g. IOB_CHAIN_END) embedded in the low bits of io_flink. Losing
    the chain-end marker corrupts queue traversal for IOBs already enqueued.
    
    - Carry over the current tail's flags to the newly allocated tail via
      IOB_FLAG_SET() before relinking
    - Clear the old tail's flags implicitly by relinking it to the plain
      pointer, since it is no longer the last buffer in the chain
    
    Signed-off-by: wangjinjing1 <[email protected]>
---
 mm/iob/iob_copyin.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/iob/iob_copyin.c b/mm/iob/iob_copyin.c
index b74528b320e..0b5e79e0fc9 100644
--- a/mm/iob/iob_copyin.c
+++ b/mm/iob/iob_copyin.c
@@ -200,8 +200,14 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR 
const uint8_t *src,
               return -ENOMEM;
             }
 
-          /* Add the new, empty I/O buffer to the end of the buffer chain. */
+          /* Add the new, empty I/O buffer to the end of the buffer chain.
+           * Carry over any queue flags (e.g. IOB_CHAIN_END) from the
+           * current tail to the new tail so that the chain boundary is
+           * preserved, then clear the flags on the old tail since it is
+           * no longer the last buffer in the chain.
+           */
 
+          IOB_FLAG_SET(next, NULL, IOB_FLAG_GET(iob));
           iob->io_flink = next;
           iobinfo("iob=%p added to the chain\n", iob);
         }

Reply via email to