From patchwork Tue Dec 26 22:53:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10133279 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 405046023A for ; Tue, 26 Dec 2017 22:54:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31EE42C383 for ; Tue, 26 Dec 2017 22:54:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 268832C387; Tue, 26 Dec 2017 22:54:15 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 0C85E2C388 for ; Tue, 26 Dec 2017 22:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751211AbdLZWyM (ORCPT ); Tue, 26 Dec 2017 17:54:12 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:38119 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751122AbdLZWyL (ORCPT ); Tue, 26 Dec 2017 17:54:11 -0500 Received: by mail-pg0-f66.google.com with SMTP id f12so18169824pgo.5; Tue, 26 Dec 2017 14:54:11 -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=32aMFOkqscH4c8WAUP025OD4Gqaxz6oT4e3TtgSxkYo=; b=P/g8wZF07vh+9gbnJmGfeJ20fKrvjs5RdFL2u3l0xyhVKQbri9/GxpybA5it+igOtP Dg5qZhOR3dk8vpVtLqDjXrhowjsch0nStbUxjMF1gR7Uv0brQUjrqWb2d9SdHysRIvU6 OQm2+IFgteiLiyUHMs+UM25p1ATc+EELbdKmytM8wWsqBKtYQArA+vRTOo+qIl5oglDI Z7VKhwO4eJYEbxogCNRdmWR8byAv7dQ7Q8URtEkY6wicRjTIu01PbeS6Jzn9drjwm1Gd z96uF66EehpZ049Xp9EFEGc4F9TEt4QzTDhX6ydMlkqfYctxmODhgZhG/ZaWsKEcbJuC ni1A== 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=32aMFOkqscH4c8WAUP025OD4Gqaxz6oT4e3TtgSxkYo=; b=RobqY/mstJfQ9gT5Glz+Jd1M+JEj2jcy64jfOAYzTC0cugfkTIW75a7kMJHWC9cRgi LDnEtQRdXIyaE6dvJrRElXyhcjP5M48LpMfo3p676BitljCRp8k8LwlbLw/z7+sIsj3F eDzGncTbHHj84QC+tAIclPkfagSHS54lr+YL3/HZejfS5Pbd9N5B/o/hZ2kOsJSH1Opk I8OaE22YdaNexMTHVRFWsRp7yUKCGxMXdYfcXyNHojcxENYu8vNeLx8mo2eoq7rFqier sDbYpRXYnLRsCA8UkzB/j0Sl/xwDY4kWPOka9hBPV7+dXrPVH3uLgU63iYDTgff9jQVJ OAew== X-Gm-Message-State: AKGB3mId0vIIPSecuh09i7+3ok5fgFO726/u+PA0HSCM4TFpqDBKWxWn e/0rnBil0Fs3DfbcRwo69i7Rlctd X-Google-Smtp-Source: ACJfBovCLdCjYjWkxZ77ZlH/Uh10dgDy0V/Xy6GD7OBBRAtYMgkpNlrFET+YcOw4AxA1llWl4O/vNQ== X-Received: by 10.99.174.7 with SMTP id q7mr13814590pgf.428.1514328850794; Tue, 26 Dec 2017 14:54:10 -0800 (PST) Received: from localhost.localdomain (75-164-223-64.ptld.qwest.net. [75.164.223.64]) by smtp.gmail.com with ESMTPSA id b6sm61381783pfe.57.2017.12.26.14.54.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Dec 2017 14:54:10 -0800 (PST) From: Jason Gerecke To: linux-input@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , stable@vger.kernel.org, Jason Gerecke Subject: [PATCH] Fix reporting of touch toggle (WACOM_HID_WD_MUTE_DEVICE) events Date: Tue, 26 Dec 2017 14:53:55 -0800 Message-Id: <20171226225355.27785-1-killertofu@gmail.com> X-Mailer: git-send-email 2.15.1 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 Touch toggle softkeys send a '1' while pressed and a '0' while released, requring the kernel to keep track of wether touch should be enabled or disabled. The code does not handle the state transitions properly, however. If the key is pressed repeatedly, the following four states of states are cycled through (assuming touch starts out enabled): Press: shared->is_touch_on => 0, SW_MUTE_DEVICE => 1 Release: shared->is_touch_on => 0, SW_MUTE_DEVICE => 1 Press: shared->is_touch_on => 1, SW_MUTE_DEVICE => 0 Release: shared->is_touch_on => 1, SW_MUTE_DEVICE => 1 The hardware always properly enables/disables touch when the key is pressed but applications that listen for SW_MUTE_DEVICE events to provide feedback about the state will only ever show touch as being enabled while the key is held, and only every-other time. This sequence occurs because the fallthrough WACOM_HID_WD_TOUCHONOFF case is always handled, and it uses the value of the *local* is_touch_on variable as the value to report to userspace. The local value is equal to the shared value when the button is pressed, but equal to zero when the button is released. Reporting the shared value to userspace fixes this problem, but the fallthrough case needs to update the shared value in an incompatible way (which is why the local variable was introduced in the first place). To work around this, we just handle both cases in a single block of code and update the shared variable as appropriate. Fixes: d793ff8187 ("HID: wacom: generic: support touch on/off softkey") Cc: # v4.12+ Signed-off-by: Jason Gerecke Reviewed-by: Aaron Skomra Tested-by: Aaron Skomra --- drivers/hid/wacom_wac.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 16af6886e828..7dbff253c05c 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1924,7 +1924,6 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field struct wacom_features *features = &wacom_wac->features; unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); int i; - bool is_touch_on = value; bool do_report = false; /* @@ -1969,16 +1968,17 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field break; case WACOM_HID_WD_MUTE_DEVICE: - if (wacom_wac->shared->touch_input && value) { - wacom_wac->shared->is_touch_on = !wacom_wac->shared->is_touch_on; - is_touch_on = wacom_wac->shared->is_touch_on; - } - - /* fall through*/ case WACOM_HID_WD_TOUCHONOFF: if (wacom_wac->shared->touch_input) { + bool *is_touch_on = &wacom_wac->shared->is_touch_on; + + if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value) + *is_touch_on = !(*is_touch_on); + else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF) + *is_touch_on = value; + input_report_switch(wacom_wac->shared->touch_input, - SW_MUTE_DEVICE, !is_touch_on); + SW_MUTE_DEVICE, !(*is_touch_on)); input_sync(wacom_wac->shared->touch_input); } break;