Received: by 10.213.65.68 with SMTP id h4csp1773745imn; Mon, 19 Mar 2018 12:54:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELtBZVrGBgAQtrEVQXHGO+EsvrT1JCvqhgmLG51bkJ2IPegRM/eNiN6ZoGvlvLzdj1Ly7goA X-Received: by 10.99.124.68 with SMTP id l4mr9980281pgn.225.1521489260075; Mon, 19 Mar 2018 12:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521489260; cv=none; d=google.com; s=arc-20160816; b=RXTbIm+hadTv9hqM1bK0OEg/h/sKlNF8d4qP7meA0T6U/5I7TmZVtc/kKPHoXWnRfZ oCA63hYVAHucz8XnRMzu4923ZY8qfV1IsH8d6eSDM7/IRMgXHkoPUuy3+X9BBfwNM6f6 wEqGWfpEGnqIyosT4KVvSMUMhzXxwTCcgEHVNnCyGCVAhOmpsZjpbwTWaEDnjiHR+jWR EIRdxYrzVaxIoIRbenGjVAe7SK+0tqmpQwvwMDk4VFoNEmeRz0vUUeojcFKLMPz5qomE moI6rNDbA17vbNu7nC4rtrRd2CFcHXRSCKdGnoGZiSOXxPXovVcnugBdeaqefxXRsbpV 9Xbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=7MrefO+rjvN91aCxnr/Unl0xbc9Yj92wAe6ULAPmXZo=; b=iMD88Ln4xMjUq/a5GzVd/Ly1ljr8Hxiah+ZH1Jy0O3LibRBtIEbmnLjasmq5YFxQq0 Da/7NlfHIRHQ7uqFUaU5iR/YINPMYeP3SHpZgsZ53mPgxy6qiB80vB95xVF+7zIcncw6 f1gaZes61B/5xu2hnBKFyMotW4aj7w86WuCmmxmZpPknppGmd8bYzuSLxUI6GlqGEuWI kmCuBErBG6w22gUdOl6fHEMFsRFGix9f/upi1a1hCnrNCiI0qwN4Wq0gIL7TKD9FZm3A uSjTP9jR1sfS+RuPZCxqf5DyUg9R/fn+Om55VML6irVvkANqJc6mKc3TbmmOUPaKEp8y 1MWQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r6-v6si580107pls.51.2018.03.19.12.54.05; Mon, 19 Mar 2018 12:54:20 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969833AbeCSTuw (ORCPT + 99 others); Mon, 19 Mar 2018 15:50:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47370 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969480AbeCSSTr (ORCPT ); Mon, 19 Mar 2018 14:19:47 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5A0C6113E; Mon, 19 Mar 2018 18:19:46 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tomasz Kramkowski , Benjamin Tissoires , Jiri Kosina , Sasha Levin Subject: [PATCH 4.9 043/241] HID: clamp input to logical range if no null state Date: Mon, 19 Mar 2018 19:05:08 +0100 Message-Id: <20180319180752.977991321@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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=vs.85).asp Signed-off-by: Tomasz Kramkowski Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-input.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1149,19 +1149,26 @@ void hidinput_hid_event(struct hid_devic /* * 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=vs.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 = clamp(value, + field->logical_minimum, + field->logical_maximum); } /*