Commit 2f69745c authored by Brian Norris's avatar Brian Norris Committed by Greg Kroah-Hartman

mwifiex: pcie: don't leak DMA buffers when removing

commit 4e841d3e upstream.

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: 4c5dae59 ("mwifiex: add PCIe function level reset support")
Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ad3b48d3
...@@ -2742,6 +2742,21 @@ static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter) ...@@ -2742,6 +2742,21 @@ static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter)
schedule_work(&pcie_work); schedule_work(&pcie_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. * This function initializes the PCI-E host memory space, WCB rings, etc.
* *
...@@ -2853,13 +2868,6 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter) ...@@ -2853,13 +2868,6 @@ static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
/* /*
* This function cleans up the allocated card buffers. * 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_pcie_cleanup(struct mwifiex_adapter *adapter) static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
{ {
...@@ -2875,6 +2883,8 @@ static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter) ...@@ -2875,6 +2883,8 @@ static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
"Failed to write driver not-ready signature\n"); "Failed to write driver not-ready signature\n");
} }
mwifiex_pcie_free_buffers(adapter);
if (pdev) { if (pdev) {
pci_iounmap(pdev, card->pci_mmap); pci_iounmap(pdev, card->pci_mmap);
pci_iounmap(pdev, card->pci_mmap1); pci_iounmap(pdev, card->pci_mmap1);
...@@ -3115,10 +3125,7 @@ static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter) ...@@ -3115,10 +3125,7 @@ static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter)
pci_iounmap(pdev, card->pci_mmap1); pci_iounmap(pdev, card->pci_mmap1);
} }
/* This function cleans up the PCI-E host memory space. /* This function cleans up the PCI-E host memory space. */
* Some code is extracted from mwifiex_unregister_dev()
*
*/
static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter)
{ {
struct pcie_service_card *card = adapter->card; struct pcie_service_card *card = adapter->card;
...@@ -3130,14 +3137,7 @@ static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) ...@@ -3130,14 +3137,7 @@ static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter)
adapter->seq_num = 0; adapter->seq_num = 0;
adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K; adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
if (reg->sleep_cookie) mwifiex_pcie_free_buffers(adapter);
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;
} }
static struct mwifiex_if_ops pcie_ops = { static struct mwifiex_if_ops pcie_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment