From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-mmc@vger.kernel.org>
Cc: <ulf.hansson@linaro.org>, <yangyingliang@huawei.com>
Subject: [PATCH 6/9] mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host()
Date: Tue, 1 Nov 2022 14:30:20 +0800 [thread overview]
Message-ID: <20221101063023.1664968-7-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221101063023.1664968-1-yangyingliang@huawei.com>
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, besides, led_classdev_unregister() and pm_runtime_disable() also
need be called.
Fixes: c7f6558d84af ("mmc: Add realtek USB sdmmc host driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/mmc/host/rtsx_usb_sdmmc.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index 5798aee06653..2c650cd58693 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -1329,6 +1329,7 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
#ifdef RTSX_USB_USE_LEDS_CLASS
int err;
#endif
+ int ret;
ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent));
if (!ucr)
@@ -1365,7 +1366,15 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
INIT_WORK(&host->led_work, rtsx_usb_update_led);
#endif
- mmc_add_host(mmc);
+ ret = mmc_add_host(mmc);
+ if (ret) {
+#ifdef RTSX_USB_USE_LEDS_CLASS
+ led_classdev_unregister(&host->led);
+#endif
+ mmc_free_host(mmc);
+ pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2022-11-01 6:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 6:30 [PATCH 0/9] mmc: fix return value check of mmc_add_host() Yang Yingliang
2022-11-01 6:30 ` [PATCH 1/9] mmc: alcor: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 2/9] mmc: moxart: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 3/9] mmc: mxcmmc: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 4/9] mmc: pxamci: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 5/9] mmc: rtsx_pci: " Yang Yingliang
2022-11-01 6:30 ` Yang Yingliang [this message]
2022-11-01 6:30 ` [PATCH 7/9] mmc: toshsd: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 8/9] mmc: vub300: " Yang Yingliang
2022-11-01 6:30 ` [PATCH 9/9] mmc: wmt-sdmmc: " Yang Yingliang
2022-11-08 16:05 ` [PATCH 0/9] mmc: " Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221101063023.1664968-7-yangyingliang@huawei.com \
--to=yangyingliang@huawei.com \
--cc=linux-mmc@vger.kernel.org \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.