diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2018-09-04 09:31:13 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2018-09-04 15:32:24 -0400 |
commit | d7065620b89fcc183caa6fa6ea36de5e01211137 (patch) | |
tree | 051c42510ccaafc952deff200f010f7f1ceeb6f1 | |
parent | 71f6fa90a353605bf25c36417c9ae529ac1a9a8d (diff) |
HID: input: do not append a suffix if the name already has it
Or it creates some weird input names like:
"MI Dongle MI Wireless Mouse Mouse"
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/hid-input.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 4e94ea3e280a..83755ba33ef4 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -1516,6 +1516,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid, | |||
1516 | struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); | 1516 | struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); |
1517 | struct input_dev *input_dev = input_allocate_device(); | 1517 | struct input_dev *input_dev = input_allocate_device(); |
1518 | const char *suffix = NULL; | 1518 | const char *suffix = NULL; |
1519 | size_t suffix_len, name_len; | ||
1519 | 1520 | ||
1520 | if (!hidinput || !input_dev) | 1521 | if (!hidinput || !input_dev) |
1521 | goto fail; | 1522 | goto fail; |
@@ -1559,10 +1560,15 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid, | |||
1559 | } | 1560 | } |
1560 | 1561 | ||
1561 | if (suffix) { | 1562 | if (suffix) { |
1562 | hidinput->name = kasprintf(GFP_KERNEL, "%s %s", | 1563 | name_len = strlen(hid->name); |
1563 | hid->name, suffix); | 1564 | suffix_len = strlen(suffix); |
1564 | if (!hidinput->name) | 1565 | if ((name_len < suffix_len) || |
1565 | goto fail; | 1566 | strcmp(hid->name + name_len - suffix_len, suffix)) { |
1567 | hidinput->name = kasprintf(GFP_KERNEL, "%s %s", | ||
1568 | hid->name, suffix); | ||
1569 | if (!hidinput->name) | ||
1570 | goto fail; | ||
1571 | } | ||
1566 | } | 1572 | } |
1567 | 1573 | ||
1568 | input_set_drvdata(input_dev, hid); | 1574 | input_set_drvdata(input_dev, hid); |