From bf9c4d146467297771a0f60bdb897be38671dba7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 13 Jan 2017 11:51:51 +0900 Subject: mmc: sdhci: fix NULL pointer access when host->ops is not set Until recently, sdhci_ops was used only for overriding IO accessors. (so, host->ops was not set by any drivers except bcm2835_sdhci.c) Now, we have more optional callbacks, get_cd, set_control_reg, and set_clock. However, the code if (host->ops->get_cd) host->ops->get_cd(host); ... expects host->ops is set for all drivers. Commit 5e96217f0434 ("mmc: pic32_sdhci: move the code to pic32_sdhci.c") and commit 62226b68631b ("mmc: sdhci: move the callback function into sdhci_ops") added sdhci_ops for pic32_sdhci.c and s5p_sdhci.c, but the other drivers still do not (need not) set host->ops because all callbacks in sdhci_ops are optional. host->ops must be checked to avoid the system crash caused by NULL pointer access. Signed-off-by: Masahiro Yamada diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 3a1f4f7..5b404ff 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -359,7 +359,7 @@ static int sdhci_set_clock(struct mmc *mmc, unsigned int clock) div >>= 1; } - if (host->ops->set_clock) + if (host->ops && host->ops->set_clock) host->ops->set_clock(host, div); clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; @@ -427,7 +427,7 @@ static int sdhci_set_ios(struct mmc *mmc) u32 ctrl; struct sdhci_host *host = mmc->priv; - if (host->ops->set_control_reg) + if (host->ops && host->ops->set_control_reg) host->ops->set_control_reg(host); if (mmc->clock != host->clock) @@ -480,7 +480,7 @@ static int sdhci_init(struct mmc *mmc) sdhci_set_power(host, fls(mmc->cfg->voltages) - 1); - if (host->ops->get_cd) + if (host->ops && host->ops->get_cd) host->ops->get_cd(host); /* Enable only interrupts served by the SD controller */ -- cgit v0.10.2 From 2cd44e1e6812201b6939134017b87215386813f5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 13 Jan 2017 12:13:48 +0900 Subject: mmc: pic32_sdhci: rename {pci->pic}32_sdhci_get_cd I suspect this is a typo. Signed-off-by: Masahiro Yamada diff --git a/drivers/mmc/pic32_sdhci.c b/drivers/mmc/pic32_sdhci.c index fd2f5e3..c06364c 100644 --- a/drivers/mmc/pic32_sdhci.c +++ b/drivers/mmc/pic32_sdhci.c @@ -15,7 +15,7 @@ DECLARE_GLOBAL_DATA_PTR; -static int pci32_sdhci_get_cd(struct sdhci_host *host) +static int pic32_sdhci_get_cd(struct sdhci_host *host) { /* PIC32 SDHCI CD errata: * - set CD_TEST and clear CD_TEST_INS bit @@ -26,7 +26,7 @@ static int pci32_sdhci_get_cd(struct sdhci_host *host) } static const struct sdhci_ops pic32_sdhci_ops = { - .get_cd = pci32_sdhci_get_cd, + .get_cd = pic32_sdhci_get_cd, }; static int pic32_sdhci_probe(struct udevice *dev) -- cgit v0.10.2 From 0ad178c18af3ed7f5752005a42283c4f95fcd4e3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 12 Jan 2017 12:16:15 +0900 Subject: mmc: sunxi: revive depends on UART0_PORT_F Commit f401e907fcbc ("ARM: sunxi: remove bare default for CONFIG_MMC") dropped "depends on UART0_PORT_F", but it is still needed. Revive it as a prerequisite of CONFIG_MMC_SUNXI. Signed-off-by: Masahiro Yamada Acked-by: Maxime Ripard diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 0aef132..9ed8da3 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -299,7 +299,7 @@ config MMC_SDHCI_TEGRA config MMC_SUNXI bool "Allwinner sunxi SD/MMC Host Controller support" - depends on ARCH_SUNXI + depends on ARCH_SUNXI && !UART0_PORT_F default y help This selects support for the SD/MMC Host Controller on -- cgit v0.10.2