From patchwork Tue Feb 18 01:10:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 3666421 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0E31BF13A for ; Tue, 18 Feb 2014 01:10:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D065820142 for ; Tue, 18 Feb 2014 01:10:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03AE8201FE for ; Tue, 18 Feb 2014 01:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753248AbaBRBKk (ORCPT ); Mon, 17 Feb 2014 20:10:40 -0500 Received: from mail-ea0-f170.google.com ([209.85.215.170]:58130 "EHLO mail-ea0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752394AbaBRBKi (ORCPT ); Mon, 17 Feb 2014 20:10:38 -0500 Received: by mail-ea0-f170.google.com with SMTP id g15so5779627eak.1 for ; Mon, 17 Feb 2014 17:10:37 -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=KQtYQd6Rgq+pKx+d4IkRdOnWawHcsaSP4HAgU+rwMr8=; b=T0bYmD2R+Uu+u5EQeiYBUJLh6qs1QVxErhZ45ek5NdG80XreVf10UkDJgzm+fpYLOL RGn0OAqcAxawmOjLl3vivBzCbtPPF1l75PdvwMYLf79KFqnoi2fNI7LfCP+dxAtmFW4S IW05ZCSiKx3yIiK+4HhQgeiuMwYhsawlPSDkpCIN3BPtiUPhncL0OtoiA1W/cCpJnJXd PJS6AB6qnkOuuOp9N3lfrOvYG6HWH2+EXd/FynkL3QqTSOKn70vZUDhJrRMZkpodufP1 8dqMp9PuhG5Ctkq8SxCcCcT+Adf9sGlEU9gBVjOrBg5JPxJInWtohzwe0/8S52Lgfotm /kMA== X-Received: by 10.14.179.129 with SMTP id h1mr30781098eem.26.1392685837554; Mon, 17 Feb 2014 17:10:37 -0800 (PST) Received: from localhost.localdomain ([95.237.125.26]) by mx.google.com with ESMTPSA id j41sm63723093eeg.10.2014.02.17.17.10.35 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:10:36 -0800 (PST) From: Andrea Merello To: linville@tuxdriver.com Cc: linux-wireless@vger.kernel.org, Larry.Finger@lwfinger.net, bernhard@schiffner-limbach.de, dan.carpenter@oracle.com, liuhq11@mails.tsinghua.edu.cn, andrea merello Subject: [PATCH 3/7] rtl818x: check for pci_map_single() success when initializing RX ring Date: Tue, 18 Feb 2014 02:10:42 +0100 Message-Id: <1392685846-10116-4-git-send-email-andrea.merello@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392685846-10116-1-git-send-email-andrea.merello@gmail.com> References: <1392685846-10116-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 During initialization a number of RX skbs are allocated and mapped for DMA. Currently if pci_map_single() fails, it will result in passing to the HW a wrong DMA address (to write to!). This patch detects this condition, eventually it tries to get a more luky skb, and if it finally fails to get things right, it makes the driver not to initialize, avoiding at least dangerous DMAs. Signed-off-by: Andrea Merello --- drivers/net/wireless/rtl818x/rtl8180/dev.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c index bf59ff9..848ea59 100644 --- a/drivers/net/wireless/rtl818x/rtl8180/dev.c +++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c @@ -458,6 +458,7 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) { struct rtl8180_priv *priv = dev->priv; struct rtl8180_rx_desc *entry; + int dma_map_fail_count = 0; int i; priv->rx_ring = pci_alloc_consistent(priv->pdev, @@ -483,6 +484,19 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) mapping = (dma_addr_t *)skb->cb; *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb), MAX_RX_SIZE, PCI_DMA_FROMDEVICE); + + if (pci_dma_mapping_error(priv->pdev, *mapping)) { + kfree_skb(skb); + if (dma_map_fail_count++ > 32) { + wiphy_err(dev->wiphy, "Cannot map DMA for RX skb\n"); + return -ENOMEM; + } + + i--; + continue; + } + + entry->rx_buf = cpu_to_le32(*mapping); entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN | MAX_RX_SIZE);