From patchwork Fri Aug 10 20:56:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 1306591 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork1.kernel.org (Postfix) with ESMTP id 867D53FC33 for ; Fri, 10 Aug 2012 20:56:54 +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 1SzwGJ-0006xI-H0; Fri, 10 Aug 2012 20:56:51 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1SzwGI-0006xC-JR for spi-devel-general@lists.sourceforge.net; Fri, 10 Aug 2012 20:56:50 +0000 X-ACL-Warn: Received: from mail.active-venture.com ([67.228.131.205]) by sog-mx-2.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1SzwGH-0004eR-Mm for spi-devel-general@lists.sourceforge.net; Fri, 10 Aug 2012 20:56:50 +0000 Received: (qmail 88549 invoked by uid 399); 10 Aug 2012 20:56:42 -0000 X-Virus-Scan: Scanned by ClamAV 0.97.2 (no viruses); Fri, 10 Aug 2012 15:56:42 -0500 Received: from unknown (HELO localhost) (guenter@roeck-us.net@108.223.40.66) by mail.active-venture.com with ESMTPAM; 10 Aug 2012 20:56:41 -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: [RFC PATCH] spi/bcm63xx: Ensure that memory is freed only after it is no longer used Date: Fri, 10 Aug 2012 13:56:27 -0700 Message-Id: <1344632187-9603-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 1.7.9.7 X-Spam-Score: -0.0 (/) 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.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1SzwGH-0004eR-Mm Cc: Mark Brown , linux-kernel@vger.kernel.org, Guenter Roeck , Florian Fainelli 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 to spi_unregister_master() in the device remove function frees device memory, and with it any device local data. However, device local data is still accessed after the call to spi_unregister_master(). Acquire a reference to the SPI device and release it after cleanup is complete to solve the problem. Cc: Florian Fainelli Signed-off-by: Guenter Roeck --- Several drivers have this problem, and I am trying to find a common fix. This solution is modeled after the approach used in spi-txx9spi:txx9spi_remove. The other possible fix would be to move spi_unregister_master() to the end of bcm63xx_spi_remove(), but I am not sure if it is a good idea to clean up before the call to spi_unregister_master(). drivers/spi/spi-bcm63xx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c index 6e25ef1..ea0aaa3 100644 --- a/drivers/spi/spi-bcm63xx.c +++ b/drivers/spi/spi-bcm63xx.c @@ -438,7 +438,7 @@ out: static int __devexit bcm63xx_spi_remove(struct platform_device *pdev) { - struct spi_master *master = platform_get_drvdata(pdev); + struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); struct bcm63xx_spi *bs = spi_master_get_devdata(master); spi_unregister_master(master); @@ -452,6 +452,8 @@ static int __devexit bcm63xx_spi_remove(struct platform_device *pdev) platform_set_drvdata(pdev, 0); + spi_master_put(master); + return 0; }