From patchwork Tue Oct 4 19:12:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniroop Mathur X-Patchwork-Id: 9362233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F1E16607D6 for ; Tue, 4 Oct 2016 19:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4FD02887A for ; Tue, 4 Oct 2016 19:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7EB2289D5; Tue, 4 Oct 2016 19:05:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6C842887A for ; Tue, 4 Oct 2016 19:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754126AbcJDTE6 (ORCPT ); Tue, 4 Oct 2016 15:04:58 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:33342 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754107AbcJDTE4 (ORCPT ); Tue, 4 Oct 2016 15:04:56 -0400 Received: by mail-pa0-f66.google.com with SMTP id hh10so3061466pac.0; Tue, 04 Oct 2016 12:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=FnX1W1USsuJJu24S2pIwsFexzXBCmcPZPvb6jDX7fls=; b=txrc8Zb3My6JPo0/+BOGrlRSfBbZ131/WY5QnUHCFcNKKXfn4GegfdzLMth9LCNgeW FBXwWgIEG/5QBmnmVytYUj3aX1G/tGBFwtVwKbCJ4ZjF+mZh0z42gLkgyY1IDMl3I3Fj XFqxRUqAAR7OFIFPdCBrbop+u+zEWGIhulNMjwC12++hQdhhz0DPyIpmBFg694uiqosl IzLhH7lbVQS1w4o1vebR11Au5QrCF/Mu3v9vQVSKYAnsCRaY4wGtMmTGfXiAl1IEMyal XpLPeMGzAON1H5fy4EOwyQGhIixS8Ko57P0hzQ4EgQazLF18nmt+2e9aeh0li39/l+lx /v6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=FnX1W1USsuJJu24S2pIwsFexzXBCmcPZPvb6jDX7fls=; b=eIQornmmtaCtAfMn3Rdpavs3F7mbLuhzmg5DhcRZNT6zd624yTL9TncGSbXlN31HwJ 3wh6g8fx5ZQ56xEoV3i2uGAdn0RLKpRYYjS9u8oJB8Wjxf44tupIizAXtJh9BQYY0QUx qwi5ELGtJAtknzEEnmIX/2AWdzlC8UQS0W1bx0q6FzphBE1qCTwMboKNjHOAMAytC2iI rk06pW/H5n00c6MUTkx57Mgy8qAbpBRQGQj7lXxhn+awl6B0+PbRnIQEaNTVCDcZnEFO TB2c6cFwBkprFP9EzH0glHk0q60BDf1Gsc79kuOCenNvTAjOjGFVQ2KR7oaL3MYKnF2i Lc2g== X-Gm-Message-State: AA6/9RkxU5UXGNTSRyIKM1g6na4MibWXDmL1R0estDtQuXuJ8nA/Xc0VUfvaghTN5rW60g== X-Received: by 10.66.81.9 with SMTP id v9mr7250327pax.62.1475607895449; Tue, 04 Oct 2016 12:04:55 -0700 (PDT) Received: from Aniroops-MacBook-Pro.local.name ([110.172.168.226]) by smtp.gmail.com with ESMTPSA id y11sm57085388pfa.4.2016.10.04.12.04.53 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 04 Oct 2016 12:04:54 -0700 (PDT) From: Aniroop Mathur To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, a.mathur@samsung.com Subject: [PATCH] [v9]Input: evdev: fix bug of dropping valid packet after syn_dropped event Date: Wed, 5 Oct 2016 00:42:56 +0530 Message-Id: <1475608376-3077-1-git-send-email-a.mathur@samsung.com> X-Mailer: git-send-email 2.6.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If last event dropped in the old queue was EV_SYN/SYN_REPORT, then lets generate EV_SYN/SYN_REPORT immediately after queing EV_SYN/SYN_DROPPED so that clients would not ignore next valid full packet events. Signed-off-by: Aniroop Mathur Difference from v8: Added check for handling EVIOCG[type] ioctl for queue empty case --- drivers/input/evdev.c | 52 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index e9ae3d5..69407ff 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -156,7 +156,12 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type) static void __evdev_queue_syn_dropped(struct evdev_client *client) { struct input_event ev; + struct input_event *last_ev; ktime_t time; + unsigned int mask = client->bufsize - 1; + + /* capture last event stored in the buffer */ + last_ev = &client->buffer[(client->head - 1) & mask]; time = client->clk_type == EV_CLK_REAL ? ktime_get_real() : @@ -170,13 +175,28 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client) ev.value = 0; client->buffer[client->head++] = ev; - client->head &= client->bufsize - 1; + client->head &= mask; if (unlikely(client->head == client->tail)) { /* drop queue but keep our SYN_DROPPED event */ - client->tail = (client->head - 1) & (client->bufsize - 1); + client->tail = (client->head - 1) & mask; client->packet_head = client->tail; } + + /* + * If last packet was completely stored, then queue SYN_REPORT + * so that clients would not ignore next valid full packet + */ + if (last_ev->type == EV_SYN && last_ev->code == SYN_REPORT) { + last_ev->time = ev.time; + client->buffer[client->head++] = *last_ev; + client->head &= mask; + client->packet_head = client->head; + + /* drop queue but keep our SYN_DROPPED & SYN_REPORT event */ + if (unlikely(client->head == client->tail)) + client->tail = (client->head - 2) & mask; + } } static void evdev_queue_syn_dropped(struct evdev_client *client) @@ -218,7 +238,7 @@ static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid) spin_lock_irqsave(&client->buffer_lock, flags); if (client->head != client->tail) { - client->packet_head = client->head = client->tail; + client->packet_head = client->tail = client->head; __evdev_queue_syn_dropped(client); } @@ -231,22 +251,24 @@ static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid) static void __pass_event(struct evdev_client *client, const struct input_event *event) { + unsigned int mask = client->bufsize - 1; + client->buffer[client->head++] = *event; - client->head &= client->bufsize - 1; + client->head &= mask; if (unlikely(client->head == client->tail)) { /* * This effectively "drops" all unconsumed events, leaving - * EV_SYN/SYN_DROPPED plus the newest event in the queue. + * EV_SYN/SYN_DROPPED, EV_SYN/SYN_REPORT (if required) and + * 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; + client->head = (client->head - 1) & mask; + client->packet_head = client->tail = client->head; + __evdev_queue_syn_dropped(client); - client->packet_head = client->tail; + client->buffer[client->head++] = *event; + client->head &= mask; + /* No need to check for buffer overflow as it just occurred */ } if (event->type == EV_SYN && event->code == SYN_REPORT) { @@ -920,6 +942,7 @@ static int evdev_handle_get_val(struct evdev_client *client, int ret; unsigned long *mem; size_t len; + bool is_queue_empty; len = BITS_TO_LONGS(maxbit) * sizeof(unsigned long); mem = kmalloc(len, GFP_KERNEL); @@ -933,12 +956,15 @@ static int evdev_handle_get_val(struct evdev_client *client, spin_unlock(&dev->event_lock); + if (client->head == client->tail) + is_queue_empty = true; + __evdev_flush_queue(client, type); spin_unlock_irq(&client->buffer_lock); ret = bits_to_user(mem, maxbit, maxlen, p, compat); - if (ret < 0) + if (ret < 0 && !is_queue_empty) evdev_queue_syn_dropped(client); kfree(mem);