From patchwork Thu Jun 24 19:50:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 56830 X-Patchwork-Delegate: leann.ogasawara@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id EA739B6F29 for ; Fri, 25 Jun 2010 05:51:46 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1ORsSd-00067Z-47; Thu, 24 Jun 2010 20:51:43 +0100 Received: from ch-smtp03.sth.basefarm.net ([80.76.149.214]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1ORsSb-000673-DJ for kernel-team@lists.ubuntu.com; Thu, 24 Jun 2010 20:51:41 +0100 Received: from c83-248-196-134.bredband.comhem.se ([83.248.196.134]:47572 helo=alnilam) by ch-smtp03.sth.basefarm.net with smtp (Exim 4.68) (envelope-from ) id 1ORsSI-0005U4-Cm; Thu, 24 Jun 2010 21:51:26 +0200 Received: by alnilam (sSMTP sendmail emulation); Thu, 24 Jun 2010 21:51:22 +0200 From: "Henrik Rydberg" To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/5] Input: evdev - never leave the client buffer empty after write Date: Thu, 24 Jun 2010 21:50:38 +0200 Message-Id: <1277409038-25887-6-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1277409038-25887-5-git-send-email-rydberg@euromail.se> References: <1277409038-25887-1-git-send-email-rydberg@euromail.se> <1277409038-25887-2-git-send-email-rydberg@euromail.se> <1277409038-25887-3-git-send-email-rydberg@euromail.se> <1277409038-25887-4-git-send-email-rydberg@euromail.se> <1277409038-25887-5-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.248.196.134 X-Scan-Result: No virus found in message 1ORsSI-0005U4-Cm. X-Scan-Signature: ch-smtp03.sth.basefarm.net 1ORsSI-0005U4-Cm 9a1ff26bea619c63b58c6d03bd6084a3 Cc: Dmitry Torokhov X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com When the client buffer is very small and wraps around a lot, it may well be that a write increases the head such that head == tail. If this happens between the point where a poll is triggered and the actual data is being read, there will be no data to read. This is confusing to applications, which might end up closing the file. This patch solves the problem by making sure the client buffer is never empty after writing to it. Signed-off-by: Henrik Rydberg Signed-off-by: Dmitry Torokhov --- drivers/input/evdev.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 30836c0..cd32325 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -54,11 +54,15 @@ static void evdev_pass_event(struct evdev_client *client, struct input_event *event) { /* - * Interrupts are disabled, just acquire the lock + * Interrupts are disabled, just acquire the lock. + * Make sure we don't leave with the client buffer + * "empty" by having client->head == client->tail. */ spin_lock(&client->buffer_lock); - client->buffer[client->head++] = *event; - client->head &= client->bufsize - 1; + do { + client->buffer[client->head++] = *event; + client->head &= client->bufsize - 1; + } while (client->head == client->tail); spin_unlock(&client->buffer_lock); if (event->type == EV_SYN)