diff mbox

spi: fsl-dspi: Fix memory leak

Message ID 1395710345.29281.1.camel@phoenix (mailing list archive)
State Accepted
Commit 0e0cd9ea8961b82947a40471080e7968b634820e
Headers show

Commit Message

Axel Lin March 25, 2014, 1:19 a.m. UTC
The memory allocated for chip is not freed anywhere.
Convert to use devm_kzalloc to fix the memory leak.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/spi/spi-fsl-dspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mark Brown March 28, 2014, 11:47 a.m. UTC | #1
On Tue, Mar 25, 2014 at 09:19:05AM +0800, Axel Lin wrote:
> The memory allocated for chip is not freed anywhere.
> Convert to use devm_kzalloc to fix the memory leak.

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 2249cb7..d565eee 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -342,7 +342,8 @@  static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 	/* Only alloc on first setup */
 	chip = spi_get_ctldata(spi);
 	if (chip == NULL) {
-		chip = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL);
+		chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data),
+				    GFP_KERNEL);
 		if (!chip)
 			return -ENOMEM;
 	}
@@ -353,7 +354,6 @@  static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 		fmsz = spi->bits_per_word - 1;
 	} else {
 		pr_err("Invalid wordsize\n");
-		kfree(chip);
 		return -ENODEV;
 	}