From patchwork Fri Mar 12 15:11:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Ellis X-Patchwork-Id: 85297 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2CFB5xe021787 for ; Fri, 12 Mar 2010 15:11:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934103Ab0CLPL5 (ORCPT ); Fri, 12 Mar 2010 10:11:57 -0500 Received: from pan.gwi.net ([207.5.128.165]:1090 "EHLO pan.gwi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934030Ab0CLPL4 (ORCPT ); Fri, 12 Mar 2010 10:11:56 -0500 Received: from [192.168.10.4] (66-63-88-74.static.suscom-maine.net [66.63.88.74]) by pan.gwi.net (8.13.1/8.13.1) with ESMTP id o2CFBsc3031295; Fri, 12 Mar 2010 10:11:54 -0500 (EST) (envelope-from scott@jumpnowtek.com) Subject: [PATCH 1/6 Revised] SPI omap2_mcspi.c: Check params before dereference or use From: Scott Ellis To: spi-devel-general@lists.sourceforge.net Cc: David Brownell , Grant Likely , Andrew Morton , Tony Lindgren , Kevin Hilman , Aaro Koskinen , Roman Tereshonkov , linux-omap@vger.kernel.org Date: Fri, 12 Mar 2010 10:11:53 -0500 Message-ID: <1268406713.14445.50.camel@quad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 12 Mar 2010 15:11:57 +0000 (UTC) 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; + } } }