HID: ignore absolute values which don't fit between logical min and max
authorJiri Kosina <jkosina@suse.cz>
Fri, 28 Oct 2011 16:15:02 +0000 (18:15 +0200)
committerJiri Kosina <jkosina@suse.cz>
Wed, 16 Nov 2011 14:00:31 +0000 (15:00 +0100)
Linux should ignore values outside logical min/max range, as they are not
meaningful. This is what at least some of other OSes do, and it also makes
sense (currently the value gets misinterpreted larger up the stack).

Reported-by: Denilson Figueiredo de Sá <denilsonsa@gmail.com>
Tested-by: Denilson Figueiredo de Sá <denilsonsa@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-input.c

index f333139..b7b0d55 100644 (file)
@@ -822,6 +822,13 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
                return;
        }
 
+       /* Ignore absolute values that are out of bounds */
+       if ((usage->type == EV_ABS && (value < field->logical_minimum ||
+                                       value > field->logical_maximum))) {
+               dbg_hid("Ignoring out-of-range value %x\n", value);
+               return;
+       }
+
        /* report the usage code as scancode if the key status has changed */
        if (usage->type == EV_KEY && !!test_bit(usage->code, input->key) != value)
                input_event(input, EV_MSC, MSC_SCAN, usage->hid);