Skip to contentSkip to conversation

omap2_mcspi.c: NULL pointer dereference

PATCH In review Scott Ellis 2 participants 2 messages Feb 23, 2010 – Feb 25, 2010 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 omap2_mcspi.c: NULL pointer dereference

Check spi->controller_state before dereferencing.

Shows up NULL here when using spi_alloc_device()/spi_add_device() and spi_add_device() fails before spi_setup(). Calling spi_dev_put() on the leftover spi_device results in the error.

 drivers/spi/omap2_mcspi.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/spi/omap2_mcspi.c +6 -4
index ba1a872..b1f82c1 100644
@@ -751,11 +751,13 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)
 	mcspi = spi_master_get_devdata(spi->master);
 	mcspi_dma = &mcspi->dma_channels[spi->chip_select];
 
-	/* Unlink controller state from context save list */
-	cs = spi->controller_state;
-	list_del(&cs->node);
+	if (spi->controller_state) {
+		/* Unlink controller state from context save list */
+		cs = spi->controller_state;
+		list_del(&cs->node);
 
-	kfree(spi->controller_state);
+		kfree(spi->controller_state);
+	}
 
 	if (mcspi_dma->dma_rx_channel != -1) {
 		omap_free_dma(mcspi_dma->dma_rx_channel);
#1 lore raw
Quoted 5 lines · Scott Ellis

Check spi->controller_state before dereferencing.

Shows up NULL here when using spi_alloc_device()/spi_add_device() and spi_add_device() fails before spi_setup(). Calling spi_dev_put() on the leftover spi_device results in the error.

This should go to the linux-omap mailing list.

Signature · 1 line
Felipe Contreras