Patchwork [U-Boot] mmc: fsl_esdhc: Check the result from malloc()

login
register
mail settings
Submitter Fabio Estevam
Date Sept. 12, 2013, 1:35 p.m.
Message ID <1378992953-8294-1-git-send-email-fabio.estevam@freescale.com>
Download mbox | patch
Permalink /patch/274556/
State Awaiting Upstream
Delegated to: Stefano Babic
Headers show

Comments

Fabio Estevam - Sept. 12, 2013, 1:35 p.m.
malloc can fail, so we should better check its return value before using it.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/mmc/fsl_esdhc.c | 2 ++
 1 file changed, 2 insertions(+)
Stefano Babic - Sept. 20, 2013, 4:04 p.m.
On 12/09/2013 15:35, Fabio Estevam wrote:
> malloc can fail, so we should better check its return value before using it.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---


Applied to u-boot-imx, thanks!

Best regards,
Stefano Babic

Patch

diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index f87e647..a7170b4 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -518,6 +518,8 @@  int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 		return -1;
 
 	mmc = malloc(sizeof(struct mmc));
+	if (!mmc)
+		return -ENOMEM;
 
 	sprintf(mmc->name, "FSL_SDHC");
 	regs = (struct fsl_esdhc *)cfg->esdhc_base;