Skip to content

Commit c554bb0

Browse files
bentissJiri Kosina
authored andcommitted
HID: input: append a suffix matching the application
Given that we create one input node per application, we should name the input node accordingly to not lose userspace. Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent f07b3c1 commit c554bb0

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

drivers/hid/hid-input.c

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,15 +1500,56 @@ static void report_features(struct hid_device *hid)
15001500
}
15011501
}
15021502

1503-
static struct hid_input *hidinput_allocate(struct hid_device *hid)
1503+
static struct hid_input *hidinput_allocate(struct hid_device *hid,
1504+
unsigned int application)
15041505
{
15051506
struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
15061507
struct input_dev *input_dev = input_allocate_device();
1507-
if (!hidinput || !input_dev) {
1508-
kfree(hidinput);
1509-
input_free_device(input_dev);
1510-
hid_err(hid, "Out of memory during hid input probe\n");
1511-
return NULL;
1508+
const char *suffix = NULL;
1509+
1510+
if (!hidinput || !input_dev)
1511+
goto fail;
1512+
1513+
if ((hid->quirks & HID_QUIRK_INPUT_PER_APP) &&
1514+
hid->maxapplication > 1) {
1515+
switch (application) {
1516+
case HID_GD_KEYBOARD:
1517+
suffix = "Keyboard";
1518+
break;
1519+
case HID_GD_KEYPAD:
1520+
suffix = "Keypad";
1521+
break;
1522+
case HID_GD_MOUSE:
1523+
suffix = "Mouse";
1524+
break;
1525+
case HID_DG_STYLUS:
1526+
suffix = "Pen";
1527+
break;
1528+
case HID_DG_TOUCHSCREEN:
1529+
suffix = "Touchscreen";
1530+
break;
1531+
case HID_DG_TOUCHPAD:
1532+
suffix = "Touchpad";
1533+
break;
1534+
case HID_GD_SYSTEM_CONTROL:
1535+
suffix = "System Control";
1536+
break;
1537+
case HID_CP_CONSUMER_CONTROL:
1538+
suffix = "Consumer Control";
1539+
break;
1540+
case HID_GD_WIRELESS_RADIO_CTLS:
1541+
suffix = "Wireless Radio Control";
1542+
break;
1543+
default:
1544+
break;
1545+
}
1546+
}
1547+
1548+
if (suffix) {
1549+
hidinput->name = kasprintf(GFP_KERNEL, "%s %s",
1550+
hid->name, suffix);
1551+
if (!hidinput->name)
1552+
goto fail;
15121553
}
15131554

15141555
input_set_drvdata(input_dev, hid);
@@ -1518,7 +1559,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid)
15181559
input_dev->setkeycode = hidinput_setkeycode;
15191560
input_dev->getkeycode = hidinput_getkeycode;
15201561

1521-
input_dev->name = hid->name;
1562+
input_dev->name = hidinput->name ? hidinput->name : hid->name;
15221563
input_dev->phys = hid->phys;
15231564
input_dev->uniq = hid->uniq;
15241565
input_dev->id.bustype = hid->bus;
@@ -1533,6 +1574,12 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid)
15331574
INIT_LIST_HEAD(&hidinput->reports);
15341575

15351576
return hidinput;
1577+
1578+
fail:
1579+
kfree(hidinput);
1580+
input_free_device(input_dev);
1581+
hid_err(hid, "Out of memory during hid input probe\n");
1582+
return NULL;
15361583
}
15371584

15381585
static bool hidinput_has_been_populated(struct hid_input *hidinput)
@@ -1578,6 +1625,7 @@ static void hidinput_cleanup_hidinput(struct hid_device *hid,
15781625

15791626
list_del(&hidinput->list);
15801627
input_free_device(hidinput->input);
1628+
kfree(hidinput->name);
15811629

15821630
for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
15831631
if (k == HID_OUTPUT_REPORT &&
@@ -1646,6 +1694,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
16461694
struct hid_driver *drv = hid->driver;
16471695
struct hid_report *report;
16481696
struct hid_input *next, *hidinput = NULL;
1697+
unsigned int application;
16491698
int i, k;
16501699

16511700
INIT_LIST_HEAD(&hid->inputs);
@@ -1678,6 +1727,8 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
16781727
if (!report->maxfield)
16791728
continue;
16801729

1730+
application = report->application;
1731+
16811732
/*
16821733
* Find the previous hidinput report attached
16831734
* to this report id.
@@ -1689,7 +1740,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
16891740
hidinput = hidinput_match_application(report);
16901741

16911742
if (!hidinput) {
1692-
hidinput = hidinput_allocate(hid);
1743+
hidinput = hidinput_allocate(hid, application);
16931744
if (!hidinput)
16941745
goto out_unwind;
16951746
}

include/linux/hid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ struct hid_input {
512512
struct list_head list;
513513
struct hid_report *report;
514514
struct input_dev *input;
515+
const char *name;
515516
bool registered;
516517
struct list_head reports; /* the list of reports */
517518
};

0 commit comments

Comments
 (0)