From patchwork Mon Aug 25 14:22:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 4775251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB9549F38D for ; Mon, 25 Aug 2014 14:25:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D44420109 for ; Mon, 25 Aug 2014 14:25:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B80E12012B for ; Mon, 25 Aug 2014 14:25:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XLvAv-0002JT-HQ; Mon, 25 Aug 2014 14:23:13 +0000 Received: from mail-la0-x22a.google.com ([2a00:1450:4010:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XLvAt-00027B-0w for linux-arm-kernel@lists.infradead.org; Mon, 25 Aug 2014 14:23:11 +0000 Received: by mail-la0-f42.google.com with SMTP id pv20so13132622lab.1 for ; Mon, 25 Aug 2014 07:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=hBZkPmbtkJhcUCSgJUzW1wZXqwBK8WPLQz9Nn6cM2FI=; b=VsATf42dKvLRXLt0ZtDbOr/th2wZXbsvSYOOOe6GB0fKUkGjK86WMzBF/u/OB+vm33 eLyPRd5a0gSS7fpsTaNlEqY1ybAAm2BviPLw68u1tsIxu98jlZI/oMvPbmeBZr8lS0GX n7QlEnB9rLVC19oS+Bl2nMM5Pm9G9mWMNu9ItobvvXjc0jrP12AA/dc68J6SJAul5FWW +4pV4AJcYZqWjySbAkNDSxgpVVruJzNzuLR95zu5Fg9YPRXy6E9a7Nw4R+rXaibYOIz4 y4aJ1wGdaFsKsKvtl64i8qzIb1WbLBsS0CGgX5YI42MQ32M1D2pK0ndw/HqAoeGBPSs8 EkdA== X-Received: by 10.152.120.38 with SMTP id kz6mr21958008lab.8.1408976565159; Mon, 25 Aug 2014 07:22:45 -0700 (PDT) Received: from Ildjarn.ath.cx (static-213-115-41-10.sme.bredbandsbolaget.se. [213.115.41.10]) by mx.google.com with ESMTPSA id iq1sm12749lac.9.2014.08.25.07.22.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Aug 2014 07:22:44 -0700 (PDT) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v6 4/4] net: moxa: continue loop on skb allocation failure Date: Mon, 25 Aug 2014 16:22:40 +0200 Message-Id: <1408976560-15694-1-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140825_072311_250328_9F820913 X-CRM114-Status: GOOD ( 11.53 ) X-Spam-Score: -0.8 (/) Cc: f.fainelli@gmail.com, eric.dumazet@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , mirqus@gmail.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If netdev_alloc_skb_ip_align() fails, subsequent code will try to dereference an invalid pointer. Continue to next descriptor on error. While we're at it, 1. eliminate the chance of an endless loop, replace the main loop with while(rx < budget) 2. use napi_complete() and remove the explicit napi_gro_flush() Signed-off-by: Jonas Jensen --- Notes: Applies to next-20140825 drivers/net/ethernet/moxa/moxart_ether.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index 983d019..2f12c88 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -206,7 +206,7 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget) int rx_head = priv->rx_head; int rx = 0; - while (1) { + while (rx < budget) { desc = priv->rx_desc_base + (RX_REG_DESC_SIZE * rx_head); desc0 = readl(desc + RX_REG_OFFSET_DESC0); @@ -218,7 +218,7 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget) net_dbg_ratelimited("packet error\n"); priv->stats.rx_dropped++; priv->stats.rx_errors++; - continue; + goto rx_next; } len = desc0 & RX_DESC0_FRAME_LEN_MASK; @@ -235,6 +235,7 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget) net_dbg_ratelimited("netdev_alloc_skb_ip_align failed\n"); priv->stats.rx_dropped++; priv->stats.rx_errors++; + goto rx_next; } memcpy(skb->data, priv->rx_buf[rx_head], len); @@ -249,18 +250,15 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget) if (desc0 & RX_DESC0_MULTICAST) priv->stats.multicast++; +rx_next: writel(RX_DESC0_DMA_OWN, desc + RX_REG_OFFSET_DESC0); rx_head = RX_NEXT(rx_head); priv->rx_head = rx_head; - - if (rx >= budget) - break; } if (rx < budget) { - napi_gro_flush(napi, false); - __napi_complete(napi); + napi_complete(napi); } priv->reg_imr |= RPKT_FINISH_M;