HID: hid-input: avoid splitting keyboard, system and consumer controls
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 14 Jan 2021 06:24:13 +0000 (22:24 -0800)
committerJiri Kosina <jkosina@suse.cz>
Tue, 2 Feb 2021 10:10:30 +0000 (11:10 +0100)
A typical USB keyboard usually splits its keys into several reports:

- one for the basic alphanumeric keys, modifier keys, F<n> keys, six pack
  keys and keypad. This report's application is normally listed as
  GenericDesktop.Keyboard
- a GenericDesktop.SystemControl report for the system control keys, such
  as power and sleep
- Consumer.ConsumerControl report for multimedia (forward, rewind,
  play/pause, mute, etc) and other extended keys.
- additional output, vendor specific, and feature reports

Splitting each report into a separate input device is wasteful and even
hurts userspace as it makes it harder to determine the true capabilities
(set of available keys) of a keyboard, so let's adjust application
matching to merge system control and consumer control reports with
keyboard report, if one has already been processed.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-input.c

index dc7f6b4a775c982a3f966480526083287d717534..2040515d49f8a393fa00823ac910c4d0d43e8a2b 100644 (file)
@@ -1852,6 +1852,16 @@ static struct hid_input *hidinput_match_application(struct hid_report *report)
        list_for_each_entry(hidinput, &hid->inputs, list) {
                if (hidinput->application == report->application)
                        return hidinput;
+
+               /*
+                * Keep SystemControl and ConsumerControl applications together
+                * with the main keyboard, if present.
+                */
+               if ((report->application == HID_GD_SYSTEM_CONTROL ||
+                    report->application == HID_CP_CONSUMER_CONTROL) &&
+                   hidinput->application == HID_GD_KEYBOARD) {
+                       return hidinput;
+               }
        }
 
        return NULL;