Received: by 10.223.185.116 with SMTP id b49csp8593809wrg; Fri, 2 Mar 2018 04:43:33 -0800 (PST) X-Google-Smtp-Source: AG47ELtku+irDqunNMsZMiBOnKGIBdfmrk+9kj7ihKgHPiQ54iRrtFmQJcI4mATHJqvfDT0RSiXS X-Received: by 10.99.111.196 with SMTP id k187mr4383540pgc.360.1519994613464; Fri, 02 Mar 2018 04:43:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519994613; cv=none; d=google.com; s=arc-20160816; b=M210tV3hFHNuNa2YPAuCwv+dU42BL/jmwUiFR2/iJXMNsxZfdhl7fVlNkcLrfqzwhd UH5RbsMFrUczmHGurZww5+112r+rNBo3shJ2pof/b+FN7v3e7FCYePCKA0xPpousQRVu B+Y73dcoqNnquM4BYTBk73c1waa22o/UMQ3OY8xP2X1xjMRihqyhr0paAWmar1qfFNRd p0f7OyiMQ4t6vOmOObEPpleusESH4P6NmyZN2kOkkIzpkPlTepaPSiDSr9TmEmG85QX6 eBEQVpO9tb5VureJzBHyVxKTP/pQKpz0/MhNtW5LFJWHRFxzlElDkYmBbfNVqabY9IM8 SL6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NYoZi0guakBBEKxsjYa6jHLwpYp1GKeq5yWwEabMcP0=; b=T7S55h+EZlh0f5SGtp9Q85bo3pUSYBziLOZ1qXgORGzcsxyoGYPER4WHuFXUOFX5Kb 8J1TdxAK+j9+F5hv5uBsVLwUAGjt2ucXi73wvPT5zX6FgEaz3msvFtZ6tR4mnzl5ZJY7 5E+TMUv+AQ9Zu8BHjMbSNvEaExxHDevJo/3Kgb18/HHIsk276ZxTIBD3vINol7BvrIt3 eXZRIYJVJ78LCE8LLB3fUcfduN2ToO4SL6jNs0/JWylhUbJdGrNfbbqxhVaElGrDkSXd 3J/TRfTNyb8gFsXcKSSJErNsBeX0ZI9H659xGsMtLx4oR1OnTBImOf0jx2VNI1toPXR+ S/2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j186si3927473pge.747.2018.03.02.04.43.18; Fri, 02 Mar 2018 04:43:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423711AbeCBIzk (ORCPT + 99 others); Fri, 2 Mar 2018 03:55:40 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50822 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423699AbeCBIzh (ORCPT ); Fri, 2 Mar 2018 03:55:37 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 655311242; Fri, 2 Mar 2018 08:55:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Kochetkov , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 09/34] net: arc_emac: fix arc_emac_rx() error paths Date: Fri, 2 Mar 2018 09:51:05 +0100 Message-Id: <20180302084436.580586591@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180302084435.842679610@linuxfoundation.org> References: <20180302084435.842679610@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Kochetkov [ Upstream commit e688822d035b494071ecbadcccbd6f3325fb0f59 ] arc_emac_rx() has some issues found by code review. In case netdev_alloc_skb_ip_align() or dma_map_single() failure rx fifo entry will not be returned to EMAC. In case dma_map_single() failure previously allocated skb became lost to driver. At the same time address of newly allocated skb will not be provided to EMAC. Signed-off-by: Alexander Kochetkov Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/arc/emac_main.c | 53 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -250,39 +250,48 @@ static int arc_emac_rx(struct net_device continue; } - pktlen = info & LEN_MASK; - stats->rx_packets++; - stats->rx_bytes += pktlen; - skb = rx_buff->skb; - skb_put(skb, pktlen); - skb->dev = ndev; - skb->protocol = eth_type_trans(skb, ndev); - - dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), - dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); - - /* Prepare the BD for next cycle */ - rx_buff->skb = netdev_alloc_skb_ip_align(ndev, - EMAC_BUFFER_SIZE); - if (unlikely(!rx_buff->skb)) { + /* Prepare the BD for next cycle. netif_receive_skb() + * only if new skb was allocated and mapped to avoid holes + * in the RX fifo. + */ + skb = netdev_alloc_skb_ip_align(ndev, EMAC_BUFFER_SIZE); + if (unlikely(!skb)) { + if (net_ratelimit()) + netdev_err(ndev, "cannot allocate skb\n"); + /* Return ownership to EMAC */ + rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE); stats->rx_errors++; - /* Because receive_skb is below, increment rx_dropped */ stats->rx_dropped++; continue; } - /* receive_skb only if new skb was allocated to avoid holes */ - netif_receive_skb(skb); - - addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data, + addr = dma_map_single(&ndev->dev, (void *)skb->data, EMAC_BUFFER_SIZE, DMA_FROM_DEVICE); if (dma_mapping_error(&ndev->dev, addr)) { if (net_ratelimit()) - netdev_err(ndev, "cannot dma map\n"); - dev_kfree_skb(rx_buff->skb); + netdev_err(ndev, "cannot map dma buffer\n"); + dev_kfree_skb(skb); + /* Return ownership to EMAC */ + rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE); stats->rx_errors++; + stats->rx_dropped++; continue; } + + /* unmap previosly mapped skb */ + dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr), + dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE); + + pktlen = info & LEN_MASK; + stats->rx_packets++; + stats->rx_bytes += pktlen; + skb_put(rx_buff->skb, pktlen); + rx_buff->skb->dev = ndev; + rx_buff->skb->protocol = eth_type_trans(rx_buff->skb, ndev); + + netif_receive_skb(rx_buff->skb); + + rx_buff->skb = skb; dma_unmap_addr_set(rx_buff, addr, addr); dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);