public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] omap2_mcspi.c: Checks in omap2_mcspi_cleanup
@ 2010-03-08 11:55 Scott Ellis
  0 siblings, 0 replies; only message in thread
From: Scott Ellis @ 2010-03-08 11:55 UTC (permalink / raw)
  To: linux-omap

Check spi->controller_state before dereferencing.
Check spi->chip_select for range before using.

Neither are guaranteed to be valid when spi_dev_put() is called.
Submitted previously to the linux-kernel list but without the 
chip_select check.

Signed-off-by: Scott Ellis <scott@jumpnowtek.com>


 drivers/spi/omap2_mcspi.c |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index 715c518..fe1b56d 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -748,22 +748,26 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)
        struct omap2_mcspi_dma  *mcspi_dma;
        struct omap2_mcspi_cs   *cs;
 
-       mcspi = spi_master_get_devdata(spi->master);
-       mcspi_dma = &mcspi->dma_channels[spi->chip_select];
+       if (spi->controller_state) {
+               /* Unlink controller state from context save list */
+               cs = spi->controller_state;
+               list_del(&cs->node);
 
-       /* Unlink controller state from context save list */
-       cs = spi->controller_state;
-       list_del(&cs->node);
+               kfree(spi->controller_state);
+       }
 
-       kfree(spi->controller_state);
+       if (spi->chip_select < spi->master->num_chipselect) {
+               mcspi = spi_master_get_devdata(spi->master);
+               mcspi_dma = &mcspi->dma_channels[spi->chip_select];
 
-       if (mcspi_dma->dma_rx_channel != -1) {
-               omap_free_dma(mcspi_dma->dma_rx_channel);
-               mcspi_dma->dma_rx_channel = -1;
-       }
-       if (mcspi_dma->dma_tx_channel != -1) {
-               omap_free_dma(mcspi_dma->dma_tx_channel);
-               mcspi_dma->dma_tx_channel = -1;
+               if (mcspi_dma->dma_rx_channel != -1) {
+                       omap_free_dma(mcspi_dma->dma_rx_channel);
+                       mcspi_dma->dma_rx_channel = -1;
+               }
+               if (mcspi_dma->dma_tx_channel != -1) {
+                       omap_free_dma(mcspi_dma->dma_tx_channel);
+                       mcspi_dma->dma_tx_channel = -1;
+               }
        }
 }




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-03-08 13:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-08 11:55 [PATCH] omap2_mcspi.c: Checks in omap2_mcspi_cleanup Scott Ellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox