All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaro Koskinen <aaro.koskinen@nokia.com>
To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Aaro Koskinen <aaro.koskinen@nokia.com>
Subject: [PATCH] input: tsc2005: fix locking issue
Date: Mon, 21 Mar 2011 18:24:10 +0200	[thread overview]
Message-ID: <1300724650-6641-1-git-send-email-aaro.koskinen@nokia.com> (raw)

Commit 0b950d3 (Input: tsc2005 - add open/close) introduced a
locking issue with the ESD watchdog: __tsc2005_disable() is calling
cancel_delayed_work_sync() with mutex held, and the work also needs the
same mutex.

Fix the problem by using cancel_delayed_work() on disable. If
the ESD work was running it will check if the device is closed
or suspended, and in that case it will do nothing and skip
re-arming. cancel_delayed_work_sync() is still needed when the module
is removed.

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
---
 drivers/input/touchscreen/tsc2005.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c
index 8742061..3a15587 100644
--- a/drivers/input/touchscreen/tsc2005.c
+++ b/drivers/input/touchscreen/tsc2005.c
@@ -345,7 +345,7 @@ static void __tsc2005_disable(struct tsc2005 *ts)
 	disable_irq(ts->spi->irq);
 	del_timer_sync(&ts->penup_timer);
 
-	cancel_delayed_work_sync(&ts->esd_work);
+	cancel_delayed_work(&ts->esd_work);
 
 	enable_irq(ts->spi->irq);
 }
@@ -479,6 +479,12 @@ static void tsc2005_esd_work(struct work_struct *work)
 
 	mutex_lock(&ts->mutex);
 
+	/* The device has been just closed or suspended. */
+	if (!ts->opened || ts->suspended) {
+		mutex_unlock(&ts->mutex);
+		return;
+	}
+
 	if (time_is_after_jiffies(ts->last_valid_interrupt +
 				  msecs_to_jiffies(ts->esd_timeout)))
 		goto out;
@@ -685,6 +691,7 @@ static int __devexit tsc2005_remove(struct spi_device *spi)
 
 	free_irq(ts->spi->irq, ts);
 	input_unregister_device(ts->idev);
+	cancel_delayed_work_sync(&ts->esd_work);
 	kfree(ts);
 
 	spi_set_drvdata(spi, NULL);
-- 
1.5.6.5


             reply	other threads:[~2011-03-21 16:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-21 16:24 Aaro Koskinen [this message]
2011-03-22  6:19 ` [PATCH] input: tsc2005: fix locking issue Dmitry Torokhov
2011-03-22 14:59   ` Aaro Koskinen
2011-03-22 15:42     ` Dmitry Torokhov
2011-03-23 13:05       ` Aaro Koskinen

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=1300724650-6641-1-git-send-email-aaro.koskinen@nokia.com \
    --to=aaro.koskinen@nokia.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.