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

mwifiex: fix memory leak issue for sdio and pcie cards

When driver is failed to load, card pointer doesn't get
freed. We will free it in cleanup handler which is called
in failure as well as unload path.
Also, update drvdata in init/cleanup handlers instead of
register/unregister handlers.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

authored by

Amitkumar Karwar and committed by
John W. Linville
3c59e328 98a4635b

+5 -4
+1 -1
drivers/net/wireless/mwifiex/pcie.c
··· 232 232 } 233 233 234 234 mwifiex_remove_card(card->adapter, &add_remove_card_sem); 235 - kfree(card); 236 235 } 237 236 238 237 static void mwifiex_pcie_shutdown(struct pci_dev *pdev) ··· 2312 2313 pci_release_region(pdev, 0); 2313 2314 pci_set_drvdata(pdev, NULL); 2314 2315 } 2316 + kfree(card); 2315 2317 } 2316 2318 2317 2319 /*
+4 -3
drivers/net/wireless/mwifiex/sdio.c
··· 196 196 } 197 197 198 198 mwifiex_remove_card(card->adapter, &add_remove_card_sem); 199 - kfree(card); 200 199 } 201 200 202 201 /* ··· 1744 1745 sdio_claim_host(card->func); 1745 1746 sdio_disable_func(card->func); 1746 1747 sdio_release_host(card->func); 1747 - sdio_set_drvdata(card->func, NULL); 1748 1748 } 1749 1749 } 1750 1750 ··· 1771 1773 return ret; 1772 1774 } 1773 1775 1774 - sdio_set_drvdata(func, card); 1775 1776 1776 1777 adapter->dev = &func->dev; 1777 1778 ··· 1797 1800 const struct mwifiex_sdio_card_reg *reg = card->reg; 1798 1801 int ret; 1799 1802 u8 sdio_ireg; 1803 + 1804 + sdio_set_drvdata(card->func, card); 1800 1805 1801 1806 /* 1802 1807 * Read the HOST_INT_STATUS_REG for ACK the first interrupt got ··· 1882 1883 kfree(card->mpa_rx.len_arr); 1883 1884 kfree(card->mpa_tx.buf); 1884 1885 kfree(card->mpa_rx.buf); 1886 + sdio_set_drvdata(card->func, NULL); 1887 + kfree(card); 1885 1888 } 1886 1889 1887 1890 /*