From patchwork Wed Oct 27 17:09:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Gatliff X-Patchwork-Id: 286302 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9RHACKk019316 for ; Wed, 27 Oct 2010 17:10:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752381Ab0J0RKL (ORCPT ); Wed, 27 Oct 2010 13:10:11 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:57124 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751899Ab0J0RKL (ORCPT ); Wed, 27 Oct 2010 13:10:11 -0400 Received: by ewy7 with SMTP id 7so830929ewy.19 for ; Wed, 27 Oct 2010 10:10:09 -0700 (PDT) Received: by 10.213.28.205 with SMTP id n13mr1097069ebc.5.1288199409571; Wed, 27 Oct 2010 10:10:09 -0700 (PDT) Received: from netbook (216-75-224-218.static.wiline.com [216.75.224.218]) by mx.google.com with ESMTPS id k11sm4636248vbp.13.2010.10.27.10.10.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 27 Oct 2010 10:10:08 -0700 (PDT) Received: from bgat by netbook with local (Exim 4.72) (envelope-from ) id 1PB9Vl-0001t3-0e; Wed, 27 Oct 2010 12:10:05 -0500 From: Bill Gatliff To: linux-input@vger.kernel.org Cc: Bill Gatliff Subject: [PATCH] evdev: discard oldest event on buffer overflow Date: Wed, 27 Oct 2010 12:09:58 -0500 Message-Id: <1288199398-7198-1-git-send-email-bgat@billgatliff.com> X-Mailer: git-send-email 1.7.1 To: linux-input@vger.kernel.org Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 27 Oct 2010 17:10:12 +0000 (UTC) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index e3f7fc6..04a18ff 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -55,15 +55,19 @@ static void evdev_pass_event(struct evdev_client *client, { /* * 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); - do { - client->buffer[client->head++] = *event; - client->head &= client->bufsize - 1; - } while (client->head == client->tail); - spin_unlock(&client->buffer_lock); + client->buffer[client->head++] = *event; + client->head &= client->bufsize - 1; + + /* + * If we overflow the buffer, consume the oldest + * event to make room for the one that just arrived + */ + if (unlikely(client->head == client->tail)) { + client->tail++; + client->tail &= client->bufsize - 1; + } if (event->type == EV_SYN) kill_fasync(&client->fasync, SIGIO, POLL_IN);