Commit 424feb59 authored by Maxime Ripard's avatar Maxime Ripard Committed by Ulf Hansson

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: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 417b1bf8
...@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -822,10 +822,13 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
break; break;
case MMC_POWER_UP: case MMC_POWER_UP:
host->ferror = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, if (!IS_ERR(mmc->supply.vmmc)) {
ios->vdd); host->ferror = mmc_regulator_set_ocr(mmc,
if (host->ferror) mmc->supply.vmmc,
return; ios->vdd);
if (host->ferror)
return;
}
if (!IS_ERR(mmc->supply.vqmmc)) { if (!IS_ERR(mmc->supply.vqmmc)) {
host->ferror = regulator_enable(mmc->supply.vqmmc); 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) ...@@ -847,7 +850,9 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
case MMC_POWER_OFF: case MMC_POWER_OFF:
dev_dbg(mmc_dev(mmc), "power off!\n"); dev_dbg(mmc_dev(mmc), "power off!\n");
sunxi_mmc_reset_host(host); sunxi_mmc_reset_host(host);
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); if (!IS_ERR(mmc->supply.vmmc))
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled)
regulator_disable(mmc->supply.vqmmc); regulator_disable(mmc->supply.vqmmc);
host->vqmmc_enabled = false; host->vqmmc_enabled = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment