From patchwork Tue Jan 18 22:37:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 533213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 989D5C433F5 for ; Tue, 18 Jan 2022 22:38:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239644AbiARWiM (ORCPT ); Tue, 18 Jan 2022 17:38:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237195AbiARWiM (ORCPT ); Tue, 18 Jan 2022 17:38:12 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 555FDC061574; Tue, 18 Jan 2022 14:38:12 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id i8-20020a17090a138800b001b3936fb375so4237566pja.1; Tue, 18 Jan 2022 14:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vqR4N7krQJrOILNCzXEdQTQxOcbR9JvCWiyukEJ9ZNY=; b=OKkAj2NEFHHn8Xsv/uA8eGcjb7rHMIU9SMEWXHvaFRPdEtFCOwCcwb4IJk8eJ7I/bz 2zrzSYWXpYvvYTHM2xw89AFZ2K+S+Y9A2bR3v8VvLkWy8b071ucXYHZR92tC8o5NV8NB 8RjdsI13fkboKqizvmncCtfFDcLS1ov5d2wsCfMAOEbRRVN+qohpqPi3b7F9kbkrAySb fXZzHR126pIuF0RskYM8UrYrXkYhv6dhJRUUleanB9rVzrrBczstHfPyrtTuHfLn2IYW qf2iiA7qKBXJOPwI1/f7lWCarUM3RV7B02k12kSD3hINX4+rhZciJNDR1SmEIGbC/cTE DwkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vqR4N7krQJrOILNCzXEdQTQxOcbR9JvCWiyukEJ9ZNY=; b=xekxr5DVpV6pRio7/ADiSYqngZ2pbnPu71mWUULdzKK4uciPWj8jO9NnBVyI3K+Zh5 zIMhq2Z1FpMny8e4c7oPAcZTlwzo48NtN57hoIDSwRs8MvRBqFIVT1WL3ro2V82wHvIO exKKv/i+cfCIAtzU0Uku7DECvQyDgsMrC+p9GDBlgWTtLM8A8tcY6RTbD8JY9mb/M/3H 4Q3ReGgd38HrSva/fkkXFyNH3GrAXg8Ycu0YQswkiZ/sZmp0gMJkG2ISNqXJc2YqanIA QTrMcUY1bEniH0g3ajoysPRU6hDr7mDODtMTVXczlJfQA3wevo4Xb6q/gHKp1f+qnQMZ EaNw== X-Gm-Message-State: AOAM530N/aKVs4TyFSAi/5s4SW9TFroAHzapxOhNX3+lB33/afG1jOFw zBKkZ6wreuhtMw5nxfOFBqgk9rJ0RaY= X-Google-Smtp-Source: ABdhPJwOh8YIusc2fX/enHKj0su7dB4pzy4ncSMZAa8QHLZrMlQx9rr8dTnuXh13moQoG2yUdVbMyQ== X-Received: by 2002:a17:90b:3e8e:: with SMTP id rj14mr823152pjb.179.1642545491603; Tue, 18 Jan 2022 14:38:11 -0800 (PST) Received: from horus.lan (75-164-184-207.ptld.qwest.net. [75.164.184.207]) by smtp.gmail.com with ESMTPSA id pf16sm3433250pjb.35.2022.01.18.14.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 14:38:10 -0800 (PST) From: Jason Gerecke X-Google-Original-From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: Ping Cheng , Aaron Armstrong Skomra , Joshua Dickens , Jason Gerecke , stable@vger.kernel.org, Ping Cheng Subject: [PATCH 1/2] HID: wacom: Reset expected and received contact counts at the same time Date: Tue, 18 Jan 2022 14:37:55 -0800 Message-Id: <20220118223756.45624-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 --- drivers/hid/wacom_wac.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 2a4cc39962e7..5978399ae7d2 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2692,11 +2692,14 @@ static void wacom_wac_finger_pre_report(struct hid_device *hdev, 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; } } @@ -2724,6 +2727,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev, 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); From patchwork Tue Jan 18 22:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 533486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8A58C433FE for ; Tue, 18 Jan 2022 22:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237690AbiARWiQ (ORCPT ); Tue, 18 Jan 2022 17:38:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240802AbiARWiP (ORCPT ); Tue, 18 Jan 2022 17:38:15 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1ED0C061574; Tue, 18 Jan 2022 14:38:14 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id z17-20020a17090ab11100b001b4d8817e04so3391853pjq.2; Tue, 18 Jan 2022 14:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZbU8JFNz8EJwN7FgVu0cRZAO8izn8Kn18zUzADS8gd4=; b=qLB+fZQTeul3PaPNLzabru6EfFjb//O5L/H/oGiKJk6TaaSEMrWTOhEWbZPsWk1pjV M/HVD2P/vAS/4eRozOAAnO8w0x4yFENI/51hKy494g2CGbfV9vUIiqymYiTIiVqeWQSW WrmsgPiaf0Tf0wIk6Hc6U6qHMXSatSkClsyRzPyZRj4EkWuTOTlGOYE7wKsqTCM2tX2N wqOApjbBiBop50XZfY4uyGQLhpy71ajc8x6itLLzdFYGN8sdSC3kFDvaaTppbrRIIFya bxzEzyDMOHCsUkzMgWmLXUU4vamt9/hPXpQj0Y1QIauOwskTbI97TBfVi/DV/tdUOE/x o7PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZbU8JFNz8EJwN7FgVu0cRZAO8izn8Kn18zUzADS8gd4=; b=Y3eXMPkdO9Dug68CNxyf3afTXlP0QLvtVs7RCUjWWJX1VxSl/gaO0uCNjeMeM/CwNm vEoxlUBX4vPJRBD0U/3LiTeKe3EZpi3RsBmFlWO7T4rT0Wl6xJ9P07DFofjQetLivT0g /MUH5X9ALO6bTJK6VjF3SfMNwSMle6C/wx1EpRyA3yZ4wkEHYe6MFRLG4zVH7ppxHarx E1pGenyWk8hlMkguQMyZaPdqXNLuSgU3jyd8Io0odlMESZdNl1HzPS9FGG6BoioH1O8t PzdpVC27LYoTXAd9kIPHjO0XaU0fjYA21vjXyuUz7cJTjvzHVQKXCkC4M6FAq8y24bT/ IPqw== X-Gm-Message-State: AOAM5325y9kv6jKdwK1x1LPNFW9C60nrbZRvCELS4qNf67YQdmCu24DJ ZJV5qaZ7y2GUebwG8ERawP9ZMSKX+T4= X-Google-Smtp-Source: ABdhPJy8NmyV4OoqB4rgP4Cm4SB/wZYyrZBmDQQ3COSOsm2/hnk+FnumY4KbscTnDAiRl/RLxL/q2g== X-Received: by 2002:a17:902:bf02:b0:149:c653:22af with SMTP id bi2-20020a170902bf0200b00149c65322afmr29852473plb.139.1642545494367; Tue, 18 Jan 2022 14:38:14 -0800 (PST) Received: from horus.lan (75-164-184-207.ptld.qwest.net. [75.164.184.207]) by smtp.gmail.com with ESMTPSA id pf16sm3433250pjb.35.2022.01.18.14.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 14:38:13 -0800 (PST) From: Jason Gerecke X-Google-Original-From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: Ping Cheng , Aaron Armstrong Skomra , Joshua Dickens , Jason Gerecke , stable@vger.kernel.org, Ping Cheng Subject: [PATCH 2/2] HID: wacom: Ignore the confidence flag when a touch is removed Date: Tue, 18 Jan 2022 14:37:56 -0800 Message-Id: <20220118223756.45624-2-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118223756.45624-1-jason.gerecke@wacom.com> References: <20220118223756.45624-1-jason.gerecke@wacom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org AES hardware may internally re-classify a contact that it thought was intentional as a palm. Intentional contacts are reported as "down" with the confidence bit set. When this re-classification occurs, however, the state transitions to "up" with the confidence bit cleared. This kind of transition appears to be legal according to Microsoft docs, but we do not handle it correctly. Because the confidence bit is clear, we don't call `wacom_wac_finger_slot` and update userspace. This causes hung touches that confuse userspace and interfere with pen arbitration. This commit adds a special case to ignore the confidence flag if a contact is reported as removed. This ensures we do not leave a hung touch if one of these re-classification events occured. Ideally we'd have some way to also let userspace know that the touch has been re-classified as a palm and needs to be canceled, but that's not possible right now :) Link: https://github.com/linuxwacom/input-wacom/issues/288 Fixes: 7fb0413baa7f (HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts) CC: stable@vger.kernel.org Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng --- drivers/hid/wacom_wac.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 5978399ae7d2..92b52b1de526 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2588,6 +2588,24 @@ static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac, } } +static bool wacom_wac_slot_is_active(struct input_dev *dev, int key) +{ + struct input_mt *mt = dev->mt; + struct input_mt_slot *s; + + if (!mt) + return false; + + for (s = mt->slots; s != mt->slots + mt->num_slots; s++) { + if (s->key == key && + input_mt_get_value(s, ABS_MT_TRACKING_ID) >= 0) { + return true; + } + } + + return false; +} + static void wacom_wac_finger_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { @@ -2638,9 +2656,14 @@ static void wacom_wac_finger_event(struct hid_device *hdev, } if (usage->usage_index + 1 == field->report_count) { - if (equivalent_usage == wacom_wac->hid_data.last_slot_field && - wacom_wac->hid_data.confidence) - wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input); + if (equivalent_usage == wacom_wac->hid_data.last_slot_field) { + bool touch_removed = wacom_wac_slot_is_active(wacom_wac->touch_input, + wacom_wac->hid_data.id) && !wacom_wac->hid_data.tipswitch; + + if (wacom_wac->hid_data.confidence || touch_removed) { + wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input); + } + } } }