diff mbox

[U-Boot,1/2] spi: fix mxc_spi_slave structure allocation to clear memory

Message ID 1345227311-11433-1-git-send-email-matt@genesi-usa.com
State Accepted
Commit 784097ae5a88f3f0b9aeab589e22091c3bf0f846
Delegated to: Stefano Babic
Headers show

Commit Message

Matt Sealey Aug. 17, 2012, 6:15 p.m. UTC
Use calloc() instead of malloc() to allocate the mxc_spi_slave structure.
Clearing the memory is necessary since most of the time this gets done
super early in boot, but on warm reboots, and when SPI probing is done
long after the init stages it could actually pick up previously used memory,
and things like the chipselect polarity and other data end up being filled
with trash data if not explicitly set by the board files.

This solves a semi-random, almost unreproducable error whereby SPI devices
act very, very strangly on boot. Tested on Efika MX over several years..

Signed-off-by: Matt Sealey <matt@genesi-usa.com>
---
 drivers/spi/mxc_spi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Babic Aug. 18, 2012, 9:05 a.m. UTC | #1
Am 17/08/2012 20:15, schrieb Matt Sealey:
> Use calloc() instead of malloc() to allocate the mxc_spi_slave structure.
> Clearing the memory is necessary since most of the time this gets done
> super early in boot, but on warm reboots, and when SPI probing is done
> long after the init stages it could actually pick up previously used memory,
> and things like the chipselect polarity and other data end up being filled
> with trash data if not explicitly set by the board files.
> 
> This solves a semi-random, almost unreproducable error whereby SPI devices
> act very, very strangly on boot. Tested on Efika MX over several years..
> 
> Signed-off-by: Matt Sealey <matt@genesi-usa.com>
> ---
>  drivers/spi/mxc_spi.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
> index 2e15318..d1dab18 100644
> --- a/drivers/spi/mxc_spi.c
> +++ b/drivers/spi/mxc_spi.c
> @@ -408,7 +408,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>  	if (bus >= ARRAY_SIZE(spi_bases))
>  		return NULL;
>  
> -	mxcs = malloc(sizeof(struct mxc_spi_slave));
> +	mxcs = calloc(sizeof(struct mxc_spi_slave), 1);
>  	if (!mxcs) {
>  		puts("mxc_spi: SPI Slave not allocated !\n");
>  		return NULL;
> 

Agree, the structure must be zeroed.

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
Stefano Babic Aug. 20, 2012, 7:59 a.m. UTC | #2
On 17/08/2012 20:15, Matt Sealey wrote:
> Use calloc() instead of malloc() to allocate the mxc_spi_slave structure.
> Clearing the memory is necessary since most of the time this gets done
> super early in boot, but on warm reboots, and when SPI probing is done
> long after the init stages it could actually pick up previously used memory,
> and things like the chipselect polarity and other data end up being filled
> with trash data if not explicitly set by the board files.
> 
> This solves a semi-random, almost unreproducable error whereby SPI devices
> act very, very strangly on boot. Tested on Efika MX over several years..
> 
> Signed-off-by: Matt Sealey <matt@genesi-usa.com>
> ---
>  drivers/spi/mxc_spi.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
> index 2e15318..d1dab18 100644
> --- a/drivers/spi/mxc_spi.c
> +++ b/drivers/spi/mxc_spi.c
> @@ -408,7 +408,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>  	if (bus >= ARRAY_SIZE(spi_bases))
>  		return NULL;
>  
> -	mxcs = malloc(sizeof(struct mxc_spi_slave));
> +	mxcs = calloc(sizeof(struct mxc_spi_slave), 1);
>  	if (!mxcs) {
>  		puts("mxc_spi: SPI Slave not allocated !\n");
>  		return NULL;
> 
Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic
diff mbox

Patch

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index 2e15318..d1dab18 100644
--- a/drivers/spi/mxc_spi.c
+++ b/drivers/spi/mxc_spi.c
@@ -408,7 +408,7 @@  struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	if (bus >= ARRAY_SIZE(spi_bases))
 		return NULL;
 
-	mxcs = malloc(sizeof(struct mxc_spi_slave));
+	mxcs = calloc(sizeof(struct mxc_spi_slave), 1);
 	if (!mxcs) {
 		puts("mxc_spi: SPI Slave not allocated !\n");
 		return NULL;