Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <maxime.ripard@free-electrons.com>
Acked-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Maxime Ripard and committed by
Ulf Hansson
424feb59 417b1bf8

+10 -5
+10 -5
drivers/mmc/host/sunxi-mmc.c
··· 822 822 break; 823 823 824 824 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 + } 829 832 830 833 if (!IS_ERR(mmc->supply.vqmmc)) { 831 834 host->ferror = regulator_enable(mmc->supply.vqmmc); ··· 850 847 case MMC_POWER_OFF: 851 848 dev_dbg(mmc_dev(mmc), "power off!\n"); 852 849 sunxi_mmc_reset_host(host); 853 - mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); 850 + if (!IS_ERR(mmc->supply.vmmc)) 851 + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); 852 + 854 853 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) 855 854 regulator_disable(mmc->supply.vqmmc); 856 855 host->vqmmc_enabled = false;