Message ID | 1345227311-11433-2-git-send-email-matt@genesi-usa.com |
---|---|
State | Accepted |
Commit | c6b52c4927df227c94650122363b8b342ddb62f0 |
Delegated to: | Stefano Babic |
Headers | show |
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
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
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;
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(-)