diff options
author | Lukasz Majewski <lukma@denx.de> | 2018-08-01 14:48:53 +0200 |
---|---|---|
committer | Minkyu Kang <mk7.kang@samsung.com> | 2018-08-06 10:53:53 +0900 |
commit | b88c1efadbf061c2e2b0bf80738892fc7559094e (patch) | |
tree | cfedf54f5a0c287ac27076cb7178099c217aa626 /drivers | |
parent | d06ac6034d798a339c58246d81763a074f742835 (diff) | |
download | u-boot-b88c1efadbf061c2e2b0bf80738892fc7559094e.zip u-boot-b88c1efadbf061c2e2b0bf80738892fc7559094e.tar.gz u-boot-b88c1efadbf061c2e2b0bf80738892fc7559094e.tar.bz2 |
ARM: dw_mmc: Exclude dwmci Exynos priv_data allocation from exynos_dwmci_get_config()
This commit prevents memory leak when this function is used with DM_MMC
as the struct dwmci_exynos_priv_data is already allocated by DM.
It is necessary for NON DM aware devices to allocate this struct first.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Anand Moon <linux.amoon@gmail.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mmc/exynos_dw_mmc.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index 865fdf4..49c4f76 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -146,17 +146,11 @@ static int do_dwmci_init(struct dwmci_host *host) } static int exynos_dwmci_get_config(const void *blob, int node, - struct dwmci_host *host) + struct dwmci_host *host, + struct dwmci_exynos_priv_data *priv) { int err = 0; u32 base, timing[3]; - struct dwmci_exynos_priv_data *priv; - - priv = malloc(sizeof(struct dwmci_exynos_priv_data)); - if (!priv) { - pr_err("dwmci_exynos_priv_data malloc fail!\n"); - return -ENOMEM; - } /* Extract device id for each mmc channel */ host->dev_id = pinmux_decode_periph_id(blob, node); @@ -167,7 +161,6 @@ static int exynos_dwmci_get_config(const void *blob, int node, if (host->dev_index > 4) { printf("DWMMC%d: Can't get the dev index\n", host->dev_index); - free(priv); return -EINVAL; } @@ -178,7 +171,6 @@ static int exynos_dwmci_get_config(const void *blob, int node, base = fdtdec_get_addr(blob, node, "reg"); if (!base) { printf("DWMMC%d: Can't get base address\n", host->dev_index); - free(priv); return -EINVAL; } host->ioaddr = (void *)base; @@ -188,7 +180,6 @@ static int exynos_dwmci_get_config(const void *blob, int node, if (err) { printf("DWMMC%d: Can't get sdr-timings for devider\n", host->dev_index); - free(priv); return -EINVAL; } @@ -208,14 +199,13 @@ static int exynos_dwmci_get_config(const void *blob, int node, host->bus_hz = fdtdec_get_int(blob, node, "bus_hz", 0); host->div = fdtdec_get_int(blob, node, "div", 0); - host->priv = priv; - return 0; } static int exynos_dwmci_process_node(const void *blob, int node_list[], int count) { + struct dwmci_exynos_priv_data *priv; struct dwmci_host *host; int i, node, err; @@ -224,11 +214,20 @@ static int exynos_dwmci_process_node(const void *blob, if (node <= 0) continue; host = &dwmci_host[i]; - err = exynos_dwmci_get_config(blob, node, host); + + priv = malloc(sizeof(struct dwmci_exynos_priv_data)); + if (!priv) { + pr_err("dwmci_exynos_priv_data malloc fail!\n"); + return -ENOMEM; + } + + err = exynos_dwmci_get_config(blob, node, host, priv); if (err) { printf("%s: failed to decode dev %d\n", __func__, i); + free(priv); return err; } + host->priv = priv; do_dwmci_init(host); } @@ -266,7 +265,8 @@ static int exynos_dwmmc_probe(struct udevice *dev) struct dwmci_host *host = &priv->host; int err; - err = exynos_dwmci_get_config(gd->fdt_blob, dev_of_offset(dev), host); + err = exynos_dwmci_get_config(gd->fdt_blob, dev_of_offset(dev), host, + priv); if (err) return err; err = do_dwmci_init(host); |