From patchwork Wed Feb 6 11:10:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 2103681 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 623FDDF2A1 for ; Wed, 6 Feb 2013 11:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753243Ab3BFLTM (ORCPT ); Wed, 6 Feb 2013 06:19:12 -0500 Received: from mail-wi0-f177.google.com ([209.85.212.177]:44345 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753171Ab3BFLTK (ORCPT ); Wed, 6 Feb 2013 06:19:10 -0500 Received: by mail-wi0-f177.google.com with SMTP id hm14so1438579wib.10 for ; Wed, 06 Feb 2013 03:19:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:date:message-id:x-mailer; bh=XIiF80GYETJWOfra1rDdRddFJQcXAE3jOwUvYPkDgN4=; b=uSsvi4b3nHnuVjx82mJd3rNUHEVI4+Ym7gpfNpLEM93w5bn3UEQlrW491r390EQs+z SMg9/zyNRrwOJSyJr1G0GKQNEFUMeAVHU1vsIgfPih12qo2+Obtx6iyhRilQersOGxEb EzdEvR2aYyZ0Z+EL7Joj0+SfbT/SdY3kpCZj8ObD/WPmD7nP5l79vyvCKl6ErCXAe0Gm 49tkKAPU2UOJKW3RhEUI0EvakYNcxbkQxqFTtVk/9OncmBa7kollbJugVzmj1WFuIWV4 U+bm9QoMdl69DdSmp2RFrRP1N9iIVbvLmf1+DFPBTE6ifpi4r4ha7VPuCT6GgUjXQpGl Uxvg== X-Received: by 10.180.107.67 with SMTP id ha3mr4312536wib.2.1360149052657; Wed, 06 Feb 2013 03:10:52 -0800 (PST) Received: from localhost.localdomain.com (lan31-8-82-247-176-67.fbx.proxad.net. [82.247.176.67]) by mx.google.com with ESMTPS id cu7sm2259627wib.8.2013.02.06.03.10.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 03:10:51 -0800 (PST) From: Benjamin Tissoires To: Benjamin Tissoires , Henrik Rydberg , Jiri Kosina , Stephane Chatty , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: multitouch: do not use pointers towards hid-core Date: Wed, 6 Feb 2013 12:10:47 +0100 Message-Id: <1360149047-23061-1-git-send-email-benjamin.tissoires@gmail.com> X-Mailer: git-send-email 1.8.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The previous implementation registered a pointer towards hid-core to the value of contact count. This is not safe and may be difficult to debug if hid-core ever changes its implementation. The use of regular indexes is a better choice. Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-multitouch.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 28af54f..e22fbd3 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -84,7 +84,8 @@ struct mt_device { struct mt_class mtclass; /* our mt device class */ struct mt_fields *fields; /* temporary placeholder for storing the multitouch fields */ - __s32 *contactcount; /* contact count value in the report */ + int cc_index; /* contact count field index in the report */ + int cc_value_index; /* contact count value index in the field */ unsigned last_field_index; /* last field index of the report */ unsigned last_slot_field; /* the last field of a slot */ unsigned mt_report_id; /* the report ID of the multitouch device */ @@ -269,7 +270,7 @@ static ssize_t mt_set_quirks(struct device *dev, td->mtclass.quirks = val; - if (!td->contactcount) + if (td->cc_index < 0) td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; return count; @@ -483,7 +484,8 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, td->last_field_index = field->index; return 1; case HID_DG_CONTACTCOUNT: - td->contactcount = field->value + usage->usage_index; + td->cc_index = field->index; + td->cc_value_index = usage->usage_index; td->last_field_index = field->index; return 1; case HID_DG_CONTACTMAX: @@ -701,8 +703,12 @@ static void mt_report(struct hid_device *hid, struct hid_report *report) * Includes multi-packet support where subsequent * packets are sent with zero contactcount. */ - if (td->contactcount && *td->contactcount) - td->num_expected = *td->contactcount; + if (td->cc_index >= 0) { + struct hid_field *field = report->field[td->cc_index]; + int value = field->value[td->cc_value_index]; + if (value) + td->num_expected = value; + } for (r = 0; r < report->maxfield; r++) { field = report->field[r]; @@ -786,7 +792,7 @@ static void mt_post_parse(struct mt_device *td) td->last_slot_field = f->usages[field_count_per_touch - 1]; } - if (!td->contactcount) + if (td->cc_index < 0) cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; } @@ -845,6 +851,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) td->mtclass = *mtclass; td->inputmode = -1; td->maxcontact_report_id = -1; + td->cc_index = -1; hid_set_drvdata(hdev, td); td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);