From patchwork Fri Mar 18 02:27:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Calaby X-Patchwork-Id: 8615861 X-Patchwork-Delegate: kvalo@adurom.com 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2B7A79F3D1 for ; Fri, 18 Mar 2016 02:27:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 51A2920306 for ; Fri, 18 Mar 2016 02:27:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EF4E202FE for ; Fri, 18 Mar 2016 02:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752643AbcCRC1S (ORCPT ); Thu, 17 Mar 2016 22:27:18 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:36261 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751361AbcCRC1R (ORCPT ); Thu, 17 Mar 2016 22:27:17 -0400 Received: by mail-pf0-f175.google.com with SMTP id u190so146235747pfb.3 for ; Thu, 17 Mar 2016 19:27:16 -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:in-reply-to:references; bh=QfWNPczfM3yLML8N4VHxAocLDsmX8qYDf/NoojVdkDg=; b=Q3J4Po9Gu3UFOWl3dOR9M+Xmg3sthfukMKTDH+VUSYbKPo/uo3LAC6n7Yg+K3kaG69 5bYEUzVnPlilTQY3M44F0IC6lsGiRHKmA3iSbkqVaFYfwYy/sSxzkyJUGtqQLAPmq/h1 hapvCYpCTAeNXtv9gWH/lKWCglMCEkbdUU2Pcu0r7EPZtuvsWOEkdgEhAI/gqyKlWB2w n9II9Q3T8uoTNQQJyZcukK2mciBWMrWPfPUdaqLCkKjYoETzfNJxEQJ3c9VWhLOYjAr5 m6zZUWT5CfcgZInm8+NtcRzBTisUmnh0Qd+Ja7DrGd1ZzcfDE3bM53xVm3ozcQDcey7M 53mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QfWNPczfM3yLML8N4VHxAocLDsmX8qYDf/NoojVdkDg=; b=LLebC8O0tvgQJHnbvfRLnp4RDWdlyLUWoHkhI6K+xr784dk6oBUYiIHbUypG7pfI4Y sum8B6VXfqu5ehxWVg48ILS6FwEOiMUJV+pRNRFpjcUf9WR2ef7Z3YqfGZgv3gdhkDdG Tgg2rbg1JexCOMCKebiHu7Q0Pf1oWqVdo1I9HO3WWA5YU6bYsZQ/2keoT/Z+KOevNdRQ yjOnPaPjBFrsGVwBITju4aYJns5dM39CwMdeDxMGX61a9X4gvKEG/eHJ98YBDE5aWKGs fkJFXbo7MFiHEKtk8CJKgmemseUrdc2F8ZuTAzNXv15phnDz2//JfwEWPZJ0OCA/j/vg clFA== X-Gm-Message-State: AD7BkJLnX+QgKTgsqYiH6/GlayUbni8WJxpSaLWD3VkSNen02dwcw4bIThze6XZH3yofwg== X-Received: by 10.98.10.156 with SMTP id 28mr19943720pfk.130.1458268036412; Thu, 17 Mar 2016 19:27:16 -0700 (PDT) Received: from multimedia.lan (C-59-101-14-180.hay.connect.net.au. [59.101.14.180]) by smtp.gmail.com with ESMTPSA id c9sm16363067pfd.90.2016.03.17.19.27.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 19:27:15 -0700 (PDT) From: Julian Calaby To: Kalle Valo Cc: Jia-Ju Bai , Johannes Berg , Larry Finger , Andrea Merello , linux-wireless@vger.kernel.org Subject: [PATCH MOREWORK 14/19] rtl818x_pci: Fix a memory leak in rtl8180_init_rx_ring Date: Fri, 18 Mar 2016 13:27:09 +1100 Message-Id: <4920ab8faf66e456a1fad1e79607d15a04cbb029.1458262312.git.julian.calaby@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 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: Jia-Ju Bai When dev_alloc_skb or pci_dma_mapping_error in rtl8180_init_rx_ring fails, the memory allocated by pci_zalloc_consistent is not freed. This patch fixes the bug by adding pci_free_consistent in error handling code. Signed-off-by: Jia-Ju Bai Signed-off-by: Julian Calaby --- Could someone else please review this? In particular, immediately after the call to pci_zalloc_coherent(), it fails if the result is null or if '(unsigned long)result & 0xFF'. Is the second arm of the or statement possible, and if so, should we be pci_free_coherent()ing the result there too? I've had a quick scout around and this check seems to be particular to realtek drivers. Thanks, Julian Calaby --- drivers/net/wireless/realtek/rtl818x/rtl8180/dev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/realtek/rtl818x/rtl8180/dev.c b/drivers/net/wireless/realtek/rtl818x/rtl8180/dev.c index c76af5d..a8a23d5 100644 --- a/drivers/net/wireless/realtek/rtl818x/rtl8180/dev.c +++ b/drivers/net/wireless/realtek/rtl818x/rtl8180/dev.c @@ -1018,6 +1018,8 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) dma_addr_t *mapping; entry = priv->rx_ring + priv->rx_ring_sz*i; if (!skb) { + pci_free_consistent(priv->pdev, priv->rx_ring_sz * 32, + priv->rx_ring, priv->rx_ring_dma); wiphy_err(dev->wiphy, "Cannot allocate RX skb\n"); return -ENOMEM; } @@ -1028,6 +1030,8 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) if (pci_dma_mapping_error(priv->pdev, *mapping)) { kfree_skb(skb); + pci_free_consistent(priv->pdev, priv->rx_ring_sz * 32, + priv->rx_ring, priv->rx_ring_dma); wiphy_err(dev->wiphy, "Cannot map DMA for RX skb\n"); return -ENOMEM; }