]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mmc: core: Disable card detect during shutdown
authorUlf Hansson <ulf.hansson@linaro.org>
Fri, 3 Dec 2021 14:15:54 +0000 (15:15 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Dec 2021 11:28:56 +0000 (12:28 +0100)
commit 66c915d09b942fb3b2b0cb2f56562180901fba17 upstream.

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
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mmc/core/core.c
drivers/mmc/core/core.h
drivers/mmc/core/host.c

index 240c5af793dcebe03479df8066b7ef4c57cf78b4..368f10405e132ceedfb722278271bf99e422afeb 100644 (file)
@@ -2264,7 +2264,7 @@ void mmc_start_host(struct mmc_host *host)
        _mmc_detect_change(host, 0, false);
 }
 
-void mmc_stop_host(struct mmc_host *host)
+void __mmc_stop_host(struct mmc_host *host)
 {
        if (host->slot.cd_irq >= 0) {
                mmc_gpio_set_cd_wake(host, false);
@@ -2273,6 +2273,11 @@ void mmc_stop_host(struct mmc_host *host)
 
        host->rescan_disable = 1;
        cancel_delayed_work_sync(&host->detect);
+}
+
+void mmc_stop_host(struct mmc_host *host)
+{
+       __mmc_stop_host(host);
 
        /* clear pm flags now and let card drivers set them as needed */
        host->pm_flags = 0;
index 7931a4f0137d20e4ed2afc2b6eb0d80693132ed7..f5f3f623ea492660cf3653b2a1d09bd781ded0ca 100644 (file)
@@ -70,6 +70,7 @@ static inline void mmc_delay(unsigned int ms)
 
 void mmc_rescan(struct work_struct *work);
 void mmc_start_host(struct mmc_host *host);
+void __mmc_stop_host(struct mmc_host *host);
 void mmc_stop_host(struct mmc_host *host);
 
 void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
index d4683b1d263fd6dfa062fe014f3817e2201b8980..cf140f4ec864307e4c2788bc198df0c488a9638d 100644 (file)
@@ -80,9 +80,18 @@ static void mmc_host_classdev_release(struct device *dev)
        kfree(host);
 }
 
+static int mmc_host_classdev_shutdown(struct device *dev)
+{
+       struct mmc_host *host = cls_dev_to_mmc_host(dev);
+
+       __mmc_stop_host(host);
+       return 0;
+}
+
 static struct class mmc_host_class = {
        .name           = "mmc_host",
        .dev_release    = mmc_host_classdev_release,
+       .shutdown_pre   = mmc_host_classdev_shutdown,
        .pm             = MMC_HOST_CLASS_DEV_PM_OPS,
 };