Patchwork [U-Boot,v2] mmc: fsl_esdhc: Use calloc()

login
register
mail settings
Submitter Fabio Estevam
Date Dec. 27, 2012, 6:51 p.m.
Message ID <1356634268-16297-1-git-send-email-festevam@gmail.com>
Download mbox | patch
Permalink /patch/208352/
State Accepted, archived
Delegated to: Andy Fleming
Headers show

Comments

Fabio Estevam - Dec. 27, 2012, 6:51 p.m.
From: Fabio Estevam <fabio.estevam@freescale.com>

A malloc() followed by memset() can be simply replaced by calloc().

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Change since v1:
- Fix commit log
 drivers/mmc/fsl_esdhc.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Jeroen Hofstee - Dec. 27, 2012, 9:53 p.m.
On 12/27/2012 07:51 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
>
> A malloc() followed by memset() can be simply replaced by calloc().
>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
> Change since v1:
> - Fix commit log
>   drivers/mmc/fsl_esdhc.c |    3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
> index e93e38a..5fc1c36 100644
> --- a/drivers/mmc/fsl_esdhc.c
> +++ b/drivers/mmc/fsl_esdhc.c
> @@ -595,8 +595,7 @@ int fsl_esdhc_mmc_init(bd_t *bis)
>   {
>   	struct fsl_esdhc_cfg *cfg;
>   
> -	cfg = malloc(sizeof(struct fsl_esdhc_cfg));
> -	memset(cfg, 0, sizeof(struct fsl_esdhc_cfg));
> +	cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
>   	cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
>   	cfg->sdhc_clk = gd->sdhc_clk;
>   	return fsl_esdhc_initialize(bis, cfg);
nitpicking: if you're cleaning up, why not swap the arguments to calloc ;)

Regards,
Jeroen

Patch

diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index e93e38a..5fc1c36 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -595,8 +595,7 @@  int fsl_esdhc_mmc_init(bd_t *bis)
 {
 	struct fsl_esdhc_cfg *cfg;
 
-	cfg = malloc(sizeof(struct fsl_esdhc_cfg));
-	memset(cfg, 0, sizeof(struct fsl_esdhc_cfg));
+	cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
 	cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
 	cfg->sdhc_clk = gd->sdhc_clk;
 	return fsl_esdhc_initialize(bis, cfg);