Received: by 10.223.185.116 with SMTP id b49csp1077204wrg; Sat, 3 Mar 2018 14:55:48 -0800 (PST) X-Google-Smtp-Source: AG47ELtiumlauYk5O3T7dqj+P9OZ7VpntdyGsoHYjoKUF3ukHm07FdPC8vZrLpwlJLJU9WfzdS35 X-Received: by 10.101.72.136 with SMTP id n8mr8354365pgs.201.1520117748587; Sat, 03 Mar 2018 14:55:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520117748; cv=none; d=google.com; s=arc-20160816; b=Bjp2jG0lKyjprtVXQmhz9Z4WeieOBHrsk+TSWqv2/82R2fQ0XC6dGllwQW5zbtarUA acXcyXjlzttMurrwdDPghMAKyUp0wgV+Tu6sAb3ozZv9ivInf7XfF4kSxJ2T02MPuMe+ W9RAxeuNSwRZ6cqXE/IVQTt7aKqJWw4aMogZxE48oT42ZwmMgpjxA3ia+koACWl/dbTf MHX6pD7lKQkStiXKEq6eR5TNCtmK7mlsfn2SUVc1Mfpi0SUrpTeyOOTmEgH5HKfoSlRf nt2lmRCpGvP7IX55eBaPaY8G6dS0IYD/VwG8SLG6X2udTwQKAxCI+TUlsCuZzVbkFwwS lSGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Pk0YQ2PkqQ4AR9Ur4tttHpwfOOF41AmSZGh4Pjg9jG0=; b=G3PVMTsN6ZtJsyWLov7RmGW+qc8tSerozIwokgcZrKkTNhd/+v+tn9TQlB3sor/VZy FIrk16MexAp2NKH66yDS3gtMX8xuuhftHdY1iukqJLnCaN1miax0HX8R78ugzv5cvUWD n9Muc28LbNXL++m3cik3ebUxTixYnW79gzR/G1qBwQXmV/89QMXxsxJDFhrV6ffQJtIn XRYJMSqdop0mGMdJpt3wCXFyEx+3kGY7evjxtet0K/8EBLx+VUCcGNWBGjh1xWx6hfQ/ lnZqL/NU4pWUj6Wk5I7Bco38aKbV9i/6vdkPt4bCUsf/TmBUkRm2odcyPiDnO94hehUR yk2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ko9xqxP3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si2337514plj.748.2018.03.03.14.55.34; Sat, 03 Mar 2018 14:55:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ko9xqxP3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935423AbeCCWy4 (ORCPT + 99 others); Sat, 3 Mar 2018 17:54:56 -0500 Received: from mail-by2nam01on0095.outbound.protection.outlook.com ([104.47.34.95]:48488 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935378AbeCCWlC (ORCPT ); Sat, 3 Mar 2018 17:41:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Pk0YQ2PkqQ4AR9Ur4tttHpwfOOF41AmSZGh4Pjg9jG0=; b=Ko9xqxP33jxmXTYwMx94rp+l3vbPNTspJP6BWZj8BWgRa3/Eo/WaSnepQYnI9m+ATJ7s074rEJBBJJkvBLiNJMDHQPz1Y5jk5GBHxVoGVyc1YG5yMj8hpZpI9rRJ6MPM8NGuAkHUe9lu0ipMgFCwGckVllYhIf7YnKihLZ3i2DU= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB0940.namprd21.prod.outlook.com (52.132.146.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.5; Sat, 3 Mar 2018 22:40:59 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:40:59 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Tomasz Kramkowski , Jiri Kosina , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 11/63] HID: clamp input to logical range if no null state Thread-Topic: [PATCH AUTOSEL for 3.18 11/63] HID: clamp input to logical range if no null state Thread-Index: AQHTsz+eBecXbzSkjk2IF3unww8/uQ== Date: Sat, 3 Mar 2018 22:33:15 +0000 Message-ID: <20180303223228.27323-11-alexander.levin@microsoft.com> References: <20180303223228.27323-1-alexander.levin@microsoft.com> In-Reply-To: <20180303223228.27323-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB0940;7:zdmiw5t0yvJsUeaAaxAVXfPTXEj22rrFoi2Ca+ZwU8r8aDGWZfCI0HPeY06SvEUyHeEvzFd9ISSeRmJ1A4x3KNWn+9OpgkcHSLkGI37A9u0P0z0dUJDk10aa2QM6LN6+igTOBorwpV9BGo30t9r/z1sdK89hatBLqE+hgLcQudGLN7u0/nt8jlIsouzFLi6eIO3vVpG9SajuCu+1efeyIzvI+ozPZBEmk44KOTtiohH0987S1X/DTsyJuDIqHTey x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 8fd819ff-17b0-4fec-96da-08d58157d619 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:MW2PR2101MB0940; x-ms-traffictypediagnostic: MW2PR2101MB0940: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(20558992708506)(89211679590171)(176295241369792)(42068640409301); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231220)(944501244)(52105095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:MW2PR2101MB0940;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB0940; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39380400002)(346002)(366004)(39860400002)(396003)(199004)(189003)(106356001)(68736007)(6486002)(25786009)(22452003)(6436002)(186003)(2906002)(81156014)(81166006)(10090500001)(66066001)(8676002)(36756003)(6512007)(2900100001)(316002)(97736004)(102836004)(53936002)(6506007)(3280700002)(26005)(6306002)(4326008)(966005)(5250100002)(305945005)(2501003)(76176011)(2950100002)(86362001)(99286004)(3846002)(72206003)(14454004)(3660700001)(478600001)(1076002)(5660300001)(10290500003)(6666003)(6116002)(7736002)(86612001)(107886003)(110136005)(54906003)(105586002)(8936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB0940;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: McLViU+SQMn4GvuK93jB+6WfZ8azDAD5h9Rzgv+ydqwTjUfcQz8oGqVcIx7yL8pxMTNfV9WH451HOkB6MDDooEUUgFdsj6tDlI8aJxeJtEJmKKPzxr59DB4Zt2GMgmrILyWY5It9wdN/bjk+m1T26a8JurcnVSn3QYew0xsCC7I= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fd819ff-17b0-4fec-96da-08d58157d619 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:33:15.4191 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB0940 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tomasz Kramkowski [ Upstream commit c3883fe06488a483658ba5d849b70e49bee15e7c ] This patch fixes an issue in drivers/hid/hid-input.c where values outside of the logical range are not clamped when "null state" bit of the input control is not set. This was discussed on the lists [1] and this change stems from the fact due to the ambiguity of the HID specification it might be appropriate to follow Microsoft's own interpretation of the specification. As noted in Microsoft's documentation [2] in the section titled "Required HID usages for digitizers" it is noted that values reported outside the logical range "will be considered as invalid data and the value will be changed to the nearest boundary value (logical min/max)." This patch fixes an issue where the (1292:4745) Innomedia INNEX GENESIS/ATARI reports out of range values for its X and Y axis of the DPad which, due to the null state bit being unset, are forwarded to userspace as is. Now these values will get clamped to the logical range before being forwarded to userspace. This device was also used to test this patch. This patch expands on commit 3f3752705dbd ("HID: reject input outside logical range only if null state is set"). [1]: http://lkml.kernel.org/r/20170307131036.GA853@gaia.local [2]: https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v= =3Dvs.85).asp Signed-off-by: Tomasz Kramkowski Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-input.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 6d766fe2c7f4..bb870ee75a90 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1090,19 +1090,26 @@ void hidinput_hid_event(struct hid_device *hid, str= uct hid_field *field, struct =20 /* * Ignore out-of-range values as per HID specification, - * section 5.10 and 6.2.25. + * section 5.10 and 6.2.25, when NULL state bit is present. + * When it's not, clamp the value to match Microsoft's input + * driver as mentioned in "Required HID usages for digitizers": + * https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v= =3Dvs.85).asp * * The logical_minimum < logical_maximum check is done so that we * don't unintentionally discard values sent by devices which * don't specify logical min and max. */ if ((field->flags & HID_MAIN_ITEM_VARIABLE) && - (field->flags & HID_MAIN_ITEM_NULL_STATE) && - (field->logical_minimum < field->logical_maximum) && - (value < field->logical_minimum || - value > field->logical_maximum)) { - dbg_hid("Ignoring out-of-range value %x\n", value); - return; + (field->logical_minimum < field->logical_maximum)) { + if (field->flags & HID_MAIN_ITEM_NULL_STATE && + (value < field->logical_minimum || + value > field->logical_maximum)) { + dbg_hid("Ignoring out-of-range value %x\n", value); + return; + } + value =3D clamp(value, + field->logical_minimum, + field->logical_maximum); } =20 /* --=20 2.14.1