All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor_core@ameritech.net>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>, Vojtech Pavlik <vojtech@suse.cz>,
	vojtech@ucw.cz
Subject: [PATCH 2/11] psmouse state locking
Date: Fri, 18 Jun 2004 03:37:46 -0500	[thread overview]
Message-ID: <200406180337.47669.dtor_core@ameritech.net> (raw)
In-Reply-To: <200406180337.17457.dtor_core@ameritech.net>


===================================================================


ChangeSet@1.1791, 2004-06-17 18:15:07-05:00, dtor_core@ameritech.net
  Input: when changing psmouse state (activated, ignore) do it while
         holding serio lock so it will not fight with the interrupt
         handler.
  
  Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


 psmouse-base.c |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)


===================================================================



diff -Nru a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c	2004-06-18 03:14:47 -05:00
+++ b/drivers/input/mouse/psmouse-base.c	2004-06-18 03:14:47 -05:00
@@ -625,6 +625,23 @@
 }
 
 /*
+ * psmouse_set_state() sets new psmouse state and resets all flags and
+ * counters while holding serio lock so fighting with interrupt handler
+ * is not a concern.
+ */
+
+static void psmouse_set_state(struct psmouse *psmouse, unsigned char new_state)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&psmouse->serio->lock, flags);
+	psmouse->state = new_state;
+	psmouse->pktcnt = psmouse->cmdcnt = psmouse->out_of_sync = 0;
+	psmouse->flags = 0;
+	spin_unlock_irqrestore(&psmouse->serio->lock, flags);
+}
+
+/*
  * psmouse_activate() enables the mouse so that we get motion reports from it.
  */
 
@@ -633,7 +650,7 @@
 	if (psmouse_command(psmouse, NULL, PSMOUSE_CMD_ENABLE))
 		printk(KERN_WARNING "psmouse.c: Failed to enable mouse on %s\n", psmouse->serio->phys);
 
-	psmouse->state = PSMOUSE_ACTIVATED;
+	psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
 }
 
 /*
@@ -655,7 +672,7 @@
 {
 	struct psmouse *psmouse = serio->private;
 
-	psmouse->state = PSMOUSE_CMD_MODE;
+	psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
 
 	if (psmouse->ptport) {
 		if (psmouse->ptport->deactivate)
@@ -668,7 +685,7 @@
 	if (psmouse->disconnect)
 		psmouse->disconnect(psmouse);
 
-	psmouse->state = PSMOUSE_IGNORE;
+	psmouse_set_state(psmouse, PSMOUSE_IGNORE);
 
 	input_unregister_device(&psmouse->dev);
 	serio_close(serio);
@@ -696,9 +713,9 @@
 	psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
 	psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
 	psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
-	psmouse->state = PSMOUSE_CMD_MODE;
 	psmouse->serio = serio;
 	psmouse->dev.private = psmouse;
+	psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
 
 	serio->private = psmouse;
 	if (serio_open(serio, dev)) {
@@ -761,12 +778,7 @@
 		return -1;
 	}
 
-	psmouse->state = PSMOUSE_CMD_MODE;
-
-	clear_bit(PSMOUSE_FLAG_ACK, &psmouse->flags);
-	clear_bit(PSMOUSE_FLAG_CMD,  &psmouse->flags);
-
-	psmouse->pktcnt = psmouse->out_of_sync = 0;
+	psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
 
 	if (psmouse->reconnect) {
 	       if (psmouse->reconnect(psmouse))

  reply	other threads:[~2004-06-18  8:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200406180335.52843.dtor_core@ameritech.net>
2004-06-18  8:37 ` [PATCH 1/11] psmouse resync for KVM users Dmitry Torokhov
2004-06-18  8:37   ` Dmitry Torokhov [this message]
2004-06-18  8:38     ` [PATCH 3/11] serio connect/disconnect mandatory Dmitry Torokhov
2004-06-18  8:39       ` [PATCH 4/11] serio renames 1 Dmitry Torokhov
2004-06-18  8:39         ` [PATCH 5/11] serio renames 2 Dmitry Torokhov
2004-06-18  8:40           ` [PATCH 6/11] serio dynamic allocation Dmitry Torokhov
2004-06-18  8:41             ` [PATCH 7/11] serio no recursion Dmitry Torokhov
2004-06-18  8:42               ` [PATCH 8/11] serio sysfs integration Dmitry Torokhov
2004-06-18  8:42                 ` [PATCH 9/11] serio allow rebinding Dmitry Torokhov
2004-06-18  8:43                   ` [PATCH 10/11] serio manual bind Dmitry Torokhov
2004-06-18  8:43                     ` [PATCH 11/11] serio_raw driver Dmitry Torokhov
2004-06-18  9:19                   ` [PATCH 9/11] serio allow rebinding Jan-Benedict Glaw
2004-06-18  9:38                 ` [PATCH 8/11] serio sysfs integration Andrew Morton
2004-06-18 12:50                   ` Dmitry Torokhov
2004-06-18 19:43                     ` Andrew Morton
2004-06-20  5:07             ` [PATCH 6/11] serio dynamic allocation Andrew Morton
2004-06-20  5:30               ` Dmitry Torokhov
2004-06-20  6:27                 ` Andrew Morton
2004-06-20  6:28                   ` Andrew Morton

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=200406180337.47669.dtor_core@ameritech.net \
    --to=dtor_core@ameritech.net \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    --cc=vojtech@ucw.cz \
    /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.