Commit 37af707c authored by Bhuvanchandra DV's avatar Bhuvanchandra DV Committed by Luis Henriques

spi: spi-fsl-dspi: Remove usage of devm_kzalloc

commit 973fbce6 upstream.

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: default avatarStefan Agner <stefan@agner.ch>
Signed-off-by: default avatarBhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 35806db3
...@@ -342,8 +342,7 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) ...@@ -342,8 +342,7 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
/* Only alloc on first setup */ /* Only alloc on first setup */
chip = spi_get_ctldata(spi); chip = spi_get_ctldata(spi);
if (chip == NULL) { if (chip == NULL) {
chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data), chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
} }
...@@ -382,6 +381,16 @@ static int dspi_setup(struct spi_device *spi) ...@@ -382,6 +381,16 @@ static int dspi_setup(struct spi_device *spi)
return dspi_setup_transfer(spi, NULL); return dspi_setup_transfer(spi, NULL);
} }
static void dspi_cleanup(struct spi_device *spi)
{
struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n",
spi->master->bus_num, spi->chip_select);
kfree(chip);
}
static irqreturn_t dspi_interrupt(int irq, void *dev_id) static irqreturn_t dspi_interrupt(int irq, void *dev_id)
{ {
struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id;
...@@ -467,6 +476,7 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -467,6 +476,7 @@ static int dspi_probe(struct platform_device *pdev)
dspi->bitbang.master->setup = dspi_setup; dspi->bitbang.master->setup = dspi_setup;
dspi->bitbang.master->dev.of_node = pdev->dev.of_node; dspi->bitbang.master->dev.of_node = pdev->dev.of_node;
master->cleanup = dspi_cleanup;
master->mode_bits = SPI_CPOL | SPI_CPHA; master->mode_bits = SPI_CPOL | SPI_CPHA;
master->bits_per_word_mask = SPI_BPW_MASK(4) | SPI_BPW_MASK(8) | master->bits_per_word_mask = SPI_BPW_MASK(4) | SPI_BPW_MASK(8) |
SPI_BPW_MASK(16); SPI_BPW_MASK(16);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment