linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@deeprootsystems.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-omap@vger.kernel.org,
	Michael Roth <mroth@nessie.de>, Pavel Machek <pavel@ucw.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Frysinger <vapier@gentoo.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] touchscreen: ads7846: please don't touch free'd memory
Date: Tue, 25 May 2010 12:52:12 -0700	[thread overview]
Message-ID: <87mxvnlpxv.fsf@deeprootsystems.com> (raw)
In-Reply-To: <20100519000019.GA17475@core.coreip.homeip.net> (Dmitry Torokhov's message of "Tue\, 18 May 2010 17\:00\:20 -0700")

Dmitry Torokhov <dmitry.torokhov@gmail.com> writes:

> On Tue, May 18, 2010 at 04:46:53PM -0700, Kevin Hilman wrote:
>> If the _probe() method fails, the 'ts' struct is freed, yet it is
>> still used as the drvdata passed to suspend/resume/remove methods.
>> Even though the input device does not get registerd, the driver's
>> suspend/resume methods still get called as it's a registered SPI
>> device.  This patch adds sanity checks to these methods to ensure that
>> drvdata is valid before using it.
>> 
>
> This is a load of crap. If probe() fails that means that driver does not
> manage the device and thus ads7846_suspend() and ads7846_resume() should
> not be called _at all_. If SPI core manages to call random methods from
> the drivers that failed to bind to a device that should be fixed in SPI
> core.

Agreed, this is indeed a bug in the SPI driver core.

However, by fixing the SPI core to unregister the driver on failure
(patch below), we prevent the suspend & resume methods from being
called, but the driver's ->remove() method will still be called due to
the driver_unregister().  So at least the remove() method needs fixing
to prevent accessing free'd memory.

Unless there are objections, I'll post the below along with an updated
version of ads7846 patch.

Kevin

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b3a1f92..42d4d26 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -175,6 +175,8 @@ static void spi_drv_shutdown(struct device *dev)
  */
 int spi_register_driver(struct spi_driver *sdrv)
 {
+	int ret;
+
 	sdrv->driver.bus = &spi_bus_type;
 	if (sdrv->probe)
 		sdrv->driver.probe = spi_drv_probe;
@@ -182,7 +184,12 @@ int spi_register_driver(struct spi_driver *sdrv)
 		sdrv->driver.remove = spi_drv_remove;
 	if (sdrv->shutdown)
 		sdrv->driver.shutdown = spi_drv_shutdown;
-	return driver_register(&sdrv->driver);
+
+	ret = driver_register(&sdrv->driver);
+	if (!ret)
+		driver_unregister(&sdrv->driver);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(spi_register_driver);
 


  reply	other threads:[~2010-05-25 19:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18 23:46 [PATCH] touchscreen: ads7846: please don't touch free'd memory Kevin Hilman
2010-05-19  0:00 ` Dmitry Torokhov
2010-05-25 19:52   ` Kevin Hilman [this message]
2010-05-25 20:21     ` Dmitry Torokhov
2010-05-25 21:46       ` Kevin Hilman
2010-05-25 21:56         ` Mike Frysinger
2010-05-25 22:18           ` Kevin Hilman
2010-05-25 22:25             ` Dmitry Torokhov
2010-05-26  0:09         ` David Brownell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxvnlpxv.fsf@deeprootsystems.com \
    --to=khilman@deeprootsystems.com \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mroth@nessie.de \
    --cc=pavel@ucw.cz \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).