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 <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2024-03-12 10:42:51 +02:00 committed by Xiang Xiao
parent 144ac23647
commit f4142626b9

View file

@ -243,8 +243,8 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)
pstate->pr_recvlen = -1; pstate->pr_recvlen = -1;
if ((iob = iob_peek_queue(&conn->readahead)) != NULL && if (pstate->pr_buflen > 0 &&
pstate->pr_buflen > 0) (iob = iob_remove_queue(&conn->readahead)) != NULL)
{ {
DEBUGASSERT(iob->io_pktlen > 0); 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) if (can_recv_filter(conn, can_id) == 0)
{ {
FAR struct iob_s *tmp; /* Free the I/O buffer chain */
/* 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 */
iob_free_chain(iob); iob_free_chain(iob);
return 0; 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); static_assert(sizeof(struct can_frame) <= CONFIG_IOB_BUFSIZE);
FAR struct iob_s *tmp; /* Free the I/O buffer chain */
/* 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 */
iob_free_chain(iob); iob_free_chain(iob);