From patchwork Sat Mar 11 01:39:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9618297 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA9B9604DD for ; Sat, 11 Mar 2017 01:40:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC2CA287AD for ; Sat, 11 Mar 2017 01:40:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFB73287B7; Sat, 11 Mar 2017 01:40:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49D3C287AD for ; Sat, 11 Mar 2017 01:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933586AbdCKBjq (ORCPT ); Fri, 10 Mar 2017 20:39:46 -0500 Received: from mail-pg0-f48.google.com ([74.125.83.48]:33738 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932614AbdCKBjd (ORCPT ); Fri, 10 Mar 2017 20:39:33 -0500 Received: by mail-pg0-f48.google.com with SMTP id 25so44851997pgy.0 for ; Fri, 10 Mar 2017 17:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OoBIyzYt88S8wDvYq2jGuw99T6b6eZRKLl23G5/vyWg=; b=NWlj1C2W2ZDenDdluo7BusrSm77ZucJVIY9xzx2GHv/PqHWuzPceY3Iwh3R5ld8p5D PXPfjvI8/dS4PX9XKhPblPfLHfwo5cjMvlsSg2TD3nl1KyRfTwomgWaqppFQBpQFUl3h 4mXdAS8LI5xlP9cw99HWMynEoSjoy0ZCyOiJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OoBIyzYt88S8wDvYq2jGuw99T6b6eZRKLl23G5/vyWg=; b=mLUBigjk1IU0O18+Q1xcEVaT2FdNRzfGw1tyWFNbZueBvMuOuqoXqsrgjRsoRVd5VX MZ7Lt4NMv9ZdACFb3f8EndGH68iGE23/1eJrj6OdJvKF13FEzih72Zymn6AYjdSuw4oV ALZw2Em9EcnDtsnklGPN+YU/hoe3Hx+Ct+jY67VF6oeNUHSmrsAGKSEK9h7KcaeLx0gU z8C0h+FfzuMt7mVpUvY5hAB/LMfPqwc1oCuoqUfQfX6o/S+bKD95JqFCrRq04ky4vU3/ 6yZuLVJlhn2BNA3buSl+dFT3+wtGNWTLsZUrS40Z/w865/gYTle4OFTp8LQ72t9Z5+XP WWkQ== X-Gm-Message-State: AMke39nWPJGZOjuryH60I4s7ysS42o3SHSMUsSJnB2tzs/OktfeAlwwbnuwsfTz+COzrVqCZ X-Received: by 10.99.127.27 with SMTP id a27mr23309419pgd.87.1489196371080; Fri, 10 Mar 2017 17:39:31 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id t133sm20984084pgc.24.2017.03.10.17.39.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Mar 2017 17:39:30 -0800 (PST) From: Brian Norris To: Amitkumar Karwar , Nishant Sarmukadam Cc: Kalle Valo , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Rajat Jain , Brian Norris , stable@vger.kernel.org Subject: [PATCH 1/4] mwifiex: pcie: don't leak DMA buffers when removing Date: Fri, 10 Mar 2017 17:39:21 -0800 Message-Id: <20170311013924.73348-2-briannorris@chromium.org> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170311013924.73348-1-briannorris@chromium.org> References: <20170311013924.73348-1-briannorris@chromium.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When PCIe FLR support was added, much of the remove/release code for PCIe was migrated to ->down_dev(), but ->down_dev() is never called for device removal. Let's refactor the cleanup to be done in both cases. Also, drop the comments above mwifiex_cleanup_pcie(), because they were clearly wrong, and it's better to have clear and obvious code than to detail the code steps in comments anyway. Fixes: 4c5dae59d2e9 ("mwifiex: add PCIe function level reset support") Cc: Signed-off-by: Brian Norris --- I don't think there's any code path in which we see ->down_dev() followed by ->cleanup_if(), with no ->up_dev() in between? (Or, what happens if PCIe FLR fails?) But if so, then this could cause a double free. It could use a close review. drivers/net/wireless/marvell/mwifiex/pcie.c | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index 5438483fcefe..eae1cc58a310 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -2732,6 +2732,21 @@ static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter) schedule_work(&card->work); } +static void mwifiex_pcie_free_buffers(struct mwifiex_adapter *adapter) +{ + struct pcie_service_card *card = adapter->card; + const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; + + if (reg->sleep_cookie) + mwifiex_pcie_delete_sleep_cookie_buf(adapter); + + mwifiex_pcie_delete_cmdrsp_buf(adapter); + mwifiex_pcie_delete_evtbd_ring(adapter); + mwifiex_pcie_delete_rxbd_ring(adapter); + mwifiex_pcie_delete_txbd_ring(adapter); + card->cmdrsp_buf = NULL; +} + /* * This function initializes the PCI-E host memory space, WCB rings, etc. * @@ -2843,13 +2858,6 @@ static int mwifiex_init_pcie(struct mwifiex_adapter *adapter) /* * This function cleans up the allocated card buffers. - * - * The following are freed by this function - - * - TXBD ring buffers - * - RXBD ring buffers - * - Event BD ring buffers - * - Command response ring buffer - * - Sleep cookie buffer */ static void mwifiex_cleanup_pcie(struct mwifiex_adapter *adapter) { @@ -2868,6 +2876,8 @@ static void mwifiex_cleanup_pcie(struct mwifiex_adapter *adapter) "Failed to write driver not-ready signature\n"); } + mwifiex_pcie_free_buffers(adapter); + if (pdev) { pci_iounmap(pdev, card->pci_mmap); pci_iounmap(pdev, card->pci_mmap1); @@ -3119,10 +3129,7 @@ static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter) pci_iounmap(pdev, card->pci_mmap1); } -/* This function cleans up the PCI-E host memory space. - * Some code is extracted from mwifiex_unregister_dev() - * - */ +/* This function cleans up the PCI-E host memory space. */ static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) { struct pcie_service_card *card = adapter->card; @@ -3133,14 +3140,7 @@ static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) adapter->seq_num = 0; - if (reg->sleep_cookie) - mwifiex_pcie_delete_sleep_cookie_buf(adapter); - - mwifiex_pcie_delete_cmdrsp_buf(adapter); - mwifiex_pcie_delete_evtbd_ring(adapter); - mwifiex_pcie_delete_rxbd_ring(adapter); - mwifiex_pcie_delete_txbd_ring(adapter); - card->cmdrsp_buf = NULL; + mwifiex_pcie_free_buffers(adapter); } static struct mwifiex_if_ops pcie_ops = {