From: "Henrik Rydberg" <rydberg@euromail.se>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Jeff Brown <jeffbrown@android.com>,
djkurtz@google.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org, Jeff Brown <jeffbrown@google.com>
Subject: Re: [PATCH v2 3/4] input: evdev: Indicate buffer overrun with SYN_DROPPED.
Date: Tue, 5 Apr 2011 13:41:18 +0200 [thread overview]
Message-ID: <20110405114118.GA19217@polaris.bitmath.org> (raw)
In-Reply-To: <20110404213338.GB984@core.coreip.homeip.net>
> Input: evdev - indicate buffer overrun with SYN_DROPPED
>
> From: Jeff Brown <jeffbrown@google.com>
>
> Add a new EV_SYN code, SYN_DROPPED, to inform the client when input
> events have been dropped from the evdev input buffer due to a
> buffer overrun. The client should use this event as a hint to
> reset its state or ignore all following events until the next
> packet begins.
>
> Signed-off-by: Jeff Brown <jeffbrown@android.com>
> [dtor@mail.ru: Implement Henrik's suggestion and drop old events in
> case of overflow.]
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
>
> Documentation/input/event-codes.txt | 6 ++++++
> drivers/input/evdev.c | 33 +++++++++++++++++++++------------
> include/linux/input.h | 1 +
> 3 files changed, 28 insertions(+), 12 deletions(-)
>
>
> diff --git a/Documentation/input/event-codes.txt b/Documentation/input/event-codes.txt
> index d6732a4..e0326a0 100644
> --- a/Documentation/input/event-codes.txt
> +++ b/Documentation/input/event-codes.txt
> @@ -79,6 +79,12 @@ defined only by when they are sent in the evdev event stream.
> - Used to synchronize and separate touch events. See the
> multi-touch-protocol.txt document for more information.
>
> +* SYN_DROPPED:
> + - Used to indicate buffer overrun in the evdev client's event queue.
> + Client should ignore all events up to and including next SYN_REPORT
> + event and query the device (using EVIOCG* ioctls) to obtain its
> + current state.
> +
> EV_KEY:
> ----------
> EV_KEY events take the form KEY_<name> or BTN_<name>. For example, KEY_A is used
> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> index 7f42d3a..f1c0910 100644
> --- a/drivers/input/evdev.c
> +++ b/drivers/input/evdev.c
> @@ -39,13 +39,13 @@ struct evdev {
> };
>
> struct evdev_client {
> - int head;
> - int tail;
> + unsigned int head;
> + unsigned int tail;
> spinlock_t buffer_lock; /* protects access to buffer, head and tail */
> struct fasync_struct *fasync;
> struct evdev *evdev;
> struct list_head node;
> - int bufsize;
> + unsigned int bufsize;
> struct input_event buffer[];
> };
>
> @@ -55,16 +55,25 @@ static DEFINE_MUTEX(evdev_table_mutex);
> static void evdev_pass_event(struct evdev_client *client,
> struct input_event *event)
> {
> - /*
> - * Interrupts are disabled, just acquire the lock.
> - * Make sure we don't leave with the client buffer
> - * "empty" by having client->head == client->tail.
> - */
> + /* Interrupts are disabled, just acquire the lock. */
> spin_lock(&client->buffer_lock);
> - do {
> - client->buffer[client->head++] = *event;
> - client->head &= client->bufsize - 1;
> - } while (client->head == client->tail);
> +
> + client->buffer[client->head++] = *event;
> + client->head &= client->bufsize - 1;
> +
> + if (unlikely(client->head == client->tail)) {
> + /*
> + * This effectively "drops" all unconsumed events, leaving
> + * EV_SYN/SYN_DROPPED plus the newest event in the queue.
> + */
> + client->tail = (client->head - 2) & (client->bufsize - 1);
> +
> + client->buffer[client->tail].time = event->time;
> + client->buffer[client->tail].type = EV_SYN;
> + client->buffer[client->tail].code = SYN_DROPPED;
> + client->buffer[client->tail].value = 0;
> + }
> +
> spin_unlock(&client->buffer_lock);
>
> if (event->type == EV_SYN)
> diff --git a/include/linux/input.h b/include/linux/input.h
> index f3a7794..71d3651 100644
> --- a/include/linux/input.h
> +++ b/include/linux/input.h
> @@ -167,6 +167,7 @@ struct input_keymap_entry {
> #define SYN_REPORT 0
> #define SYN_CONFIG 1
> #define SYN_MT_REPORT 2
> +#define SYN_DROPPED 3
>
> /*
> * Keys and buttons
Acked-by: Henrik Rydberg <rydberg@euromail.se>
Thanks,
Henrik
next prev parent reply other threads:[~2011-04-05 12:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-02 6:54 [PATCH v2 1/4] input: Set default events per packet Jeff Brown
2011-04-02 6:54 ` [PATCH v2 2/4] hid: hid-input: Remove obsolete default events per packet setting Jeff Brown
2011-04-05 12:20 ` Henrik Rydberg
2011-04-02 6:54 ` [PATCH v2 3/4] input: evdev: Indicate buffer overrun with SYN_DROPPED Jeff Brown
2011-04-04 21:33 ` Dmitry Torokhov
2011-04-04 21:52 ` Jeffrey Brown
2011-04-05 11:41 ` Henrik Rydberg [this message]
2011-04-02 6:54 ` [PATCH v2 4/4] input: evdev: Make device readable only when it contains a complete packet Jeff Brown
2011-04-04 21:36 ` Dmitry Torokhov
2011-04-04 22:16 ` Jeffrey Brown
2011-04-04 22:46 ` Dmitry Torokhov
2011-04-05 0:34 ` Jeffrey Brown
2011-04-05 12:03 ` Henrik Rydberg
2011-04-05 16:32 ` Dmitry Torokhov
2011-04-05 16:38 ` Dmitry Torokhov
2011-04-11 20:15 ` Jeffrey Brown
2011-04-05 12:16 ` [PATCH v2 1/4] input: Set default events per packet Henrik Rydberg
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=20110405114118.GA19217@polaris.bitmath.org \
--to=rydberg@euromail.se \
--cc=djkurtz@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jeffbrown@android.com \
--cc=jeffbrown@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome