Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi/omap2_mcspi: Check params before dereference or use

Check spi->chip_select for range before use.

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

authored by

Scott Ellis and committed by
Grant Likely
99f1a43f 4743a0f8

+11 -8
+11 -8
drivers/spi/omap2_mcspi.c
··· 834 834 struct omap2_mcspi_cs *cs; 835 835 836 836 mcspi = spi_master_get_devdata(spi->master); 837 - mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 838 837 839 838 if (spi->controller_state) { 840 839 /* Unlink controller state from context save list */ ··· 843 844 kfree(spi->controller_state); 844 845 } 845 846 846 - if (mcspi_dma->dma_rx_channel != -1) { 847 - omap_free_dma(mcspi_dma->dma_rx_channel); 848 - mcspi_dma->dma_rx_channel = -1; 849 - } 850 - if (mcspi_dma->dma_tx_channel != -1) { 851 - omap_free_dma(mcspi_dma->dma_tx_channel); 852 - mcspi_dma->dma_tx_channel = -1; 847 + if (spi->chip_select < spi->master->num_chipselect) { 848 + mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 849 + 850 + if (mcspi_dma->dma_rx_channel != -1) { 851 + omap_free_dma(mcspi_dma->dma_rx_channel); 852 + mcspi_dma->dma_rx_channel = -1; 853 + } 854 + if (mcspi_dma->dma_tx_channel != -1) { 855 + omap_free_dma(mcspi_dma->dma_tx_channel); 856 + mcspi_dma->dma_tx_channel = -1; 857 + } 853 858 } 854 859 } 855 860