From ceadfd8de067e37d52e2af6bb60016cb90342fe8 Mon Sep 17 00:00:00 2001 From: Bhuvanchandra DV Date: Sat, 31 Jan 2015 22:03:25 +0530 Subject: 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 Signed-off-by: Bhuvanchandra DV Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-dspi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'drivers/spi/spi-fsl-dspi.c') 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) 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) { @@ -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; -- cgit v1.2.3