Received: by 10.223.176.5 with SMTP id f5csp1002127wra; Fri, 2 Feb 2018 09:30:54 -0800 (PST) X-Google-Smtp-Source: AH8x2243WhP2s4CpnymC+oL8iNP+E17sgN4od63AtM21q5hI+wqnNCJaKBRiZIlaiJA1cvk48H2l X-Received: by 2002:a17:902:8487:: with SMTP id c7-v6mr26295992plo.7.1517592654405; Fri, 02 Feb 2018 09:30:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517592654; cv=none; d=google.com; s=arc-20160816; b=LavO/hA0xQ06kThEd4iEo48n/g5HJ7sJKIwpV3Kib5G80MKdiLL3bjbQOvo8KCLqsy NveCZevZzgOoJWw/hTnlglDi0lXRAb4rL94mT+mlEGva5TAYHMc3NelmyKjFHtyfguxh 3IM823vrihcRFXWru/AaIYmWveCSydd+dRxH2aG1rBDhb2rvFTti2jBjPVpLrsLeNlps sq4g8NbPL1h4bjLNxG6zMYJSgYzUVJw4xS52MV3wpVbBp04T0JEAdD6208iigyNqd/K0 6CSmlXDrmFiDuh8RuleV1G7dSe9QsIwgq4SnHI+GRMHw3gRUE2IrEsVyX1aTlAaW9ySe noHw== 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=YFj4yxccaKTZvC1+BBHC23FdfYD+lX+rj8DEkIzJIAY=; b=O7HEYqwIWy/vgDTGPIsDs9jAUaUdcxoXfLzTPvWTOwNOcERz9qEA2qvcQKHe7QOKeL EyGfMnHo7fdvuUVuvf1KW3bh4ptUR6+vxfbt525OhEe94ypBBbUnyIitpGkf9m6V92uK 0PEoEx27WLyHp6QrjN8hXm5pzvAQmCH47MEf339iECii38y9Qr0S43haEKiJ9MZWdJay odOEa8ar5MORaE3tCiErxmNhXuJDx5jVa9byEHTHSOUofo/fogORYDdquiG2sYwKzhUl IxOUaV0OSjG3uMK/4a91/NBrcsdN+vnW4aNey7aE2JmkSSoQgptWSei5017IAdjB15QN +GNg== 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 h12-v6si78702plt.241.2018.02.02.09.30.39; Fri, 02 Feb 2018 09:30:54 -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 S1754215AbeBBR2z (ORCPT + 99 others); Fri, 2 Feb 2018 12:28:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41130 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753694AbeBBRQ7 (ORCPT ); Fri, 2 Feb 2018 12:16:59 -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 F2B92BC4; Fri, 2 Feb 2018 17:16:58 +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.15 17/55] HID: wacom: Fix reporting of touch toggle (WACOM_HID_WD_MUTE_DEVICE) events Date: Fri, 2 Feb 2018 17:58:35 +0100 Message-Id: <20180202140827.932130501@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140826.117602411@linuxfoundation.org> References: <20180202140826.117602411@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.15-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;