Commit 5e7749436d576a525d7b2a4bcffb17b3364b9e00
Committed by
Grant Likely
1 parent
07081fd858
Exists in
master
and in
4 other branches
spi/omap2_mcspi: fix 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. Signed-off-by: Scott Ellis <scott@jumpnowtek.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Showing 1 changed file with 6 additions and 4 deletions Side-by-side Diff
drivers/spi/omap2_mcspi.c
... | ... | @@ -751,11 +751,13 @@ |
751 | 751 | mcspi = spi_master_get_devdata(spi->master); |
752 | 752 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; |
753 | 753 | |
754 | - /* Unlink controller state from context save list */ | |
755 | - cs = spi->controller_state; | |
756 | - list_del(&cs->node); | |
754 | + if (spi->controller_state) { | |
755 | + /* Unlink controller state from context save list */ | |
756 | + cs = spi->controller_state; | |
757 | + list_del(&cs->node); | |
757 | 758 | |
758 | - kfree(spi->controller_state); | |
759 | + kfree(spi->controller_state); | |
760 | + } | |
759 | 761 | |
760 | 762 | if (mcspi_dma->dma_rx_channel != -1) { |
761 | 763 | omap_free_dma(mcspi_dma->dma_rx_channel); |