Skip to content

Commit 66c915d

Browse files
author
Ulf Hansson
committed
mmc: core: Disable card detect during shutdown
It's seems prone to problems by allowing card detect and its corresponding mmc_rescan() work to run, during platform shutdown. For example, we may end up turning off the power while initializing a card, which potentially could damage it. To avoid this scenario, let's add ->shutdown_pre() callback for the mmc host class device and then turn of the card detect from there. Reported-by: Al Cooper <alcooperx@gmail.com> Suggested-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20211203141555.105351-1-ulf.hansson@linaro.org
1 parent 4fc7261 commit 66c915d

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

drivers/mmc/core/core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ void mmc_start_host(struct mmc_host *host)
22642264
_mmc_detect_change(host, 0, false);
22652265
}
22662266

2267-
void mmc_stop_host(struct mmc_host *host)
2267+
void __mmc_stop_host(struct mmc_host *host)
22682268
{
22692269
if (host->slot.cd_irq >= 0) {
22702270
mmc_gpio_set_cd_wake(host, false);
@@ -2273,6 +2273,11 @@ void mmc_stop_host(struct mmc_host *host)
22732273

22742274
host->rescan_disable = 1;
22752275
cancel_delayed_work_sync(&host->detect);
2276+
}
2277+
2278+
void mmc_stop_host(struct mmc_host *host)
2279+
{
2280+
__mmc_stop_host(host);
22762281

22772282
/* clear pm flags now and let card drivers set them as needed */
22782283
host->pm_flags = 0;

drivers/mmc/core/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static inline void mmc_delay(unsigned int ms)
7070

7171
void mmc_rescan(struct work_struct *work);
7272
void mmc_start_host(struct mmc_host *host);
73+
void __mmc_stop_host(struct mmc_host *host);
7374
void mmc_stop_host(struct mmc_host *host);
7475

7576
void _mmc_detect_change(struct mmc_host *host, unsigned long delay,

drivers/mmc/core/host.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,18 @@ static void mmc_host_classdev_release(struct device *dev)
8080
kfree(host);
8181
}
8282

83+
static int mmc_host_classdev_shutdown(struct device *dev)
84+
{
85+
struct mmc_host *host = cls_dev_to_mmc_host(dev);
86+
87+
__mmc_stop_host(host);
88+
return 0;
89+
}
90+
8391
static struct class mmc_host_class = {
8492
.name = "mmc_host",
8593
.dev_release = mmc_host_classdev_release,
94+
.shutdown_pre = mmc_host_classdev_shutdown,
8695
.pm = MMC_HOST_CLASS_DEV_PM_OPS,
8796
};
8897

0 commit comments

Comments
 (0)