diff options
author | Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> | 2015-01-31 11:33:25 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-02-02 15:05:19 -0500 |
commit | ceadfd8de067e37d52e2af6bb60016cb90342fe8 (patch) | |
tree | 1b3a76f797f5425f1ad42eb23f2791f5e785a22f /drivers | |
parent | 9298bc727385cd625cdda5e877bd3cba8acff668 (diff) |
spi: fsl-dspi: Remove possible memory leak of 'chip'
Move the check for spi->bits_per_word
before allocation, to avoid memory leak.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/spi-fsl-dspi.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 2c52c2e185c7..d1a39249704a 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c | |||
@@ -347,6 +347,13 @@ static int dspi_setup(struct spi_device *spi) | |||
347 | struct fsl_dspi *dspi = spi_master_get_devdata(spi->master); | 347 | struct fsl_dspi *dspi = spi_master_get_devdata(spi->master); |
348 | unsigned char br = 0, pbr = 0, fmsz = 0; | 348 | unsigned char br = 0, pbr = 0, fmsz = 0; |
349 | 349 | ||
350 | if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) { | ||
351 | fmsz = spi->bits_per_word - 1; | ||
352 | } else { | ||
353 | pr_err("Invalid wordsize\n"); | ||
354 | return -ENODEV; | ||
355 | } | ||
356 | |||
350 | /* Only alloc on first setup */ | 357 | /* Only alloc on first setup */ |
351 | chip = spi_get_ctldata(spi); | 358 | chip = spi_get_ctldata(spi); |
352 | if (chip == NULL) { | 359 | if (chip == NULL) { |
@@ -357,12 +364,6 @@ static int dspi_setup(struct spi_device *spi) | |||
357 | 364 | ||
358 | chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS | | 365 | chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS | |
359 | SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF; | 366 | SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF; |
360 | if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) { | ||
361 | fmsz = spi->bits_per_word - 1; | ||
362 | } else { | ||
363 | pr_err("Invalid wordsize\n"); | ||
364 | return -ENODEV; | ||
365 | } | ||
366 | 367 | ||
367 | chip->void_write_data = 0; | 368 | chip->void_write_data = 0; |
368 | 369 | ||