lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1422722005-1616-1-git-send-email-bhuvanchandra.dv@toradex.com>
Date:	Sat, 31 Jan 2015 22:03:25 +0530
From:	Bhuvanchandra DV <bhuvanchandra.dv@...adex.com>
To:	<broonie@...nel.org>
CC:	<stefan@...er.ch>, <dan.carpenter@...cle.com>,
	<linux-spi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
	Bhuvanchandra DV <bhuvanchandra.dv@...adex.com>
Subject: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'

Move the check for spi->bits_per_word
before allocation, to avoid memory leak.

Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@...adex.com>
---
 drivers/spi/spi-fsl-dspi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

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;
 
-- 
2.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ