The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mmc: dw_mmc: Add a defensive check to prevent potential null-pointer dereferences in dw_mci_runtime_resume()
@ 2025-12-11 16:13 Tuo Li
  2025-12-12  0:28 ` Shawn Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Tuo Li @ 2025-12-11 16:13 UTC (permalink / raw)
  To: jh80.chung, shawn.lin, ulf.hansson; +Cc: linux-mmc, linux-kernel, 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);

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

Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/mmc/host/dw_mmc.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 9e74b675e92d..e74dea0a32d4 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -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;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-12  5:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 16:13 [PATCH] mmc: dw_mmc: Add a defensive check to prevent potential null-pointer dereferences in dw_mci_runtime_resume() Tuo Li
2025-12-12  0:28 ` Shawn Lin
2025-12-12  5:13   ` Tuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox