From: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
To: <broonie@kernel.org>
Cc: <stefan@agner.ch>, <dan.carpenter@oracle.com>,
<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Subject: [PATCH] spi: fsl-dspi: Remove possible memory leak of 'chip'
Date: Sat, 31 Jan 2015 22:03:25 +0530 [thread overview]
Message-ID: <1422722005-1616-1-git-send-email-bhuvanchandra.dv@toradex.com> (raw)
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
next reply other threads:[~2015-01-31 16:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-31 16:33 Bhuvanchandra DV [this message]
2015-01-31 16:46 ` Dan Carpenter
2015-02-02 20:23 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1422722005-1616-1-git-send-email-bhuvanchandra.dv@toradex.com \
--to=bhuvanchandra.dv@toradex.com \
--cc=broonie@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stefan@agner.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®