@@ -1364,6 +1364,30 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
13641364 return ;
13651365 }
13661366
1367+ /*
1368+ * Ignore out-of-range values as per HID specification,
1369+ * section 5.10 and 6.2.25, when NULL state bit is present.
1370+ * When it's not, clamp the value to match Microsoft's input
1371+ * driver as mentioned in "Required HID usages for digitizers":
1372+ * https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v=vs.85).asp
1373+ *
1374+ * The logical_minimum < logical_maximum check is done so that we
1375+ * don't unintentionally discard values sent by devices which
1376+ * don't specify logical min and max.
1377+ */
1378+ if ((field -> flags & HID_MAIN_ITEM_VARIABLE ) &&
1379+ field -> logical_minimum < field -> logical_maximum ) {
1380+ if (field -> flags & HID_MAIN_ITEM_NULL_STATE &&
1381+ (value < field -> logical_minimum ||
1382+ value > field -> logical_maximum )) {
1383+ dbg_hid ("Ignoring out-of-range value %x\n" , value );
1384+ return ;
1385+ }
1386+ value = clamp (value ,
1387+ field -> logical_minimum ,
1388+ field -> logical_maximum );
1389+ }
1390+
13671391 switch (usage -> hid ) {
13681392 case HID_DG_INVERT :
13691393 * quirks = value ? (* quirks | HID_QUIRK_INVERT ) : (* quirks & ~HID_QUIRK_INVERT );
@@ -1431,30 +1455,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
14311455 break ;
14321456 }
14331457
1434- /*
1435- * Ignore out-of-range values as per HID specification,
1436- * section 5.10 and 6.2.25, when NULL state bit is present.
1437- * When it's not, clamp the value to match Microsoft's input
1438- * driver as mentioned in "Required HID usages for digitizers":
1439- * https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v=vs.85).asp
1440- *
1441- * The logical_minimum < logical_maximum check is done so that we
1442- * don't unintentionally discard values sent by devices which
1443- * don't specify logical min and max.
1444- */
1445- if ((field -> flags & HID_MAIN_ITEM_VARIABLE ) &&
1446- (field -> logical_minimum < field -> logical_maximum )) {
1447- if (field -> flags & HID_MAIN_ITEM_NULL_STATE &&
1448- (value < field -> logical_minimum ||
1449- value > field -> logical_maximum )) {
1450- dbg_hid ("Ignoring out-of-range value %x\n" , value );
1451- return ;
1452- }
1453- value = clamp (value ,
1454- field -> logical_minimum ,
1455- field -> logical_maximum );
1456- }
1457-
14581458 /*
14591459 * Ignore reports for absolute data if the data didn't change. This is
14601460 * not only an optimization but also fixes 'dead' key reports. Some
0 commit comments