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 f4142626b9b4a161fc67791a9c09965da6fc6ab2
Author: Jukka Laitinen <juk...@ssrc.tii.ae>
AuthorDate: Tue Mar 12 10:42:51 2024 +0200

    net/can/can_recvmsg.c: Cleanup can_readahead
    
    It is better to remove the iob from the readahead queue first,
    and only after that work on the iob.
    
    Signed-off-by: Jukka Laitinen <juk...@ssrc.tii.ae>
---
 net/can/can_recvmsg.c | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/net/can/can_recvmsg.c b/net/can/can_recvmsg.c
index f11789ddc7..9ec9dddbee 100644
--- a/net/can/can_recvmsg.c
+++ b/net/can/can_recvmsg.c
@@ -243,8 +243,8 @@ static inline int can_readahead(struct can_recvfrom_s 
*pstate)
 
   pstate->pr_recvlen = -1;
 
-  if ((iob = iob_peek_queue(&conn->readahead)) != NULL &&
-      pstate->pr_buflen > 0)
+  if (pstate->pr_buflen > 0 &&
+      (iob = iob_remove_queue(&conn->readahead)) != NULL)
     {
       DEBUGASSERT(iob->io_pktlen > 0);
 
@@ -256,17 +256,7 @@ static inline int can_readahead(struct can_recvfrom_s 
*pstate)
 
       if (can_recv_filter(conn, can_id) == 0)
         {
-          FAR struct iob_s *tmp;
-
-          /* Remove the I/O buffer chain from the head of the read-ahead
-           * buffer queue.
-           */
-
-          tmp = iob_remove_queue(&conn->readahead);
-          DEBUGASSERT(tmp == iob);
-          UNUSED(tmp);
-
-          /* And free the I/O buffer chain */
+          /* Free the I/O buffer chain */
 
           iob_free_chain(iob);
           return 0;
@@ -295,17 +285,7 @@ static inline int can_readahead(struct can_recvfrom_s 
*pstate)
 
       static_assert(sizeof(struct can_frame) <= CONFIG_IOB_BUFSIZE);
 
-      FAR struct iob_s *tmp;
-
-      /* Remove the I/O buffer chain from the head of the read-ahead
-       * buffer queue.
-       */
-
-      tmp = iob_remove_queue(&conn->readahead);
-      DEBUGASSERT(tmp == iob);
-      UNUSED(tmp);
-
-      /* And free the I/O buffer chain */
+      /* Free the I/O buffer chain */
 
       iob_free_chain(iob);
 

Reply via email to