From: Baruch Siach Date: Mon, 30 Dec 2013 18:30:46 +0000 (+0200) Subject: spi: dw: fix memory leak on error path X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=43f627ac9de42;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git spi: dw: fix memory leak on error path Signed-off-by: Baruch Siach Signed-off-by: Mark Brown --- diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 48ec161d6eed..bf98d63d92b3 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -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; }