Received: by 10.223.176.5 with SMTP id f5csp1122239wra; Fri, 2 Feb 2018 11:34:01 -0800 (PST) X-Google-Smtp-Source: AH8x224CWf+ntixCjyuk5FViCpiY7SigmGSUtEuRHU8CALwP6TRW7dK8CZumSOWjtUl9UaGsLo40 X-Received: by 2002:a17:902:8546:: with SMTP id d6-v6mr20236104plo.147.1517600041201; Fri, 02 Feb 2018 11:34:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517600041; cv=none; d=google.com; s=arc-20160816; b=Q7GUQx9MBB/dgpZHDKgsxoUDd1TrhskALkzvfVndVTcvIbc0BvjsJHDV0d8ZRCSypi UDUNREUJRqOEI9a7K3bbsxY3hOAEQfwyNC58j2JJw83HueJgwFDrbxo9ZORrnMmix7MQ syj+1diG4bMTdtzV3tHX1OvTD63W7+9SK+jMDu204Zm0Z4nmBcOMmy8n1443lZarazY7 WfoqHTcTW4Y1/Mo7YwlQcaOolMr0o7pzLyk2V8rMK7ljKImPvmD05eaiwOuxD6DrZqxu A54xW4cq0Bz/BsxTZJpK//O49lRUtl+rkVz6PPawfl2c5mxL0qMmVAz7t7XIrS8SK+DD ow8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TinKj3s1gQOgx+0JnxGVAHHxiHzwU/7GV57F/8rswrI=; b=KicvVG7eZMBIw82aMeUsJ9YUzhAArMi7LoLckLJIJYNaHXwVzB1FEVm2gZxrtTcwJ/ y56luAp0eU9hYFqmC3H3YayMIN0JPZ1JTohvbqLwW8l1AbFVQ5IlF+piht8HT5OBTw4V wGlKumv2Sue/YziA2Z+raKNYnkNdm8hSCpFnU73DMZHlNfXk4cvbkedflLMfxaBWNjXN GodkSmtB1jwzYEiZLtfo5TzqwKfw2bZdb853hq3vQT/ZBVCBPAmskw0ubiWNMPSodUr6 /4qh4uejeSxkDXPWJU5+fwa/hVbV6OLLeWPtVvbfuy2gHzAwFFvPHiypL3EQF4cMaX5g 1kJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h33-v6si363589plh.78.2018.02.02.11.33.46; Fri, 02 Feb 2018 11:34:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753908AbeBBSJk (ORCPT + 99 others); Fri, 2 Feb 2018 13:09:40 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37132 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753052AbeBBRHs (ORCPT ); Fri, 2 Feb 2018 12:07:48 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2EFB5EFB; Fri, 2 Feb 2018 17:07:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Gerecke , Aaron Skomra , Jiri Kosina Subject: [PATCH 4.14 021/156] HID: wacom: Fix reporting of touch toggle (WACOM_HID_WD_MUTE_DEVICE) events Date: Fri, 2 Feb 2018 17:56:42 +0100 Message-Id: <20180202140841.282225601@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Gerecke commit 403c0f681c1964ff1db8c2fb8de8c4067779d081 upstream. 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") Signed-off-by: Jason Gerecke Reviewed-by: Aaron Skomra Tested-by: Aaron Skomra Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/wacom_wac.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1924,7 +1924,6 @@ static void wacom_wac_pad_event(struct h 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 h 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;