public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory
@ 2012-08-17 18:15 Matt Sealey
  2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Matt Sealey @ 2012-08-17 18:15 UTC (permalink / raw)
  To: u-boot

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;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave structure allocation to clear memory
  2012-08-17 18:15 [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory Matt Sealey
@ 2012-08-17 18:15 ` Matt Sealey
  2012-08-18  9:05   ` stefano babic
  2012-08-20  7:59   ` Stefano Babic
  2012-08-18  9:05 ` [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave " stefano babic
  2012-08-20  7:59 ` Stefano Babic
  2 siblings, 2 replies; 6+ messages in thread
From: Matt Sealey @ 2012-08-17 18:15 UTC (permalink / raw)
  To: u-boot

Use calloc() instead of malloc() to allocate the mxs_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.

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

diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index a037c13..5fa7f2b 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -91,7 +91,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 		return NULL;
 	}
 
-	mxs_slave = malloc(sizeof(struct mxs_spi_slave));
+	mxs_slave = calloc(sizeof(struct mxs_spi_slave), 1);
 	if (!mxs_slave)
 		return NULL;
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave structure allocation to clear memory
  2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
@ 2012-08-18  9:05   ` stefano babic
  2012-08-20  7:59   ` Stefano Babic
  1 sibling, 0 replies; 6+ messages in thread
From: stefano babic @ 2012-08-18  9:05 UTC (permalink / raw)
  To: u-boot

Am 17/08/2012 20:15, schrieb Matt Sealey:
> Use calloc() instead of malloc() to allocate the mxs_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.
> 
> Signed-off-by: Matt Sealey <matt@genesi-usa.com>
> ---
>  drivers/spi/mxs_spi.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
> index a037c13..5fa7f2b 100644
> --- a/drivers/spi/mxs_spi.c
> +++ b/drivers/spi/mxs_spi.c
> @@ -91,7 +91,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>  		return NULL;
>  	}
>  
> -	mxs_slave = malloc(sizeof(struct mxs_spi_slave));
> +	mxs_slave = calloc(sizeof(struct mxs_spi_slave), 1);
>  	if (!mxs_slave)
>  		return NULL;
>  
> 


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

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory
  2012-08-17 18:15 [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory Matt Sealey
  2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
@ 2012-08-18  9:05 ` stefano babic
  2012-08-20  7:59 ` Stefano Babic
  2 siblings, 0 replies; 6+ messages in thread
From: stefano babic @ 2012-08-18  9:05 UTC (permalink / raw)
  To: u-boot

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


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory
  2012-08-17 18:15 [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory Matt Sealey
  2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
  2012-08-18  9:05 ` [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave " stefano babic
@ 2012-08-20  7:59 ` Stefano Babic
  2 siblings, 0 replies; 6+ messages in thread
From: Stefano Babic @ 2012-08-20  7:59 UTC (permalink / raw)
  To: u-boot

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


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave structure allocation to clear memory
  2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
  2012-08-18  9:05   ` stefano babic
@ 2012-08-20  7:59   ` Stefano Babic
  1 sibling, 0 replies; 6+ messages in thread
From: Stefano Babic @ 2012-08-20  7:59 UTC (permalink / raw)
  To: u-boot

On 17/08/2012 20:15, Matt Sealey wrote:
> Use calloc() instead of malloc() to allocate the mxs_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.
> 
> Signed-off-by: Matt Sealey <matt@genesi-usa.com>
> ---
>  drivers/spi/mxs_spi.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
> index a037c13..5fa7f2b 100644
> --- a/drivers/spi/mxs_spi.c
> +++ b/drivers/spi/mxs_spi.c
> @@ -91,7 +91,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>  		return NULL;
>  	}
>  
> -	mxs_slave = malloc(sizeof(struct mxs_spi_slave));
> +	mxs_slave = calloc(sizeof(struct mxs_spi_slave), 1);
>  	if (!mxs_slave)
>  		return NULL;
>  
> 

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic
-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-20  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-17 18:15 [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory Matt Sealey
2012-08-17 18:15 ` [U-Boot] [PATCH 2/2] spi: fix mxs_spi_slave " Matt Sealey
2012-08-18  9:05   ` stefano babic
2012-08-20  7:59   ` Stefano Babic
2012-08-18  9:05 ` [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave " stefano babic
2012-08-20  7:59 ` Stefano Babic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox