]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
api: net: fix length check in eth_receive()
authorMichael Walle <michael@walle.cc>
Fri, 22 Jun 2012 11:24:28 +0000 (11:24 +0000)
committerJoe Hershberger <joe.hershberger@ni.com>
Mon, 24 Sep 2012 18:17:24 +0000 (13:17 -0500)
If the requested length is too small to hold the received packet,
eth_receive() will return -1 and will leave the packet in the receive
buffers. Instead of returning an error in this case, we return the first
portion of the received packet and remove it from the receive buffers.

This fixes FreeBSD's ubldr. Without this patch it will just stop receiving
packets if the NIC receives more than PKTBUFSRX too large packets.

Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Joe Hershberger <joe.hershberger@gmail.com>
Cc: Rafal Jaworowski <raj@semihalf.com>
Cc: Piotr Kruszynski <ppk@semihalf.com>
net/eth.c

index 1a11ce10277e591eee26acc493475514eba5b72b..bb4d95be8ec4800b17fdb454eda55b8ce6d9f21e 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -500,10 +500,7 @@ int eth_receive(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(eth_rcv_bufs[eth_rcv_current].length, length);
 
        for (i = 0; i < length; i++)
                p[i] = eth_rcv_bufs[eth_rcv_current].data[i];