diff options
| author | Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> | 2015-01-27 05:57:20 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2015-01-27 14:52:02 -0500 |
| commit | 973fbce69ed8e79b5fe3ad19cfecb581a7ef8048 (patch) | |
| tree | be3d6b0e06947571d65441c03ba20b56f6ab4e80 | |
| parent | 97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff) | |
spi: spi-fsl-dspi: Remove usage of devm_kzalloc
devm_* API was supposed to be used only in probe function call.
Memory is allocated at 'probe' and free automatically at 'remove'.
Usage of devm_* functions outside probe sometimes leads to memory leak.
Avoid using devm_kzalloc in dspi_setup_transfer and use kzalloc instead.
Also add the dspi_cleanup function to free the controller data upon
cleanup.
Acked-by: Stefan Agner <stefan@agner.ch>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
| -rw-r--r-- | drivers/spi/spi-fsl-dspi.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 4cda994d3f40..9b80d54d4ddb 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c | |||
| @@ -342,8 +342,7 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
| 342 | /* Only alloc on first setup */ | 342 | /* Only alloc on first setup */ |
| 343 | chip = spi_get_ctldata(spi); | 343 | chip = spi_get_ctldata(spi); |
| 344 | if (chip == NULL) { | 344 | if (chip == NULL) { |
| 345 | chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data), | 345 | chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); |
| 346 | GFP_KERNEL); | ||
| 347 | if (!chip) | 346 | if (!chip) |
| 348 | return -ENOMEM; | 347 | return -ENOMEM; |
| 349 | } | 348 | } |
| @@ -382,6 +381,16 @@ static int dspi_setup(struct spi_device *spi) | |||
| 382 | return dspi_setup_transfer(spi, NULL); | 381 | return dspi_setup_transfer(spi, NULL); |
| 383 | } | 382 | } |
| 384 | 383 | ||
| 384 | static void dspi_cleanup(struct spi_device *spi) | ||
| 385 | { | ||
| 386 | struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); | ||
| 387 | |||
| 388 | dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n", | ||
| 389 | spi->master->bus_num, spi->chip_select); | ||
| 390 | |||
| 391 | kfree(chip); | ||
| 392 | } | ||
| 393 | |||
| 385 | static irqreturn_t dspi_interrupt(int irq, void *dev_id) | 394 | static irqreturn_t dspi_interrupt(int irq, void *dev_id) |
| 386 | { | 395 | { |
| 387 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; | 396 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; |
| @@ -467,6 +476,7 @@ static int dspi_probe(struct platform_device *pdev) | |||
| 467 | dspi->bitbang.master->setup = dspi_setup; | 476 | dspi->bitbang.master->setup = dspi_setup; |
| 468 | dspi->bitbang.master->dev.of_node = pdev->dev.of_node; | 477 | dspi->bitbang.master->dev.of_node = pdev->dev.of_node; |
| 469 | 478 | ||
| 479 | master->cleanup = dspi_cleanup; | ||
| 470 | master->mode_bits = SPI_CPOL | SPI_CPHA; | 480 | master->mode_bits = SPI_CPOL | SPI_CPHA; |
| 471 | master->bits_per_word_mask = SPI_BPW_MASK(4) | SPI_BPW_MASK(8) | | 481 | master->bits_per_word_mask = SPI_BPW_MASK(4) | SPI_BPW_MASK(8) | |
| 472 | SPI_BPW_MASK(16); | 482 | SPI_BPW_MASK(16); |
