Skip to content

Atmel SAM driver: let gmac_dev_read() return the proper length #950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/portable/NetworkInterface/DriverSAM/gmac_SAM.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,
return GMAC_RX_NO_DATA;
}

/* Return the number of bytes received. */
*p_rcv_size = bytesLeft;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to compare with frame size?
The *p_rcv_size might be different when ul_frame_size is smaller than bytesLeft + 2.

if( bytesLeft + 2 <= ul_frame_size )
{
    *p_rcv_size = bytesLeft;
}
else
{
    *p_rcv_size = ul_frame_size;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*p_rcv_size = bytesLeft;
*p_rcv_size = min( bytesLeft + 2, ( int32_t ) ul_frame_size );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ActoryOu and @htibosch this should be the fix. Am I correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AniruddhaKanhere,
It can't be bytesLeft + 2 because the stack compares packet length with buffer length.
It's only allowed when buffer length is exactly equal to packet length, which is bytesLeft.
Take #941 as reference.


/* gmac_dev_poll has confirmed that there is a complete frame at
* the current position 'ul_rx_idx'
*/
Expand Down Expand Up @@ -693,8 +696,6 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev,

p_gmac_dev->ul_rx_idx = nextIdx;

*p_rcv_size = bytesLeft;

return GMAC_OK;
}

Expand Down