All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
@ 2015-01-31 16:33 ` Bhuvanchandra DV
  0 siblings, 0 replies; 6+ messages in thread
From: Bhuvanchandra DV @ 2015-01-31 16:33 UTC (permalink / raw)
  To: broonie; +Cc: stefan, dan.carpenter, linux-spi, linux-kernel, Bhuvanchandra DV

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

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
@ 2015-01-31 16:33 ` Bhuvanchandra DV
  0 siblings, 0 replies; 6+ messages in thread
From: Bhuvanchandra DV @ 2015-01-31 16:33 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A
  Cc: stefan-XLVq0VzYD2Y, dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA,
	linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Bhuvanchandra DV

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

Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>
---
 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-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
@ 2015-01-31 16:46   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2015-01-31 16:46 UTC (permalink / raw)
  To: Bhuvanchandra DV; +Cc: broonie, stefan, linux-spi, linux-kernel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
@ 2015-01-31 16:46   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2015-01-31 16:46 UTC (permalink / raw)
  To: Bhuvanchandra DV
  Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A, stefan-XLVq0VzYD2Y,
	linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

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-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>

Normally, you would give me a Reported-by: tag.  Not a big deal either
way.

> Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv-2KBjVHiyJgBBDgjK7y7TUQ@public.gmane.org>

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
  2015-01-31 16:46   ` Dan Carpenter
@ 2015-02-02 20:23     ` Mark Brown
  -1 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2015-02-02 20:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Bhuvanchandra DV, stefan, linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

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.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
@ 2015-02-02 20:23     ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2015-02-02 20:23 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Bhuvanchandra DV, stefan-XLVq0VzYD2Y,
	linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

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-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>

> 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.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-02-02 20:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-31 16:33 [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip' Bhuvanchandra DV
2015-01-31 16:33 ` Bhuvanchandra DV
2015-01-31 16:46 ` Dan Carpenter
2015-01-31 16:46   ` Dan Carpenter
2015-02-02 20:23   ` Mark Brown
2015-02-02 20:23     ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.