Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3586645pxb; Mon, 24 Jan 2022 12:53:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdnGL9GrLe6zlmyTXgTifCMQkqrpryYlkddj7llZ2ys+VM9vZ48OlCQH8WaEw3RbOR7jNC X-Received: by 2002:a17:90b:4a47:: with SMTP id lb7mr71200pjb.55.1643057636651; Mon, 24 Jan 2022 12:53:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057636; cv=none; d=google.com; s=arc-20160816; b=KqK+1WAkQIi8dK9vtAiJ7GhnDqjn/5Hnuh1sV6OpxEIajHs1Mr8EN4tOc6//9hTV9j E6kdd8v1aPp4Bdk7BSMSn5O/S1KA67XZ4X2aZQKB8EQoCyvBFWxXzNtmHUG+iPZEzWex CpEdsJKs8VRBWcXNkKmg6vnUhFMVNM2NoOa8mnQfKhBXbL/QEIEsxULZoG4Rok78QMLb BZeMiv8/7GFvKsGXjX3zd3IwE5ehZR786HGORH3AkD0EDF2p7SfLD8bw2QrmWHAZ497m mHZ/X+TntjGuvU5PtDWNMymRQfq5Pl/k8uV4ZJPdvkYSOFRGJCpwEDvaku/ce7veV2+H Owsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lxif3oiAJVOtkW2qh15IiqFaSBwf//TQPdgxpmlWTz8=; b=j20B9m5RLu+Iw33IHDm9grVaXk8ZTE43PRiDbeAf79m1S8/3oY7K494n3f1FvKYrvB sIWGxZevJQLL4AKW6Xa0Qaj2zgXh1graPSgJUhuU8gRT69GqlLdUQrbcXzr7IvnzQfMB Zyaz7IZ+Fnxl/ob4tbj/oq2vkSSI9XRAfBcCjzlfaQ0bQrQr5qFtBycHyyaVjUn+o158 Hgzb5ypN4bl0mqpGLG7hNCuU51kHk7sqWzyEpW7hAwJPDLVVy32WW2rUF4GmPSwdA9bh yKOhfghrnk2mV7848QIvhWcxa3sHA6uOVOG59V/LSs6uSaCRHJSQEc95aRI4HcdaFhtG YDoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T8yrmXqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t187si13082970pfb.352.2022.01.24.12.53.44; Mon, 24 Jan 2022 12:53:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T8yrmXqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380268AbiAXUQD (ORCPT + 99 others); Mon, 24 Jan 2022 15:16:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351604AbiAXTwN (ORCPT ); Mon, 24 Jan 2022 14:52:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD1A3C0617BC; Mon, 24 Jan 2022 11:25:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A67C61317; Mon, 24 Jan 2022 19:25:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B7F6C340E8; Mon, 24 Jan 2022 19:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052318; bh=3CEz9ODacc9jEscmMETRWxB3JPYlvQ03a39mjOKa3f8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T8yrmXqeQygU3F0W0YTnxdi66v0lrVjUr9YSbYVrjfGnKG9/Xoh5t6GVuA3zdN4GY +b2b3Lk3ThZbab3ND4IclJHFQcv1d7l/YrpbS06xFQGK4qNINsh/wtkGr/as1IqMtk lT/A4iV9GTBLFHQLPv6DdFJmjnAB7hRr5J5LZtW0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Gerecke , Ping Cheng , Jiri Kosina Subject: [PATCH 5.4 002/320] HID: wacom: Reset expected and received contact counts at the same time Date: Mon, 24 Jan 2022 19:39:46 +0100 Message-Id: <20220124183953.841108325@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gerecke commit 546e41ac994cc185ef3de610ca849a294b5df3ba upstream. These two values go hand-in-hand and must be valid for the driver to behave correctly. We are currently lazy about updating the values and rely on the "expected" code flow to take care of making sure they're valid at the point they're needed. The "expected" flow changed somewhat with commit f8b6a74719b5 ("HID: wacom: generic: Support multiple tools per report"), however. This led to problems with the DTH-2452 due (in part) to *all* contacts being fully processed -- even those past the expected contact count. Specifically, the received count gets reset to 0 once all expected fingers are processed, but not the expected count. The rest of the contacts in the report are then *also* processed since now the driver thinks we've only processed 0 of N expected contacts. Later commits such as 7fb0413baa7f (HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts) worked around the DTH-2452 issue by skipping the invalid contacts at the end of the report, but this is not a complete fix. The confidence flag cannot be relied on when a contact is removed (see the following patch), and dealing with that condition re-introduces the DTH-2452 issue unless we also address this contact count laziness. By resetting expected and received counts at the same time we ensure the driver understands that there are 0 more contacts expected in the report. Similarly, we also make sure to reset the received count if for some reason we're out of sync in the pre-report phase. Link: https://github.com/linuxwacom/input-wacom/issues/288 Fixes: f8b6a74719b5 ("HID: wacom: generic: Support multiple tools per report") CC: stable@vger.kernel.org Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/wacom_wac.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2664,11 +2664,14 @@ static void wacom_wac_finger_pre_report( hid_data->cc_index >= 0) { struct hid_field *field = report->field[hid_data->cc_index]; int value = field->value[hid_data->cc_value_index]; - if (value) + if (value) { hid_data->num_expected = value; + hid_data->num_received = 0; + } } else { hid_data->num_expected = wacom_wac->features.touch_max; + hid_data->num_received = 0; } } @@ -2692,6 +2695,7 @@ static void wacom_wac_finger_report(stru input_sync(input); wacom_wac->hid_data.num_received = 0; + wacom_wac->hid_data.num_expected = 0; /* keep touch state for pen event */ wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);