Skip to contentSkip to conversation

mmc: dw_mmc: Add a defensive check to prevent potential null-pointer dereferences in dw_mci_runtime_resume()

PATCH In review Tuo Li 2 participants 3 messages Dec 11, 2025 – Dec 12, 2025

Subsystems (2)
lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 mmc: dw_mmc: Add a defensive check to prevent potential null-pointer dereferences in dw_mci_runtime_resume()

In this function, the variable host->slot is checked and then dereferenced in several places which indicates it can be NULL, for example:

if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)

		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);

However, in the following cases, host->slot is dereferenced without a preceding NULL check, which introduces a risk of null-pointer dereference:

  dw_mci_setup_bus(host->slot, true);

  if (sdio_irq_claimed(host->slot->mmc))
    __dw_mci_enable_sdio_irq(host->slot, 1);

  dw_mci_enable_cd(host);

To prevent such issues, add a defensive check to ensure host->slot is not NULL before dereferencing it.

---
 drivers/mmc/host/dw_mmc.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/mmc/host/dw_mmc.c +10 -7
index 9e74b675e92d..e74dea0a32d4 100644
@@ -3670,15 +3670,18 @@ int dw_mci_runtime_resume(struct device *dev)
 	if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
 		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
 
-	/* Force setup bus to guarantee available clock output */
-	dw_mci_setup_bus(host->slot, true);
 
-	/* Re-enable SDIO interrupts. */
-	if (sdio_irq_claimed(host->slot->mmc))
-		__dw_mci_enable_sdio_irq(host->slot, 1);
+	if (host->slot) {
+		/* Force setup bus to guarantee available clock output */
+		dw_mci_setup_bus(host->slot, true);
 
-	/* Now that slots are all setup, we can enable card detect */
-	dw_mci_enable_cd(host);
+		/* Re-enable SDIO interrupts. */
+		if (sdio_irq_claimed(host->slot->mmc))
+			__dw_mci_enable_sdio_irq(host->slot, 1);
+
+		/* Now that slots are all setup, we can enable card detect */
+		dw_mci_enable_cd(host);
+	}
 
 	return 0;
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi Tuo,

Quoted 16 lines · Tuo Li

In this function, the variable host->slot is checked and then dereferenced in several places which indicates it can be NULL, for example:

   if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);

However, in the following cases, host->slot is dereferenced without a preceding NULL check, which introduces a risk of null-pointer dereference:

   dw_mci_setup_bus(host->slot, true);

   if (sdio_irq_claimed(host->slot->mmc))
     __dw_mci_enable_sdio_irq(host->slot, 1);

   dw_mci_enable_cd(host);
Quoted 3 lines

To prevent such issues, add a defensive check to ensure host->slot is not NULL before dereferencing it.

Thanks for your patch. we plan to remove the slot design entirely soon, probably this cycle.

Quoted 35 lines
---
  drivers/mmc/host/dw_mmc.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
drivers/mmc/host/dw_mmc.c +10 -7
index 9e74b675e92d..e74dea0a32d4 100644
@@ -3670,15 +3670,18 @@ int dw_mci_runtime_resume(struct device *dev)
  	if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
  		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
 
-	/* Force setup bus to guarantee available clock output */
-	dw_mci_setup_bus(host->slot, true);
 
-	/* Re-enable SDIO interrupts. */
-	if (sdio_irq_claimed(host->slot->mmc))
-		__dw_mci_enable_sdio_irq(host->slot, 1);
+	if (host->slot) {
+		/* Force setup bus to guarantee available clock output */
+		dw_mci_setup_bus(host->slot, true);
 
-	/* Now that slots are all setup, we can enable card detect */
-	dw_mci_enable_cd(host);
+		/* Re-enable SDIO interrupts. */
+		if (sdio_irq_claimed(host->slot->mmc))
+			__dw_mci_enable_sdio_irq(host->slot, 1);
+
+		/* Now that slots are all setup, we can enable card detect */
+		dw_mci_enable_cd(host);
+	}
 
  	return 0;
 
author
#2 lore raw

Hi Shawn,

Quoted 18 lines · Shawn Lin

Hi Tuo,

Quoted 14 lines · Tuo Li

In this function, the variable host->slot is checked and then dereferenced in several places which indicates it can be NULL, for example:

   if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
              dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);

However, in the following cases, host->slot is dereferenced without a preceding NULL check, which introduces a risk of null-pointer dereference:

   dw_mci_setup_bus(host->slot, true);

   if (sdio_irq_claimed(host->slot->mmc))
     __dw_mci_enable_sdio_irq(host->slot, 1);
Quoted 9 lines
Quoted 5 lines
   dw_mci_enable_cd(host);

To prevent such issues, add a defensive check to ensure host->slot is not NULL before dereferencing it.

Thanks for your patch. we plan to remove the slot design entirely soon, probably this cycle.

Thanks for your feedback!

Quoted 33 lines
Quoted 33 lines
---
  drivers/mmc/host/dw_mmc.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
drivers/mmc/host/dw_mmc.c +10 -7
index 9e74b675e92d..e74dea0a32d4 100644
@@ -3670,15 +3670,18 @@ int dw_mci_runtime_resume(struct device *dev)
      if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
              dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
 
-     /* Force setup bus to guarantee available clock output */
-     dw_mci_setup_bus(host->slot, true);
 
-     /* Re-enable SDIO interrupts. */
-     if (sdio_irq_claimed(host->slot->mmc))
-             __dw_mci_enable_sdio_irq(host->slot, 1);
+     if (host->slot) {
+             /* Force setup bus to guarantee available clock output */
+             dw_mci_setup_bus(host->slot, true);
 
-     /* Now that slots are all setup, we can enable card detect */
-     dw_mci_enable_cd(host);
+             /* Re-enable SDIO interrupts. */
+             if (sdio_irq_claimed(host->slot->mmc))
+                     __dw_mci_enable_sdio_irq(host->slot, 1);
+
+             /* Now that slots are all setup, we can enable card detect */
+             dw_mci_enable_cd(host);
+     }
 
Quoted 3 lines

drivers/mmc/host/dw_mmc.c int dw_mci_runtime_resume(struct device *dev) · line 3687

Quoted 2 lines
drivers/mmc/host/dw_mmc.c +0 -0
      return 0;
 

Sincerely,
Tuo Li