spi: dw: fix memory leak on error path
authorBaruch Siach <baruch@tkos.co.il>
Mon, 30 Dec 2013 18:30:46 +0000 (20:30 +0200)
committerMark Brown <broonie@linaro.org>
Tue, 31 Dec 2013 12:30:25 +0000 (12:30 +0000)
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/spi/spi-dw.c

index 48ec161d6eede3c91bd0d9b6bf4da9ca0da5fb64..bf98d63d92b3eabbd80ea49d125421069139c535 100644 (file)
@@ -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;
 }