linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: host: dw_mmc: Fix possible null-pointer dereferences in dw_mci_runtime_resume()
@ 2019-07-26 14:22 Jia-Ju Bai
  2019-08-01 14:58 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-07-26 14:22 UTC (permalink / raw)
  To: jh80.chung, ulf.hansson; +Cc: linux-mmc, linux-kernel, Jia-Ju Bai

In dw_mci_runtime_resume(), there is an if statement on line 3420 
to check whether host->slot is NULL:
    if (host->slot && ...)

When host->slot is NULL, it is used on line 3458:
    if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
and on line 3462:
    dw_mci_setup_bus(host->slot, true);
        struct dw_mci *host = slot->host;

Thus, possible null-pointer dereferences may occur.

To fix these bugs, host->slot is checked before being used.

These bugs are found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/mmc/host/dw_mmc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index faaaf52a46d2..91bd6c3ccf50 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -3455,11 +3455,12 @@ int dw_mci_runtime_resume(struct device *dev)
 	mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
 
 
-	if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
+	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);
+	if (host->slot)
+		dw_mci_setup_bus(host->slot, true);
 
 	/* Now that slots are all setup, we can enable card detect */
 	dw_mci_enable_cd(host);
-- 
2.17.0


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

end of thread, other threads:[~2019-08-01 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26 14:22 [PATCH] mmc: host: dw_mmc: Fix possible null-pointer dereferences in dw_mci_runtime_resume() Jia-Ju Bai
2019-08-01 14:58 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).