Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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: <stable@vger.kernel.org>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

authored by

Brian Norris and committed by
Kalle Valo
4e841d3e 9a3fcf91

+19 -19
+19 -19
drivers/net/wireless/marvell/mwifiex/pcie.c
··· 2739 2739 schedule_work(&card->work); 2740 2740 } 2741 2741 2742 + static void mwifiex_pcie_free_buffers(struct mwifiex_adapter *adapter) 2743 + { 2744 + struct pcie_service_card *card = adapter->card; 2745 + const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; 2746 + 2747 + if (reg->sleep_cookie) 2748 + mwifiex_pcie_delete_sleep_cookie_buf(adapter); 2749 + 2750 + mwifiex_pcie_delete_cmdrsp_buf(adapter); 2751 + mwifiex_pcie_delete_evtbd_ring(adapter); 2752 + mwifiex_pcie_delete_rxbd_ring(adapter); 2753 + mwifiex_pcie_delete_txbd_ring(adapter); 2754 + card->cmdrsp_buf = NULL; 2755 + } 2756 + 2742 2757 /* 2743 2758 * This function initializes the PCI-E host memory space, WCB rings, etc. 2744 2759 * ··· 2865 2850 2866 2851 /* 2867 2852 * This function cleans up the allocated card buffers. 2868 - * 2869 - * The following are freed by this function - 2870 - * - TXBD ring buffers 2871 - * - RXBD ring buffers 2872 - * - Event BD ring buffers 2873 - * - Command response ring buffer 2874 - * - Sleep cookie buffer 2875 2853 */ 2876 2854 static void mwifiex_cleanup_pcie(struct mwifiex_adapter *adapter) 2877 2855 { ··· 2882 2874 mwifiex_dbg(adapter, ERROR, 2883 2875 "Failed to write driver not-ready signature\n"); 2884 2876 } 2877 + 2878 + mwifiex_pcie_free_buffers(adapter); 2885 2879 2886 2880 if (pdev) { 2887 2881 pci_iounmap(pdev, card->pci_mmap); ··· 3136 3126 pci_iounmap(pdev, card->pci_mmap1); 3137 3127 } 3138 3128 3139 - /* This function cleans up the PCI-E host memory space. 3140 - * Some code is extracted from mwifiex_unregister_dev() 3141 - * 3142 - */ 3129 + /* This function cleans up the PCI-E host memory space. */ 3143 3130 static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) 3144 3131 { 3145 3132 struct pcie_service_card *card = adapter->card; ··· 3147 3140 3148 3141 adapter->seq_num = 0; 3149 3142 3150 - if (reg->sleep_cookie) 3151 - mwifiex_pcie_delete_sleep_cookie_buf(adapter); 3152 - 3153 - mwifiex_pcie_delete_cmdrsp_buf(adapter); 3154 - mwifiex_pcie_delete_evtbd_ring(adapter); 3155 - mwifiex_pcie_delete_rxbd_ring(adapter); 3156 - mwifiex_pcie_delete_txbd_ring(adapter); 3157 - card->cmdrsp_buf = NULL; 3143 + mwifiex_pcie_free_buffers(adapter); 3158 3144 } 3159 3145 3160 3146 static struct mwifiex_if_ops pcie_ops = {