mmc: host: Return an error when ->enable_sdio_irq() ops is missing
authorUlf Hansson <ulf.hansson@linaro.org>
Thu, 3 Mar 2022 16:51:42 +0000 (17:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:06:40 +0000 (09:06 +0200)
[ Upstream commit d6c9219ca1139b74541b2a98cee47a3426d754a9 ]

Even if the current WARN() notifies the user that something is severely
wrong, we can still end up in a PANIC() when trying to invoke the missing
->enable_sdio_irq() ops. Therefore, let's also return an error code and
prevent the host from being added.

While at it, move the code into a separate function to prepare for
subsequent changes and for further host caps validations.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20220303165142.129745-1-ulf.hansson@linaro.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mmc/core/host.c

index 848b3453517ea62bd4f717bc17a757129d33eb13..60c2ca58dec34c16054cb2a8af5daa87ddadff01 100644 (file)
@@ -403,6 +403,16 @@ again:
 
 EXPORT_SYMBOL(mmc_alloc_host);
 
+static int mmc_validate_host_caps(struct mmc_host *host)
+{
+       if (host->caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) {
+               dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 /**
  *     mmc_add_host - initialise host hardware
  *     @host: mmc host
@@ -415,8 +425,9 @@ int mmc_add_host(struct mmc_host *host)
 {
        int err;
 
-       WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
-               !host->ops->enable_sdio_irq);
+       err = mmc_validate_host_caps(host);
+       if (err)
+               return err;
 
        err = device_add(&host->class_dev);
        if (err)