Skip to content

Commit 424feb5

Browse files
mripardstorulf
authored andcommitted
mmc: sunxi: Prevent against null dereference for vmmc
VMMC is an optional regulator, which means that mmc_regulator_get_supply will only return an error in case of a deferred probe, but not when the regulator is not set in the DT. However, the sunxi driver assumes that VMMC is always there, and doesn't check the value of the regulator pointer before using it, which obviously leads to a (close to) null pointer dereference. Add proper checks to prevent that. Signed-off-by: Maxime Ripard <[email protected]> Acked-by: Chen-Yu Tsai <[email protected]> Signed-off-by: Ulf Hansson <[email protected]>
1 parent 417b1bf commit 424feb5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/mmc/host/sunxi-mmc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
822822
break;
823823

824824
case MMC_POWER_UP:
825-
host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
826-
ios->vdd);
827-
if (host->ferror)
828-
return;
825+
if (!IS_ERR(mmc->supply.vmmc)) {
826+
host->ferror = mmc_regulator_set_ocr(mmc,
827+
mmc->supply.vmmc,
828+
ios->vdd);
829+
if (host->ferror)
830+
return;
831+
}
829832

830833
if (!IS_ERR(mmc->supply.vqmmc)) {
831834
host->ferror = regulator_enable(mmc->supply.vqmmc);
@@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
847850
case MMC_POWER_OFF:
848851
dev_dbg(mmc_dev(mmc), "power off!\n");
849852
sunxi_mmc_reset_host(host);
850-
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
853+
if (!IS_ERR(mmc->supply.vmmc))
854+
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
855+
851856
if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
852857
regulator_disable(mmc->supply.vqmmc);
853858
host->vqmmc_enabled = false;

0 commit comments

Comments
 (0)