From patchwork Thu Jan 26 17:06:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9539801 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 A5ABE604A0 for ; Thu, 26 Jan 2017 17:06:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B1F426B39 for ; Thu, 26 Jan 2017 17:06:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F6CA27D29; Thu, 26 Jan 2017 17:06:54 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 07AFF26B39 for ; Thu, 26 Jan 2017 17:06:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752479AbdAZRGw (ORCPT ); Thu, 26 Jan 2017 12:06:52 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33942 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752865AbdAZRGv (ORCPT ); Thu, 26 Jan 2017 12:06:51 -0500 Received: by mail-pf0-f194.google.com with SMTP id y143so16813988pfb.1 for ; Thu, 26 Jan 2017 09:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Spo099BLuAu9ZRrMwM2PTmGavNJwZYdGmlkTXSbLgw0=; b=X4a/kF0Kxodf/RbbyhSq1IeacVlWJDopXeAWOC0uu6ImfJvgKHliERNEGzJDRXQQxA qRB7YQ+2Dn+HxLlI/xRVJXYk419+RDUba1BT4d08I8zVuF5878nOpdFfDzZGgpUCR/R5 WEjm3tB8BcRSWRbNrMbdhw/nnTDz7utRmjwJAdvJC5WcfZRzyyhXeaOyxEBpLgVXKkzy DyZ1qKZyAbSwZ6EMr3MCVTgnvPiXh9XQy//DSRJY2alC8agBUkBI4mE2U/RpQovDFbN6 6wf0Mv/22skDStLpVb51ZXXooOJXMjTc0kqxty7mawn4YY6W9HLQPZJ85rEXcYhLCiRt MEig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Spo099BLuAu9ZRrMwM2PTmGavNJwZYdGmlkTXSbLgw0=; b=efcfuELyvVuzUv5OrC1FLmY74E/jcku02huqvG0WHWMqDdPlUkEfvr+w2HZjVTOGLx GA2LYSaEpqvcNOsQD7uGY/j58S/o/LT+3Fn7VpmP9Z63FJvpllLzrG+uyG7tRQ29qb4B /92A5gamEns7LqXvYdN+/h0lN5VZ9l0rYLXYDCZQBskJ9QlGquIaqi2I3k8v1R6WRAxG pkGt1wEKcb6cUcTXMArzb3lshU41y23tJYVdBrJYsCwwfngfsYjF++YLS7QIy9bD0l8X 9QlOYYAjew9hdhlIyWdV5oMEnvsH83+x7jzckF8vglW7yxYO6Ubjj0Ryje+24LQN+xfA NMSg== X-Gm-Message-State: AIkVDXJDVGn9j/vARRghkkK96L8RJPP59GBpXUPuwWpC6LimK0HqxE6pxjoC8/GqnipICA== X-Received: by 10.84.232.70 with SMTP id f6mr5575571pln.113.1485450398615; Thu, 26 Jan 2017 09:06:38 -0800 (PST) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id 134sm4755225pgh.13.2017.01.26.09.06.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jan 2017 09:06:37 -0800 (PST) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Benjamin Tissoires , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq' Date: Thu, 26 Jan 2017 09:06:22 -0800 Message-Id: <20170126170622.6760-1-killertofu@gmail.com> X-Mailer: git-send-email 2.11.0 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 Commit 025bcc1 performed cleanup work on the 'wacom_pl_irq' function, making it follow the standards used in the rest of the codebase. The change unintiontionally allowed the function to send input events from reports that are not marked as being in prox. This can cause problems as the report values for X, Y, etc. are not guaranteed to be correct. In particular, occasionally the tablet will send a report with these values set to zero. If such a report is received it can caus an unexpected jump in the XY position. This patch surrounds more of the processing code with a proximity check, preventing these zeroed reports from overwriting the current state. To be safe, only the tool type and ABS_MISC events should be reported when the pen is marked as being out of prox. Fixes: 025bcc1540 ("HID: wacom: Simplify 'wacom_pl_irq'") Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng --- drivers/hid/wacom_wac.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 0884dc9554fd..672145b0d8f5 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -166,19 +166,21 @@ static int wacom_pl_irq(struct wacom_wac *wacom) wacom->id[0] = STYLUS_DEVICE_ID; } - pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); - if (features->pressure_max > 255) - pressure = (pressure << 1) | ((data[4] >> 6) & 1); - pressure += (features->pressure_max + 1) / 2; - - input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); - input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); - input_report_abs(input, ABS_PRESSURE, pressure); - - input_report_key(input, BTN_TOUCH, data[4] & 0x08); - input_report_key(input, BTN_STYLUS, data[4] & 0x10); - /* Only allow the stylus2 button to be reported for the pen tool. */ - input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20)); + if (prox) { + pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); + if (features->pressure_max > 255) + pressure = (pressure << 1) | ((data[4] >> 6) & 1); + pressure += (features->pressure_max + 1) / 2; + + input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); + input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); + input_report_abs(input, ABS_PRESSURE, pressure); + + input_report_key(input, BTN_TOUCH, data[4] & 0x08); + input_report_key(input, BTN_STYLUS, data[4] & 0x10); + /* Only allow the stylus2 button to be reported for the pen tool. */ + input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20)); + } if (!prox) wacom->id[0] = 0;