Skip to content

Commit 190d7f0

Browse files
bentissJiri Kosina
authored andcommitted
HID: input: do not increment usages when a duplicate is found
This is something that bothered us from a long time. When hid-input doesn't know how to map a usage, it uses *_MISC. But there is something else which increments the usage if the evdev code is already used. This leads to few issues: - some devices may have their ABS_X mapped to ABS_Y if they export a bad set of usages (see the DragonRise joysticks IIRC -> fixed in a specific HID driver) - *_MISC + N might (will) conflict with other defined axes (my Logitech H800 exports some multitouch axes because of that) - this prevents to freely add some new evdev usages, because "hey, my headset will now report ABS_COFFEE, and it's not coffee capable". So let's try to kill this nonsense, and hope we won't break too many devices. I my headset case, the ABS_MISC axes are created because of some proprietary usages, so we might not break that many devices. For backward compatibility, a quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE is created and can be applied to any device that needs this behavior. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent e8403b4 commit 190d7f0

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

drivers/hid/hid-input.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,31 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
11001100

11011101
set_bit(usage->type, input->evbit);
11021102

1103-
while (usage->code <= max && test_and_set_bit(usage->code, bit))
1104-
usage->code = find_next_zero_bit(bit, max + 1, usage->code);
1103+
/*
1104+
* This part is *really* controversial:
1105+
* - HID aims at being generic so we should do our best to export
1106+
* all incoming events
1107+
* - HID describes what events are, so there is no reason for ABS_X
1108+
* to be mapped to ABS_Y
1109+
* - HID is using *_MISC+N as a default value, but nothing prevents
1110+
* *_MISC+N to overwrite a legitimate even, which confuses userspace
1111+
* (for instance ABS_MISC + 7 is ABS_MT_SLOT, which has a different
1112+
* processing)
1113+
*
1114+
* If devices still want to use this (at their own risk), they will
1115+
* have to use the quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE, but
1116+
* the default should be a reliable mapping.
1117+
*/
1118+
while (usage->code <= max && test_and_set_bit(usage->code, bit)) {
1119+
if (device->quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE) {
1120+
usage->code = find_next_zero_bit(bit,
1121+
max + 1,
1122+
usage->code);
1123+
} else {
1124+
device->status |= HID_STAT_DUP_DETECTED;
1125+
goto ignore;
1126+
}
1127+
}
11051128

11061129
if (usage->code > max)
11071130
goto ignore;
@@ -1611,6 +1634,8 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
16111634
INIT_LIST_HEAD(&hid->inputs);
16121635
INIT_WORK(&hid->led_work, hidinput_led_worker);
16131636

1637+
hid->status &= ~HID_STAT_DUP_DETECTED;
1638+
16141639
if (!force) {
16151640
for (i = 0; i < hid->maxcollection; i++) {
16161641
struct hid_collection *col = &hid->collection[i];
@@ -1677,6 +1702,10 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
16771702
goto out_unwind;
16781703
}
16791704

1705+
if (hid->status & HID_STAT_DUP_DETECTED)
1706+
hid_dbg(hid,
1707+
"Some usages could not be mapped, please use HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE if this is legitimate.\n");
1708+
16801709
return 0;
16811710

16821711
out_unwind:

include/linux/hid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ struct hid_item {
345345
#define HID_QUIRK_SKIP_OUTPUT_REPORT_ID BIT(17)
346346
#define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18)
347347
#define HID_QUIRK_HAVE_SPECIAL_DRIVER BIT(19)
348+
#define HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE BIT(20)
348349
#define HID_QUIRK_FULLSPEED_INTERVAL BIT(28)
349350
#define HID_QUIRK_NO_INIT_REPORTS BIT(29)
350351
#define HID_QUIRK_NO_IGNORE BIT(30)
@@ -502,6 +503,7 @@ struct hid_output_fifo {
502503

503504
#define HID_STAT_ADDED BIT(0)
504505
#define HID_STAT_PARSED BIT(1)
506+
#define HID_STAT_DUP_DETECTED BIT(2)
505507

506508
struct hid_input {
507509
struct list_head list;

0 commit comments

Comments
 (0)