From patchwork Wed Feb 5 21:38:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 3591551 Return-Path: X-Original-To: patchwork-linux-wireless@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 C304A9F2E9 for ; Wed, 5 Feb 2014 21:37:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6B3220154 for ; Wed, 5 Feb 2014 21:37:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E6E220114 for ; Wed, 5 Feb 2014 21:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754455AbaBEVhu (ORCPT ); Wed, 5 Feb 2014 16:37:50 -0500 Received: from mail-ea0-f176.google.com ([209.85.215.176]:42556 "EHLO mail-ea0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754403AbaBEVhr (ORCPT ); Wed, 5 Feb 2014 16:37:47 -0500 Received: by mail-ea0-f176.google.com with SMTP id h14so515619eaj.7 for ; Wed, 05 Feb 2014 13:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LYcV73FiiA3K/xbQvzB+VgddPiMtqZ6A43n4Eu6KSPk=; b=0CPy/MnG7jIIFODJBZQM0tMOr9JOgCFqsB+PHVoboN9wzZq5uJ7qm7peQM0lhQXa9T l21kehgICyarWYte+YDrDfHaSFpouZoKvrKmoiyNqyOssRUxeCsaTWAVZDxDVKF/DaSR KJrdBVhwcvyFiL7mIisiZEB2QW2yUaf1xp8bXCPdZUGZ/qw8lrOTWWah65c0NN9NnYvC vAD9PAye1sxIAFCJmszKSv3ujRjJ4DzUbKhLkCAbu6AS0fz68udQN2K9QUxLJgXlMKq6 viT7dt8yoEPmWV/pah7ty5sSvy0/gNaKyqBYeEQc37U9SN05plQjiJ0WT0CM/pV3GVtu RjCQ== X-Received: by 10.14.220.193 with SMTP id o41mr4718659eep.22.1391636266882; Wed, 05 Feb 2014 13:37:46 -0800 (PST) Received: from localhost.localdomain (host209-123-dynamic.54-79-r.retail.telecomitalia.it. [79.54.123.209]) by mx.google.com with ESMTPSA id v7sm106105864eel.2.2014.02.05.13.37.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Feb 2014 13:37:46 -0800 (PST) From: andrea merello To: linville@tuxdriver.com Cc: linux-wireless@vger.kernel.org, Larry.Finger@lwfinger.net, "andrea.merello" Subject: [PATCH 2/4] Add error check for pci_map_single return value in rtl8180 RX path Date: Wed, 5 Feb 2014 22:38:05 +0100 Message-Id: <1391636287-17712-3-git-send-email-andrea.merello@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391636287-17712-1-git-send-email-andrea.merello@gmail.com> References: <1391636287-17712-1-git-send-email-andrea.merello@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: "andrea.merello" In original code the old RX DMA buffer is unmapped and processed and at the end of the isr a new buffer is mapped with pci_map_single and attached to the RX descriptor. If pci_map_single fails then the RX descriptor remains with no valid DMA buffer attached. In this condition the DMA will target where it shouldn't with obvious evil consequences. Simply avoiding re-arming the descriptor will prevent buggy DMA but it will result soon in RX stuck. This patch move the DMA mapping of the new buffer at the beginning of the ISR (and it adds error check for pci_map_single success/fail). If the DMA mapping fails then we do not unmap the old buffer and we re-arm the descriptor without processing it, with the old DMA buffer still attached. In this way we lose the currently RX-ed packet, but whenever next calls to pci_map_single will succeed again,then the RX process will go on without stuck. Signed-off-by: andrea.merello Signed-off-by: andrea merello --- drivers/net/wireless/rtl818x/rtl8180/dev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c index 79b9398..1c6ac25 100644 --- a/drivers/net/wireless/rtl818x/rtl8180/dev.c +++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c @@ -107,6 +107,7 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev) struct rtl8180_priv *priv = dev->priv; unsigned int count = 32; u8 signal, agc, sq; + dma_addr_t mapping; while (count--) { struct rtl8180_rx_desc *entry = &priv->rx_ring[priv->rx_idx]; @@ -128,6 +129,17 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev) if (unlikely(!new_skb)) goto done; + mapping = pci_map_single(priv->pdev, + skb_tail_pointer(new_skb), + MAX_RX_SIZE, PCI_DMA_FROMDEVICE); + + if (pci_dma_mapping_error(priv->pdev, mapping)) { + kfree_skb(new_skb); + dev_err(&priv->pdev->dev, "RX DMA map error\n"); + + goto done; + } + pci_unmap_single(priv->pdev, *((dma_addr_t *)skb->cb), MAX_RX_SIZE, PCI_DMA_FROMDEVICE); @@ -158,9 +170,7 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev) skb = new_skb; priv->rx_buf[priv->rx_idx] = skb; - *((dma_addr_t *) skb->cb) = - pci_map_single(priv->pdev, skb_tail_pointer(skb), - MAX_RX_SIZE, PCI_DMA_FROMDEVICE); + *((dma_addr_t *) skb->cb) = mapping; } done: