From f3e8252124543836d3361e5c03909168077131a7 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 20 Aug 2021 19:16:55 +0300 Subject: HID: core: add TransducerSerialNumber2 A recent request for change to the HID spec got approved adding support for another 4-bytes to the Transducer Serial Number. This commit adds support for the new usage. https://www.usb.org/sites/default/files/hutrr103-transducerserialnumbermoresignificantbits_0.pdf Signed-off-by: Felipe Balbi Signed-off-by: Jiri Kosina --- drivers/hid/hid-debug.c | 1 + drivers/hid/hid-input.c | 1 + 2 files changed, 2 insertions(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index fa57d05badf7..e6f18a181eb8 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -160,6 +160,7 @@ static const struct hid_usage_entry hid_usage_table[] = { {0, 0x59, "ButtonType"}, {0, 0x5A, "SecondaryBarrelSwitch"}, {0, 0x5B, "TransducerSerialNumber"}, + {0, 0x6e, "TransducerSerialNumber2"}, { 15, 0, "PhysicalInterfaceDevice" }, {0, 0x00, "Undefined"}, {0, 0x01, "Physical_Interface_Device"}, diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 4b5ebeacd283..2c72ce4147b1 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -871,6 +871,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel break; case 0x5b: /* TransducerSerialNumber */ + case 0x6e: /* TransducerSerialNumber2 */ usage->type = EV_MSC; usage->code = MSC_SERIAL; bit = input->mscbit; -- cgit v1.2.3 From a68f3bd13994b315f47ec7e4da8d1c39ba0a2bb4 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 16 Sep 2021 16:21:54 +0300 Subject: HID: hid-debug: clean up snprintf() checks in hid_resolv_usage() The snprintf() limits are complicated and slightly wrong when it does: max(0, HID_DEBUG_BUFSIZE - len - 1) The "- 1" should not be there. It means we can't use the last byte of the buffer. If we change the first snprintf() to scnprintf() then we can remove the max(). At the start of the function the strlen(buf) is going always going to be < HID_DEBUG_BUFSIZE so that is safe. If it were > HID_DEBUG_BUFSIZE then that would result in a WARN(). Signed-off-by: Dan Carpenter Signed-off-by: Jiri Kosina --- drivers/hid/hid-debug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index e6f18a181eb8..7a92e2a04a09 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -487,8 +487,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) { if (!f) { len = strlen(buf); - snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), "."); - len++; + len += scnprintf(buf + len, HID_DEBUG_BUFSIZE - len, "."); } else { seq_printf(f, "."); @@ -499,7 +498,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) { if (p->usage == (usage & 0xffff)) { if (!f) snprintf(buf + len, - max(0,HID_DEBUG_BUFSIZE - len - 1), + HID_DEBUG_BUFSIZE - len, "%s", p->description); else seq_printf(f, @@ -510,8 +509,8 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) { break; } if (!f) - snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1), - "%04x", usage & 0xffff); + snprintf(buf + len, HID_DEBUG_BUFSIZE - len, "%04x", + usage & 0xffff); else seq_printf(f, "%04x", usage & 0xffff); return buf; -- cgit v1.2.3 From 8e3cd9221c66b97c31964c013499e6c8d0f49440 Mon Sep 17 00:00:00 2001 From: Cai Huoqing Date: Wed, 22 Sep 2021 20:59:31 +0800 Subject: HID: cougar: Make use of the helper function devm_add_action_or_reset() The helper function devm_add_action_or_reset() will internally call devm_add_action(), and if devm_add_action() fails then it will execute the action mentioned and return the error code. So use devm_add_action_or_reset() instead of devm_add_action() to simplify the error handling, reduce the code. Signed-off-by: Cai Huoqing Signed-off-by: Jiri Kosina --- drivers/hid/hid-cougar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-cougar.c b/drivers/hid/hid-cougar.c index 28d671c5e0ca..cb8bd8aae15b 100644 --- a/drivers/hid/hid-cougar.c +++ b/drivers/hid/hid-cougar.c @@ -179,10 +179,9 @@ static int cougar_bind_shared_data(struct hid_device *hdev, cougar->shared = shared; - error = devm_add_action(&hdev->dev, cougar_remove_shared_data, cougar); + error = devm_add_action_or_reset(&hdev->dev, cougar_remove_shared_data, cougar); if (error) { mutex_unlock(&cougar_udev_list_lock); - cougar_remove_shared_data(cougar); return error; } -- cgit v1.2.3