From patchwork Fri Nov 12 08:11:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 70938 X-Patchwork-Delegate: apw@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 552EAB712C for ; Fri, 12 Nov 2010 19:13:13 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1PGokv-0004u5-9z; Fri, 12 Nov 2010 08:13:09 +0000 Received: from ch-smtp03.sth.basefarm.net ([80.76.149.214]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1PGoku-0004tb-7e for kernel-team@lists.ubuntu.com; Fri, 12 Nov 2010 08:13:08 +0000 Received: from c83-248-196-134.bredband.comhem.se ([83.248.196.134]:42068 helo=polaris) by ch-smtp03.sth.basefarm.net with smtp (Exim 4.68) (envelope-from ) id 1PGok7-00088R-C5 for kernel-team@lists.ubuntu.com; Fri, 12 Nov 2010 09:12:22 +0100 Received: by polaris (sSMTP sendmail emulation); Fri, 12 Nov 2010 09:12:18 +0100 From: "Henrik Rydberg" To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/5] hid: ntrig: Support single-touch devices Date: Fri, 12 Nov 2010 09:11:53 +0100 Message-Id: <1289549514-5421-5-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1289549514-5421-1-git-send-email-rydberg@euromail.se> References: <1289549514-5421-1-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.248.196.134 X-Scan-Result: No virus found in message 1PGok7-00088R-C5. X-Scan-Signature: ch-smtp03.sth.basefarm.net 1PGok7-00088R-C5 2d1efbd8d14d10b41896d9db28877c87 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: Henrik Rydberg The current driver was regressed to not work for single-touch devices, and the driver occasionally crashes in those cases. The HID report which resets the array index is never received, resulting in out-of-range memory access. This patch restores functionality by detecting the presence of the multitouch firmware, and adds a range check to make the driver resilient to unknown firmware versions. Signed-off-by: Henrik Rydberg --- drivers/hid/hid-ntrig.c | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 695fa54..05f7e27 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -50,6 +50,8 @@ struct ntrig_data { int nrow, ncol; int index, nindex; int nhold; + bool touch; + bool hasmt; }; @@ -180,7 +182,14 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, return 1; } return 0; + case 0xff000000: + switch (usage->hid) { + case 0xff000001: + /* multi-touch firmware */ + nd->hasmt = true; + break; + } /* we do not want to map these: no input-oriented meaning */ return -1; } @@ -334,7 +343,9 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, if (hid->claimed & HID_CLAIMED_INPUT) { switch (usage->hid) { case HID_DG_TIPSWITCH: - nd->index = nd->nindex++; + nd->touch = value; + if (nd->nindex < MAX_SLOTS) + nd->index = nd->nindex++; break; case HID_GD_X: nd->col[nd->index].x = value; @@ -347,8 +358,15 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, break; case HID_DG_HEIGHT: nd->col[nd->index].h = value; + if (!nd->hasmt) { + nd->nindex = 0; + nd->ncol = nd->touch; + report_frame(input, nd); + } break; case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ + if (!nd->hasmt) + break; nd->nindex = 0; nd->ncol = value; report_frame(input, nd);