mmc: rtsx_pci: fix return value check of mmc_add_host()
Subsystems (2)
PATCH 1/1 mmc: rtsx_pci: fix return value check of mmc_add_host()
From: Yang Yingliang <[email protected]>
commit 0c87db77423a282b3b38b8a6daf057b822680516 upstream.
mmc_add_host() may return error, if we ignore its return value, the memory that allocated in mmc_alloc_host() will be leaked and it will lead a kernel crash because of deleting not added device in the remove path.
So fix this by checking the return value and calling mmc_free_host() in the error path, beside, runtime PM also needs be disabled.
[Denis Arefev: adapted for 5.10: the pm_runtime_dont_use_autosuspend() and pm_runtime_disable() calls present in the upstream commit are not included, since runtime PM support was never added to the rtsx_pci_sdmmc driver in this tree (the probe/remove path has no pm_runtime calls).]
--- drivers/mmc/host/rtsx_pci_sdmmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mmc/host/rtsx_pci_sdmmc.c +6 -1
@@ -1439,6 +1439,7 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)struct realtek_pci_sdmmc *host;struct rtsx_pcr *pcr;struct pcr_handle *handle = pdev->dev.platform_data; +int ret;if (!handle)return -ENXIO ;
@@ -1469,7 +1470,11 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)realtek_init_host (host); -mmc_add_host (mmc); + ret =mmc_add_host (mmc); +if (ret) { +mmc_free_host (mmc); +return ret; + }return 0 ; }
Signature · 1 line
2.43.0