mmc: vub300: fix return value check of mmc_add_host()

[ Upstream commit 0613ad2401f88bdeae5594c30afe318e93b14676 ]

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 goto error path which will call
mmc_free_host(), besides, the timer added before mmc_add_host() needs be del.

And this patch fixes another missing call mmc_free_host() if usb_control_msg()
fails.

Fixes: 88095e7b47 ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221101063023.1664968-9-yangyingliang@huawei.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Yang Yingliang 2022-11-01 14:30:22 +08:00 committed by Greg Kroah-Hartman
parent 3dbb69a024
commit 3b29f8769d

View File

@ -2306,14 +2306,14 @@ static int vub300_probe(struct usb_interface *interface,
0x0000, 0x0000, &vub300->system_port_status, 0x0000, 0x0000, &vub300->system_port_status,
sizeof(vub300->system_port_status), 1000); sizeof(vub300->system_port_status), 1000);
if (retval < 0) { if (retval < 0) {
goto error4; goto error5;
} else if (sizeof(vub300->system_port_status) == retval) { } else if (sizeof(vub300->system_port_status) == retval) {
vub300->card_present = vub300->card_present =
(0x0001 & vub300->system_port_status.port_flags) ? 1 : 0; (0x0001 & vub300->system_port_status.port_flags) ? 1 : 0;
vub300->read_only = vub300->read_only =
(0x0010 & vub300->system_port_status.port_flags) ? 1 : 0; (0x0010 & vub300->system_port_status.port_flags) ? 1 : 0;
} else { } else {
goto error4; goto error5;
} }
usb_set_intfdata(interface, vub300); usb_set_intfdata(interface, vub300);
INIT_DELAYED_WORK(&vub300->pollwork, vub300_pollwork_thread); INIT_DELAYED_WORK(&vub300->pollwork, vub300_pollwork_thread);
@ -2336,8 +2336,13 @@ static int vub300_probe(struct usb_interface *interface,
"USB vub300 remote SDIO host controller[%d]" "USB vub300 remote SDIO host controller[%d]"
"connected with no SD/SDIO card inserted\n", "connected with no SD/SDIO card inserted\n",
interface_to_InterfaceNumber(interface)); interface_to_InterfaceNumber(interface));
mmc_add_host(mmc); retval = mmc_add_host(mmc);
if (retval)
goto error6;
return 0; return 0;
error6:
del_timer_sync(&vub300->inactivity_timer);
error5: error5:
mmc_free_host(mmc); mmc_free_host(mmc);
/* /*