From patchwork Fri Jun 22 21:24:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 166677 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 0633FB6FA4 for ; Sat, 23 Jun 2012 07:24:44 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F5732808F; Fri, 22 Jun 2012 23:24:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cLksFPHKz6Hj; Fri, 22 Jun 2012 23:24:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0E05228088; Fri, 22 Jun 2012 23:24:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DFA2928088 for ; Fri, 22 Jun 2012 23:24:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YWBDzA7XSGrd for ; Fri, 22 Jun 2012 23:24:33 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.serverraum.org (mail.serverraum.org [78.47.150.89]) by theia.denx.de (Postfix) with ESMTP id 1F7F728087 for ; Fri, 22 Jun 2012 23:24:31 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.serverraum.org (Postfix) with ESMTP id ED2123F001; Fri, 22 Jun 2012 23:24:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.serverraum.org Received: from mail.serverraum.org ([127.0.0.1]) by localhost (web.serverraum.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7pyHNtRqP36d; Fri, 22 Jun 2012 23:24:30 +0200 (CEST) Received: from thanatos.fritz.box (95-89-251-205-dynip.superkabel.de [95.89.251.205]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.serverraum.org (Postfix) with ESMTPSA id 1F8B93EFFB; Fri, 22 Jun 2012 23:24:29 +0200 (CEST) From: Michael Walle To: u-boot@lists.denx.de Date: Fri, 22 Jun 2012 23:24:28 +0200 Message-Id: <1340400268-7403-1-git-send-email-michael@walle.cc> X-Mailer: git-send-email 1.7.2.5 Cc: Piotr Kruszynski Subject: [U-Boot] [PATCH] api: net: fix length check in eth_receive() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Cc: Joe Hershberger Cc: Rafal Jaworowski Cc: Piotr Kruszynski --- net/eth.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/net/eth.c b/net/eth.c index d526264..09249c9 100644 --- a/net/eth.c +++ b/net/eth.c @@ -486,10 +486,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];