Message ID | 1422722005-1616-1-git-send-email-bhuvanchandra.dv@toradex.com (mailing list archive) |
---|---|
State | Accepted |
Commit | ceadfd8de067e37d52e2af6bb60016cb90342fe8 |
Headers | show |
On Sat, Jan 31, 2015 at 10:03:25PM +0530, Bhuvanchandra DV wrote: > Move the check for spi->bits_per_word > before allocation, to avoid memory leak. > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Normally, you would give me a Reported-by: tag. Not a big deal either way. > Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sat, Jan 31, 2015 at 07:46:48PM +0300, Dan Carpenter wrote: > On Sat, Jan 31, 2015 at 10:03:25PM +0530, Bhuvanchandra DV wrote: > > Move the check for spi->bits_per_word > > before allocation, to avoid memory leak. > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> > Normally, you would give me a Reported-by: tag. Not a big deal either > way. It is a big deal - the Signed-off-by involves all the stuff in SubmittingPatches which means that you really shouldn't add a signoff for anyone who didn't supply one. I've changed to a Reported-by and applied, please be more careful with this in future Bhuvanchandra.
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 4cda994..604b6d3 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -339,6 +339,13 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 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) { @@ -350,12 +357,6 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 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;