spi: fsl-dspi: Fix memory leak
authorAxel Lin <axel.lin@ingics.com>
Tue, 25 Mar 2014 01:19:05 +0000 (09:19 +0800)
committerMark Brown <broonie@linaro.org>
Fri, 28 Mar 2014 11:47:43 +0000 (11:47 +0000)
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>
drivers/spi/spi-fsl-dspi.c

index 7f0dddb21833e95fac93e4378b302c6261e80f49..c5ecfc1240ab8619159d64b3c802225326b4cec2 100644 (file)
@@ -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;
        }