From patchwork Wed Sep 15 04:58:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 181732 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8F4wU23009763 for ; Wed, 15 Sep 2010 04:58:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752507Ab0IOE6a (ORCPT ); Wed, 15 Sep 2010 00:58:30 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:59575 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752054Ab0IOE63 (ORCPT ); Wed, 15 Sep 2010 00:58:29 -0400 Received: by yxp4 with SMTP id 4so2577201yxp.19 for ; Tue, 14 Sep 2010 21:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=GKvxKJdnIuqs9DXTvU5A+UwLQv1iLAZ40K24quDmJLA=; b=tHOtSInwUo02pTK1jCts4A250L1Y6mhVn6rrAqh2ThWDv8w+7d7RPq/z+NHbHxSKSC Jv+DlGRG8+Uq7cUlHlaqiMNmcVFByXLlNSjCvWhcvxP3uKaLb1C85/Aafs4oWZv1NAHX FpO+qzweROCmYDuspAfIa6tBYAFJSiQIQCvXI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=qmRnExEOuuezRIbCC2s67kQoKhugWJ78RL8O5QcDzCxuPoDjB5ZPoB1renklqbcue6 CqCOM2KJ8qmyWu2wgRuqiun9QULCFgJnt58KK62jmK6CZxx8HRNjWyYCkuvX0KukFFEn hy5Ve9jnVBY3fNqLw9wPNUzQOvQJbf5lFxYJ4= Received: by 10.100.136.10 with SMTP id j10mr1187908and.62.1284526708682; Tue, 14 Sep 2010 21:58:28 -0700 (PDT) Received: from mailhub.coreip.homeip.net (c-24-6-153-206.hsd1.ca.comcast.net [24.6.153.206]) by mx.google.com with ESMTPS id u14sm1485509ann.0.2010.09.14.21.58.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 14 Sep 2010 21:58:27 -0700 (PDT) Date: Tue, 14 Sep 2010 21:58:22 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: Linux Input , jonno.conder+bugs@gmail.com Subject: HID: Allow changing not-yet-mapped usages Message-ID: <20100915045822.GA21672@core.coreip.homeip.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 15 Sep 2010 04:58:30 +0000 (UTC) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index b12c07e..8dd17ce 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -77,7 +77,10 @@ static bool match_scancode(struct hid_usage *usage, static bool match_keycode(struct hid_usage *usage, unsigned int cur_idx, unsigned int keycode) { - return usage->code == keycode; + /* + * We should exclude unmapped usages when doing lookup by keycode. + */ + return usage->type == EV_KEY && usage->code == keycode; } static bool match_index(struct hid_usage *usage, @@ -103,7 +106,7 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid, for (i = 0; i < report->maxfield; i++) { for (j = 0; j < report->field[i]->maxusage; j++) { usage = report->field[i]->usage + j; - if (usage->type == EV_KEY) { + if (usage->type == EV_KEY || usage->type == 0) { if (match(usage, cur_idx, value)) { if (usage_idx) *usage_idx = cur_idx; @@ -144,7 +147,8 @@ static int hidinput_getkeycode(struct input_dev *dev, usage = hidinput_locate_usage(hid, ke, &index); if (usage) { - ke->keycode = usage->code; + ke->keycode = usage->type == EV_KEY ? + usage->code : KEY_RESERVED; ke->index = index; scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE); ke->len = sizeof(scancode); @@ -164,7 +168,8 @@ static int hidinput_setkeycode(struct input_dev *dev, usage = hidinput_locate_usage(hid, ke, NULL); if (usage) { - *old_keycode = usage->code; + *old_keycode = usage->type == EV_KEY ? + usage->code : KEY_RESERVED; usage->code = ke->keycode; clear_bit(*old_keycode, dev->keybit);