Skip to content

Commit

Permalink
spi: fsl-dspi: Remove possible memory leak of 'chip'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bhuvanchandra DV authored and Mark Brown committed Feb 2, 2015
1 parent 9298bc7 commit ceadfd8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/spi/spi-fsl-dspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ static int dspi_setup(struct spi_device *spi)
struct fsl_dspi *dspi = spi_master_get_devdata(spi->master);
unsigned char br = 0, pbr = 0, fmsz = 0;

if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) {
fmsz = spi->bits_per_word - 1;
} else {
pr_err("Invalid wordsize\n");
return -ENODEV;
}

/* Only alloc on first setup */
chip = spi_get_ctldata(spi);
if (chip == NULL) {
Expand All @@ -357,12 +364,6 @@ static int dspi_setup(struct spi_device *spi)

chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS |
SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF;
if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) {
fmsz = spi->bits_per_word - 1;
} else {
pr_err("Invalid wordsize\n");
return -ENODEV;
}

chip->void_write_data = 0;

Expand Down

0 comments on commit ceadfd8

Please sign in to comment.