diff mbox

[v2,3/3] spi: dw: fix memory leak on error path

Message ID 595523d657a57cc4103553b062c505dc0cff4649.1388427564.git.baruch@tkos.co.il (mailing list archive)
State Accepted
Commit 43f627ac9de42607b2cdcc7a41f2bcc82187e06a
Headers show

Commit Message

Baruch Siach Dec. 30, 2013, 6:30 p.m. UTC
Cc: Feng Tang <feng.tang@intel.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
v2:
    Use managed resources to fix the leak
---
 drivers/spi/spi-dw.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 48ec161..bf98d63 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -619,9 +619,11 @@  static int dw_spi_setup(struct spi_device *spi)
 	/* Only alloc on first setup */
 	chip = spi_get_ctldata(spi);
 	if (!chip) {
-		chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
+		chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data),
+				GFP_KERNEL);
 		if (!chip)
 			return -ENOMEM;
+		spi_set_ctldata(spi, chip);
 	}
 
 	/*
@@ -666,7 +668,6 @@  static int dw_spi_setup(struct spi_device *spi)
 			| (spi->mode  << SPI_MODE_OFFSET)
 			| (chip->tmode << SPI_TMOD_OFFSET);
 
-	spi_set_ctldata(spi, chip);
 	return 0;
 }