From: Piotr Ziecik Date: Tue, 14 Jul 2009 10:08:35 +0200 Subject: [U-Boot] [PATCH] eth_receive(): Do not assume that caller always wants full packet. Message-ID: <1247558915-26591-1-git-send-email-kosmo@semihalf.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de When packets arrive on the interface that are larger than the buffer being passed to U-Boot from a standalone application, then the eth_receive() returns -1 and leaves the packet saved. The next call to eth_receive() will find that same packet and can fail for the exact same reason. A typical scenario is the loader doing ARP with a buffer of 66 bytes. The end result is that the ARP will fail and the loader panics. This patch fixes above problem by allowing partial packet read. Signed-off-by: Marcel Moolenaar Signed-off-by: Piotr Ziecik --- net/eth.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/net/eth.c b/net/eth.c index 3d93966..f0124f8 100644 --- a/net/eth.c +++ b/net/eth.c @@ -416,10 +416,7 @@ int eth_receive(volatile void *packet, int length) return -1; } - if (length < eth_rcv_bufs[eth_rcv_current].length) - return -1; - - length = eth_rcv_bufs[eth_rcv_current].length; + length = min(length, eth_rcv_bufs[eth_rcv_current].length); for (i = 0; i < length; i++) p[i] = eth_rcv_bufs[eth_rcv_current].data[i]; -- 1.5.2.2