From patchwork Fri Aug 24 18:03:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 1372261 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork2.kernel.org (Postfix) with ESMTP id 2C87DDF28C for ; Fri, 24 Aug 2012 18:03:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T4yE6-0007E9-OV; Fri, 24 Aug 2012 18:03:22 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1T4yE5-0007E4-Cu for spi-devel-general@lists.sourceforge.net; Fri, 24 Aug 2012 18:03:21 +0000 X-ACL-Warn: Received: from mail.active-venture.com ([67.228.131.205]) by sog-mx-3.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1T4yDz-000832-SJ for spi-devel-general@lists.sourceforge.net; Fri, 24 Aug 2012 18:03:21 +0000 Received: (qmail 56523 invoked by uid 399); 24 Aug 2012 18:03:08 -0000 X-Virus-Scan: Scanned by ClamAV 0.97.2 (no viruses); Fri, 24 Aug 2012 13:03:08 -0500 Received: from unknown (HELO localhost) (guenter@roeck-us.net@108.223.40.66) by mail.active-venture.com with ESMTPAM; 24 Aug 2012 18:03:08 -0000 X-Originating-IP: 108.223.40.66 X-Sender: guenter@roeck-us.net From: Guenter Roeck To: spi-devel-general@lists.sourceforge.net Subject: [PATCH] spi/mxs: Fix device remove function Date: Fri, 24 Aug 2012 11:03:02 -0700 Message-Id: <1345831382-7290-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 1.7.9.7 X-Spam-Score: 0.1 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 AWL AWL: From: address is in the auto white-list X-Headers-End: 1T4yDz-000832-SJ Cc: Marek Vasut , Mark Brown , Guenter Roeck X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net The call sequence spi_alloc_master/spi_register_master/spi_unregister_master is complete; it reduces the device reference count to zero, which results in device memory being freed. The remove function accesses the freed memory after the call to spi_unregister_master(), _and_ it calls spi_master_put on the freed memory. Acquire a reference to the SPI master device and release it after cleanup is complete (with the existing spi_master_put) to solve the problem. Also, the device subsystem ensures that the remove function is only called once, and resets device driver data to NULL. Remove the unnecessaary calls to platform_set_drvdata(). Cc: Marek Vasut Signed-off-by: Guenter Roeck Reviewed-by: Marek Vasut --- Applies to -next (as of 8/24/12). drivers/spi/spi-mxs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c index 130a436..cb189b7 100644 --- a/drivers/spi/spi-mxs.c +++ b/drivers/spi/spi-mxs.c @@ -582,7 +582,6 @@ static int __devinit mxs_spi_probe(struct platform_device *pdev) return 0; out_free_dma: - platform_set_drvdata(pdev, NULL); dma_release_channel(ssp->dmach); clk_disable_unprepare(ssp->clk); out_master_free: @@ -596,14 +595,12 @@ static int __devexit mxs_spi_remove(struct platform_device *pdev) struct mxs_spi *spi; struct mxs_ssp *ssp; - master = platform_get_drvdata(pdev); + master = spi_master_get(platform_get_drvdata(pdev)); spi = spi_master_get_devdata(master); ssp = &spi->ssp; spi_unregister_master(master); - platform_set_drvdata(pdev, NULL); - dma_release_channel(ssp->dmach); clk_disable_unprepare(ssp->clk);