spi/omap2_mcspi: fix NULL pointer dereference
authorScott Ellis <scott@jumpnowtek.com>
Wed, 10 Mar 2010 21:22:45 +0000 (14:22 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Wed, 10 Mar 2010 21:22:45 +0000 (14:22 -0700)
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.

Signed-off-by: Scott Ellis <scott@jumpnowtek.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
drivers/spi/omap2_mcspi.c

index 715c518b1b68f78d820145a13e652f22d4d51dea..87d44eeaaa7bd653e712016c3c40259c968432db 100644 (file)
@@ -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);