[PATCH 5.10] mmc: rtsx_pci: fix return value check of mmc_add_host()

From: Denis Arefev

Date: Tue Nov 24 2026 - 04:42:18 EST


From: Yang Yingliang <yangyingliang@xxxxxxxxxx>

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.

Fixes: ff984e57d36e ("mmc: Add realtek pcie sdmmc host driver")
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Link: https://lore.kernel.org/r/20221101063023.1664968-6-yangyingliang@xxxxxxxxxx
Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
[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).]
Signed-off-by: Denis Arefev <arefev@xxxxxxxxx>
---
drivers/mmc/host/rtsx_pci_sdmmc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index f0e9a7667994..161bc5b98ed6 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -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;
}
--
2.43.0