mmc: rtsx_pci: fix return value check of mmc_add_host()
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 1 Nov 2022 06:30:19 +0000 (14:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:24 +0000 (13:32 +0100)
commitffa9b2a79e3e959683efbad3f6db937eca9d38f5
tree6ade7556aecc63431b375a70a2251dba3415f53e
parent5a62cba138519161a2fe4937720b2649760e57e9
mmc: rtsx_pci: fix return value check of mmc_add_host()

[ Upstream commit 0c87db77423a282b3b38b8a6daf057b822680516 ]

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@huawei.com>
Link: https://lore.kernel.org/r/20221101063023.1664968-6-yangyingliang@huawei.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mmc/host/rtsx_pci_sdmmc.c