From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 1/9] ARM: dw_mmc: Exclude dwmci Exynos priv_data allocation from exynos_dwmci_get_config()
Date: Thu, 26 Jul 2018 00:25:44 +0200 [thread overview]
Message-ID: <20180725222552.3450-2-lukma@denx.de> (raw)
In-Reply-To: <20180725222552.3450-1-lukma@denx.de>
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>
---
drivers/mmc/exynos_dw_mmc.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c
index 865fdf4dbba0..49c4f7634830 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);
--
2.11.0
next prev parent reply other threads:[~2018-07-25 22:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-25 22:25 [U-Boot] [PATCH v1 0/9] ARM: Odroid XU3: Enable DM_MMC support which is necessary for CONFIG_BLK Lukasz Majewski
2018-07-25 22:25 ` Lukasz Majewski [this message]
2018-07-27 3:06 ` [U-Boot] [PATCH v1 1/9] ARM: dw_mmc: Exclude dwmci Exynos priv_data allocation from exynos_dwmci_get_config() Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 2/9] ARM: Odroid XU3: config: Disable SDHCI support in the Odroid XU3 Lukasz Majewski
2018-07-27 3:07 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 3/9] ARM: Odroid XU3: Enable driver model support for MMC (DM_MMC) Lukasz Majewski
2018-07-27 3:07 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 4/9] ARM: Odroid XU3: Fix autoboot.cmd to use ${mmcbootdev} instead of hardcoded 0 Lukasz Majewski
2018-07-27 3:09 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 5/9] ARM: Odroid XU3: Adjust BOOT_TARGET_DEVICES to allow booting from SD card (mmc2) Lukasz Majewski
2018-07-27 3:10 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 6/9] ARM: Odroid XU3: MAINTAINERS: Add a co-maintainer for OdroidXU3 Lukasz Majewski
2018-07-25 22:25 ` [U-Boot] [PATCH v1 7/9] ARM: Odroid XU3: Fix the dwmci_exynos *priv data assignment for DM_MMC (sdr_timing) Lukasz Majewski
2018-07-27 3:12 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 8/9] ARM: Odroid XU3: Modify exynos dw_mmc driver to support Odroid XU3 in DM MMC Lukasz Majewski
2018-07-27 3:13 ` Anand Moon
2018-07-25 22:25 ` [U-Boot] [PATCH v1 9/9] ARM: Odroid XU3: Modify Odroid XU3 config to boot by default from SD card Lukasz Majewski
2018-07-26 15:28 ` Anand Moon
2018-07-26 15:53 ` Lukasz Majewski
2018-07-27 3:04 ` Anand Moon
2018-07-27 8:24 ` Lukasz Majewski
2018-07-27 9:12 ` Anand Moon
2018-07-27 9:56 ` Lukasz Majewski
2018-07-31 18:10 ` Anand Moon
2018-08-01 7:51 ` Lukasz Majewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180725222552.3450-2-lukma@denx.de \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox