Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753418AbdLSPW6 (ORCPT ); Tue, 19 Dec 2017 10:22:58 -0500 Received: from shards.monkeyblade.net ([184.105.139.130]:51652 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753130AbdLSPW4 (ORCPT ); Tue, 19 Dec 2017 10:22:56 -0500 Date: Tue, 19 Dec 2017 10:22:54 -0500 (EST) Message-Id: <20171219.102254.1959679351283055093.davem@davemloft.net> To: al.kochet@gmail.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, f.fainelli@gmail.com, edumazet@google.com Subject: Re: [PATCH] net: arc_emac: fix arc_emac_rx() error paths From: David Miller In-Reply-To: <1513358406-32503-1-git-send-email-al.kochet@gmail.com> References: <1513358406-32503-1-git-send-email-al.kochet@gmail.com> X-Mailer: Mew version 6.7 on Emacs 25.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 19 Dec 2017 07:22:56 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1515 Lines: 44 From: Alexander Kochetkov Date: Fri, 15 Dec 2017 20:20:06 +0300 > 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 This patch adds quite a few bugs, here is one which shows this is not functionally tested: > - /* 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); Map the new SKB. > 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); And then you unmap it. "addr" is the new DMA mapping, not the old one.