From 1a9d1731f93ad170f0c19b93407630b0fb966fd0 Mon Sep 17 00:00:00 2001 From: Tobias Jakobi Date: Mon, 5 Oct 2015 13:47:50 +0200 Subject: exynos: Properly zero initialize host in s5p_sdhci_init() This makes sure that setting the host_caps in s5p_sdhci_core_init() doesn't operate on potentially uninitialized memory. Acked-by: Lukasz Majewski Signed-off-by: Tobias Jakobi Signed-off-by: Minkyu Kang --- drivers/mmc/s5p_sdhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c index 4db51d6488a..911e7a83077 100644 --- a/drivers/mmc/s5p_sdhci.c +++ b/drivers/mmc/s5p_sdhci.c @@ -84,9 +84,9 @@ static int s5p_sdhci_core_init(struct sdhci_host *host) int s5p_sdhci_init(u32 regbase, int index, int bus_width) { - struct sdhci_host *host = malloc(sizeof(struct sdhci_host)); + struct sdhci_host *host = calloc(1, sizeof(struct sdhci_host)); if (!host) { - printf("sdhci__host malloc fail!\n"); + printf("sdhci__host allocation fail!\n"); return 1; } host->ioaddr = (void *)regbase; -- cgit v1.3.1 From 6a9fbb6e20eda538eb1cb394000d95c7577555ad Mon Sep 17 00:00:00 2001 From: Tobias Jakobi Date: Mon, 5 Oct 2015 13:47:51 +0200 Subject: exynos: Fix passing of errors in exynos_mmc_init() exynos_mmc_init() always returns zero, so for the caller it looks like it never fails. Correct this by returning the error code of process_nodes(). For process_nodes() do something similar and return early when do_sdhci_init() fails. v2: Only fail in process_nodes() if we fail on all available nodes. Acked-by: Przemyslaw Marczak Signed-off-by: Tobias Jakobi Signed-off-by: Minkyu Kang --- drivers/mmc/s5p_sdhci.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c index 911e7a83077..bd9e0147487 100644 --- a/drivers/mmc/s5p_sdhci.c +++ b/drivers/mmc/s5p_sdhci.c @@ -171,6 +171,7 @@ static int process_nodes(const void *blob, int node_list[], int count) { struct sdhci_host *host; int i, node; + int failed = 0; debug("%s: count = %d\n", __func__, count); @@ -184,11 +185,18 @@ static int process_nodes(const void *blob, int node_list[], int count) if (sdhci_get_config(blob, node, host)) { printf("%s: failed to decode dev %d\n", __func__, i); - return -1; + failed++; + continue; + } + + if (do_sdhci_init(host)) { + printf("%s: failed to initialize dev %d\n", __func__, i); + failed++; } - do_sdhci_init(host); } - return 0; + + /* we only consider it an error when all nodes fail */ + return (failed == count ? -1 : 0); } int exynos_mmc_init(const void *blob) @@ -200,8 +208,6 @@ int exynos_mmc_init(const void *blob) COMPAT_SAMSUNG_EXYNOS_MMC, node_list, SDHCI_MAX_HOSTS); - process_nodes(blob, node_list, count); - - return 0; + return process_nodes(blob, node_list, count); } #endif -- cgit v1.3.1 From 995a54cc120e2a1e56a79ea9abb0ba9d343c8997 Mon Sep 17 00:00:00 2001 From: Tobias Jakobi Date: Mon, 5 Oct 2015 13:47:52 +0200 Subject: exynos: be more verbose in process_nodes() In case sdhci_get_config() or do_sdhci_init() fail, show the error code that was returned. Acked-by: Przemyslaw Marczak Signed-off-by: Tobias Jakobi Signed-off-by: Minkyu Kang --- drivers/mmc/s5p_sdhci.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c index bd9e0147487..b203beef35e 100644 --- a/drivers/mmc/s5p_sdhci.c +++ b/drivers/mmc/s5p_sdhci.c @@ -170,7 +170,7 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host) static int process_nodes(const void *blob, int node_list[], int count) { struct sdhci_host *host; - int i, node; + int i, node, ret; int failed = 0; debug("%s: count = %d\n", __func__, count); @@ -183,14 +183,16 @@ static int process_nodes(const void *blob, int node_list[], int count) host = &sdhci_host[i]; - if (sdhci_get_config(blob, node, host)) { - printf("%s: failed to decode dev %d\n", __func__, i); + ret = sdhci_get_config(blob, node, host); + if (ret) { + printf("%s: failed to decode dev %d (%d)\n", __func__, i, ret); failed++; continue; } - if (do_sdhci_init(host)) { - printf("%s: failed to initialize dev %d\n", __func__, i); + ret = do_sdhci_init(host); + if (ret) { + printf("%s: failed to initialize dev %d (%d)\n", __func__, i, ret); failed++; } } -- cgit v1.3.1 From 2308ea7c6fe003f699f4648d4ac3bb030fdc64d0 Mon Sep 17 00:00:00 2001 From: Tobias Jakobi Date: Mon, 5 Oct 2015 13:47:53 +0200 Subject: exynos: more debug and cleanup in do_sdhci_init() Add more debug printfs in do_sdhci_init() for calls that can potentially fail. Acked-by: Przemyslaw Marczak Signed-off-by: Tobias Jakobi Signed-off-by: Minkyu Kang --- drivers/mmc/s5p_sdhci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c index b203beef35e..15ecfee961b 100644 --- a/drivers/mmc/s5p_sdhci.c +++ b/drivers/mmc/s5p_sdhci.c @@ -101,29 +101,31 @@ struct sdhci_host sdhci_host[SDHCI_MAX_HOSTS]; static int do_sdhci_init(struct sdhci_host *host) { - int dev_id, flag; - int err = 0; + int dev_id, flag, ret; flag = host->bus_width == 8 ? PINMUX_FLAG_8BIT_MODE : PINMUX_FLAG_NONE; dev_id = host->index + PERIPH_ID_SDMMC0; if (dm_gpio_is_valid(&host->pwr_gpio)) { dm_gpio_set_value(&host->pwr_gpio, 1); - err = exynos_pinmux_config(dev_id, flag); - if (err) { + ret = exynos_pinmux_config(dev_id, flag); + if (ret) { debug("MMC not configured\n"); - return err; + return ret; } } if (dm_gpio_is_valid(&host->cd_gpio)) { - if (dm_gpio_get_value(&host->cd_gpio)) + ret = dm_gpio_get_value(&host->cd_gpio); + if (ret) { + debug("no SD card detected (%d)\n", ret); return -ENODEV; + } - err = exynos_pinmux_config(dev_id, flag); - if (err) { + ret = exynos_pinmux_config(dev_id, flag); + if (ret) { printf("external SD not configured\n"); - return err; + return ret; } } -- cgit v1.3.1