linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@deeprootsystems.com>
To: linux-input@vger.kernel.org
Cc: linux-omap@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	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: [PATCH] touchscreen: ads7846: please don't touch free'd memory
Date: Tue, 18 May 2010 16:46:53 -0700	[thread overview]
Message-ID: <1274226413-8520-1-git-send-email-khilman@deeprootsystems.com> (raw)

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.

Problem discovered when using lockdep since the ts->lock taken in
suspend & resume methods was left pointing into free'd memory if
_probe() fails.

Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
---
 drivers/input/touchscreen/ads7846.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 532279c..1da2369 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -815,6 +815,9 @@ static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
 {
 	struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 
+	if (WARN_ON_ONCE(!ts))
+		return 0;
+
 	spin_lock_irq(&ts->lock);
 
 	ts->is_suspended = 1;
@@ -833,6 +836,9 @@ static int ads7846_resume(struct spi_device *spi)
 {
 	struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 
+	if (WARN_ON_ONCE(!ts))
+		return 0;
+
 	if (device_may_wakeup(&ts->spi->dev))
 		disable_irq_wake(ts->spi->irq);
 
@@ -1231,6 +1237,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	input_free_device(input_dev);
 	kfree(packet);
 	kfree(ts);
+	dev_set_drvdata(&spi->dev, NULL);
 	return err;
 }
 
@@ -1240,6 +1247,9 @@ static int __devexit ads7846_remove(struct spi_device *spi)
 
 	device_init_wakeup(&spi->dev, false);
 
+	if (WARN_ON_ONCE(!ts))
+		return 0;
+
 	ads784x_hwmon_unregister(spi, ts);
 	input_unregister_device(ts->input);
 
-- 
1.7.0.2


             reply	other threads:[~2010-05-18 23:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-18 23:46 Kevin Hilman [this message]
2010-05-19  0:00 ` [PATCH] touchscreen: ads7846: please don't touch free'd memory Dmitry Torokhov
2010-05-25 19:52   ` Kevin Hilman
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=1274226413-8520-1-git-send-email-khilman@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).