From patchwork Wed Jan 13 14:44:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 8026131 X-Patchwork-Delegate: kvalo@adurom.com 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE68CBEEE5 for ; Wed, 13 Jan 2016 14:45:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02C2920515 for ; Wed, 13 Jan 2016 14:45:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF39A20513 for ; Wed, 13 Jan 2016 14:45:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932540AbcAMOpM (ORCPT ); Wed, 13 Jan 2016 09:45:12 -0500 Received: from m12-12.163.com ([220.181.12.12]:55996 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754303AbcAMOpK (ORCPT ); Wed, 13 Jan 2016 09:45:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=8/5CZSumKGWs0Ei4G3 VphnXOAbVGc9u7B6i+QS+BQyA=; b=dLJDvbzQ+0AcvJ2ZNkqVxmpEbcCM0P3gFb Pi6zOBbNiZ7sikXQg514F+G07AqOPh/nbcR0Ef9zOF5Ws79p+3xljuQ4GpHzGr0x /YqI5M6OJyPOiquIhE0N7j0NcJv7+ATBAhi5UjCbw6FraAADEts28bWJgpuzW5s8 J/AcFQb8w= Received: from bai-oslab.tsinghua.edu.cn (unknown [166.111.70.58]) by smtp8 (Coremail) with SMTP id DMCowACnv4ezYpZWVxRaAA--.22198S2; Wed, 13 Jan 2016 22:44:06 +0800 (CST) From: Jia-Ju Bai To: andrea.merello@gmail.com, Larry.Finger@lwfinger.net, flamingice@sourmilk.net, kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] rtl818x_pci: Fix a memory leak in rtl8180_init_rx_ring Date: Wed, 13 Jan 2016 22:44:32 +0800 Message-Id: <1452696272-31229-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DMCowACnv4ezYpZWVxRaAA--.22198S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar47Gw4rGF18Gr1rZFW5Wrg_yoW8GF1rpr WYk3WFkr10yr1jqaykJay3Xr1rZw1rGF97WFW0yw15CFW3JFySqFyF934j9rn8WrWUWay5 XwsFvr15WFsIga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UGZXwUUUUU= X-Originating-IP: [166.111.70.58] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiZRfuelWBOQshiwAAsq 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_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 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 --- 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 a43a16f..28479b1 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; }