From patchwork Wed Oct 7 23:54:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 7347741 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 450539F302 for ; Wed, 7 Oct 2015 23:54:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55F6820610 for ; Wed, 7 Oct 2015 23:54:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C94F2060E for ; Wed, 7 Oct 2015 23:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753636AbbJGXyw (ORCPT ); Wed, 7 Oct 2015 19:54:52 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:33210 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753626AbbJGXyv (ORCPT ); Wed, 7 Oct 2015 19:54:51 -0400 Received: by pacex6 with SMTP id ex6so35244028pac.0 for ; Wed, 07 Oct 2015 16:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=g0IGTXyFHCXlEuE4SQIjGxDLtQlqnvWTvZyLzeM6u0w=; b=AnaAaz7M41eEgDacdoEw6cRtqb2eM6c+62h2uuePkksDqRYoKkQVlRwy3tPyS2+Xsl odIfujWXijyQ7SCshbdjPFdngVQ3tQ2G4e0hoi0mRJHwgTTJuOZnCevdHKATSF/nNJ5I kQcl78RB9zEvTWDn8SDiR5uLvvp6MoTpWCAPu6k+uA8v1CenhTRlX5MmNT42sc9t3FEg fjZOvNKwSetmpRuWcgnyns0sckKC0QIEzTwCcIpLNxa6Vk6KILe4tB4jHycG4mFLR2kx LkZGiQEsw7gz4PqbdrpMtvVtHAjJC48sm1lLOOcUNxlmpz1YAtFQ/s66RD/dUrgGiqOZ tqNQ== X-Received: by 10.68.244.34 with SMTP id xd2mr4223536pbc.50.1444262091136; Wed, 07 Oct 2015 16:54:51 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([67.51.163.2]) by smtp.gmail.com with ESMTPSA id u3sm41586904pbs.33.2015.10.07.16.54.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Oct 2015 16:54:50 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , Ping Cheng , Aaron Skomra , expiredpopsicle@gmail.com, Jason Gerecke , Jason Gerecke Subject: [PATCH 1/2] HID: wacom: Tie cached HID_DG_CONTACTCOUNT indices to report ID Date: Wed, 7 Oct 2015 16:54:21 -0700 Message-Id: <1444262062-19247-1-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.6.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cached indicies 'cc_index' and 'cc_value_index' introduced in 1b5d514 are only valid for a single report ID. If a touchscreen has multiple reports with a HID_DG_CONTACTCOUNT usage, its possible that the values will not be correct for the report we're handling, resulting in an incorrect value for 'num_expected'. This has been observed with the Cintiq Companion 2. To address this, we store the ID of the report those indicies are valid for in a new 'cc_report' variable. Before using them to get the expected contact count, we first check if the ID of the report we're processing matches 'cc_report'. If it doesn't, we update the indicies to point to the HID_DG_CONTACTCOUNT usage of the current report (if it has one). Signed-off-by: Jason Gerecke --- Jiri, Could you please queue this patch and the next for 4.3? They fix issues with the implementation of my "Ignore contacts in excess of declared contact count" patch which was pulled in as part of the 4.3 merge window. Thanks :) drivers/hid/wacom_wac.c | 26 ++++++++++++++++++++++++++ drivers/hid/wacom_wac.h | 1 + 2 files changed, 27 insertions(+) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index c40a6d1..4140b1d 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1628,6 +1628,7 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0); break; case HID_DG_CONTACTCOUNT: + wacom_wac->hid_data.cc_report = field->report->id; wacom_wac->hid_data.cc_index = field->index; wacom_wac->hid_data.cc_value_index = usage->usage_index; break; @@ -1715,6 +1716,31 @@ static void wacom_wac_finger_pre_report(struct hid_device *hdev, struct wacom_wac *wacom_wac = &wacom->wacom_wac; struct hid_data* hid_data = &wacom_wac->hid_data; + if (hid_data->cc_report != 0 && + hid_data->cc_report != report->id) { + int i; + + hid_data->cc_report = report->id; + hid_data->cc_index = -1; + hid_data->cc_value_index = -1; + + for (i = 0; i < report->maxfield; i++) { + struct hid_field *field = report->field[i]; + int j; + + for (j = 0; j < field->maxusage; j++) { + if (field->usage[j].hid == HID_DG_CONTACTCOUNT) { + hid_data->cc_index = i; + hid_data->cc_value_index = j; + + /* break */ + i = report->maxfield; + j = field->maxusage; + } + } + } + } + if (hid_data->cc_index >= 0) { struct hid_field *field = report->field[hid_data->cc_index]; int value = field->value[hid_data->cc_value_index]; diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 1e270d4..809c03e 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -198,6 +198,7 @@ struct hid_data { int width; int height; int id; + int cc_report; int cc_index; int cc_value_index; int num_expected;