spi: fsl-dspi: Fix memory leak

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>
Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
Axel Lin 2014-03-25 09:19:05 +08:00 committed by Mark Brown
parent ba811addff
commit 0e0cd9ea89

View File

@ -342,7 +342,8 @@ 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 = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL); chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data),
GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; 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; fmsz = spi->bits_per_word - 1;
} else { } else {
pr_err("Invalid wordsize\n"); pr_err("Invalid wordsize\n");
kfree(chip);
return -ENODEV; return -ENODEV;
} }