diff mbox

[U-Boot,1/1] mmc: bcm2835_sdhci: Use calloc to allocate bcm2835_sdhci_host

Message ID 1429284797-8433-1-git-send-email-alexanders83@web.de
State Accepted
Delegated to: Pantelis Antoniou
Headers show

Commit Message

Alexander Stein April 17, 2015, 3:33 p.m. UTC
We need to clear the allocated memory explicitly as the included
struct sdhci_host has function pointers. Those are compared to NULL to
test if this (optional) feature is supported. Leaving them undefined let
u-boot jump to arbitrary memory.

Signed-off-by: Alexander Stein <alexanders83@web.de>
---
 drivers/mmc/bcm2835_sdhci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Alexander Stein May 3, 2015, 2:51 p.m. UTC | #1
Any feedback on this?

Best regards,
Alexander

On Friday 17 April 2015, 17:33:17 wrote Alexander Stein:
> We need to clear the allocated memory explicitly as the included
> struct sdhci_host has function pointers. Those are compared to NULL to
> test if this (optional) feature is supported. Leaving them undefined let
> u-boot jump to arbitrary memory.
> 
> Signed-off-by: Alexander Stein <alexanders83@web.de>
> ---
>  drivers/mmc/bcm2835_sdhci.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/bcm2835_sdhci.c b/drivers/mmc/bcm2835_sdhci.c
> index 92f7d89..127dbe3 100644
> --- a/drivers/mmc/bcm2835_sdhci.c
> +++ b/drivers/mmc/bcm2835_sdhci.c
> @@ -154,9 +154,9 @@ int bcm2835_sdhci_init(u32 regbase, u32 emmc_freq)
>  	struct bcm2835_sdhci_host *bcm_host;
>  	struct sdhci_host *host;
>  
> -	bcm_host = malloc(sizeof(*bcm_host));
> +	bcm_host = calloc(1, sizeof(*bcm_host));
>  	if (!bcm_host) {
> -		printf("sdhci_host malloc fail!\n");
> +		printf("sdhci_host calloc fail!\n");
>  		return 1;
>  	}
>  
>
Pantelis Antoniou May 5, 2015, 9:38 a.m. UTC | #2
Hi Alexander,

> On Apr 17, 2015, at 18:33 , Alexander Stein <alexanders83@web.de> wrote:
> 
> We need to clear the allocated memory explicitly as the included
> struct sdhci_host has function pointers. Those are compared to NULL to
> test if this (optional) feature is supported. Leaving them undefined let
> u-boot jump to arbitrary memory.
> 
> Signed-off-by: Alexander Stein <alexanders83@web.de>
> ---
> drivers/mmc/bcm2835_sdhci.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/bcm2835_sdhci.c b/drivers/mmc/bcm2835_sdhci.c
> index 92f7d89..127dbe3 100644
> --- a/drivers/mmc/bcm2835_sdhci.c
> +++ b/drivers/mmc/bcm2835_sdhci.c
> @@ -154,9 +154,9 @@ int bcm2835_sdhci_init(u32 regbase, u32 emmc_freq)
> 	struct bcm2835_sdhci_host *bcm_host;
> 	struct sdhci_host *host;
> 
> -	bcm_host = malloc(sizeof(*bcm_host));
> +	bcm_host = calloc(1, sizeof(*bcm_host));
> 	if (!bcm_host) {
> -		printf("sdhci_host malloc fail!\n");
> +		printf("sdhci_host calloc fail!\n");
> 		return 1;
> 	}
> 
> -- 
> 2.3.5
> 

Applied, Thanks.

— Pantelis
diff mbox

Patch

diff --git a/drivers/mmc/bcm2835_sdhci.c b/drivers/mmc/bcm2835_sdhci.c
index 92f7d89..127dbe3 100644
--- a/drivers/mmc/bcm2835_sdhci.c
+++ b/drivers/mmc/bcm2835_sdhci.c
@@ -154,9 +154,9 @@  int bcm2835_sdhci_init(u32 regbase, u32 emmc_freq)
 	struct bcm2835_sdhci_host *bcm_host;
 	struct sdhci_host *host;
 
-	bcm_host = malloc(sizeof(*bcm_host));
+	bcm_host = calloc(1, sizeof(*bcm_host));
 	if (!bcm_host) {
-		printf("sdhci_host malloc fail!\n");
+		printf("sdhci_host calloc fail!\n");
 		return 1;
 	}