Skip to content

Commit

Permalink
net/can/can_recvmsg.c: Cleanup can_readahead
Browse files Browse the repository at this point in the history
It is better to just atomically remove the iob from the readahead queue first, and only after that work on the iob.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Mar 13, 2024
1 parent ceaef74 commit 51162be
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions net/can/can_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)

pstate->pr_recvlen = -1;

if ((iob = iob_peek_queue(&conn->readahead)) != NULL &&
if ((iob = iob_remove_queue(&conn->readahead)) != NULL &&
pstate->pr_buflen > 0)
{
DEBUGASSERT(iob->io_pktlen > 0);
Expand All @@ -246,17 +246,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;
Expand Down Expand Up @@ -284,17 +274,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);

Expand Down

0 comments on commit 51162be

Please sign in to comment.