From patchwork Wed Mar 8 21:52:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Kramkowski X-Patchwork-Id: 9612045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5C11760414 for ; Wed, 8 Mar 2017 21:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B992285CF for ; Wed, 8 Mar 2017 21:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 403D428644; Wed, 8 Mar 2017 21:53:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 930BB2863E for ; Wed, 8 Mar 2017 21:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754594AbdCHVwx (ORCPT ); Wed, 8 Mar 2017 16:52:53 -0500 Received: from erebus.the-tk.com ([109.74.205.187]:55454 "EHLO erebus.the-tk.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754593AbdCHVww (ORCPT ); Wed, 8 Mar 2017 16:52:52 -0500 Received: from erebus.the-tk.com (localhost [127.0.0.1]) by erebus.the-tk.com (OpenSMTPD) with ESMTP id a11ea3aa; Wed, 8 Mar 2017 21:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=the-tk.com; h=from:to:cc :subject:date:message-id; s=sel0; bh=Ns1RQx/dVgsqkn9ydceMT1yX+D8 =; b=V9uiVNLe5jNyOKbB6X75bWF5KyWqJ+36FMWnuNSD8onwYVRccVOREAa9rDP mHU4tVv64+ZlJ5qtKA6UZzAF4/1eogOJQ2J2UAVP0Cw8onzxTUgUY0wJcD+OLShh 9D8CER3SBP8YDGR4iasJ9vK+wbeBR213WaSnEYfDuQ80OPK4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=the-tk.com; h=from:to:cc :subject:date:message-id; q=dns; s=sel0; b=FUKfgnXQMJ7ahKN/tqUHW tPACw+7YxCDro/QMeq+NVEnUBTGazTR1RmvBsVKj4LINzDYqBddD4TFsmc3Q+s7o 00PPE9mHqhRnyevIFsiaUMwkB6gCIXuZqcrUQG0tL5YNTRJ+Lzpta46fZ9iKNoVX 4iKj3lhIz68dNZilT0+w58= Received: from localhost (cpc1-nott20-2-0-cust508.12-2.cable.virginm.net [82.4.129.253]) by erebus.the-tk.com (OpenSMTPD) with ESMTPSA id 78c3c13a (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 8 Mar 2017 21:52:39 +0000 (UTC) From: Tomasz Kramkowski To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Tomasz Kramkowski Subject: [PATCH 1/1] HID: clamp input to logical range if no null state Date: Wed, 8 Mar 2017 21:52:11 +0000 Message-Id: <20170308215211.24263-1-tk@the-tk.com> X-Mailer: git-send-email 2.12.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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=vs.85).asp Signed-off-by: Tomasz Kramkowski --- drivers/hid/hid-input.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index cf8256aac2bd..cf38ff79cfe9 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1157,12 +1157,15 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct * 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; + if (field->flags & HID_MAIN_ITEM_NULL_STATE) { + dbg_hid("Ignoring out-of-range value %x\n", value); + return; + } + value = value < field->logical_minimum ? + field->logical_minimum : field->logical_maximum; } /*