Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: core: store the unique system identifier in hid_device

This unique identifier is currently used only for ensuring uniqueness in
sysfs. However, this could be handful for userspace to refer to a specific
hid_device by this id.

2 use cases are in my mind: LEDs (and their naming convention), and
HID-BPF.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20220902132938.2409206-9-benjamin.tissoires@redhat.com

+5 -1
+3 -1
drivers/hid/hid-core.c
··· 2739 2739 hid_warn(hdev, "bad device descriptor (%d)\n", ret); 2740 2740 } 2741 2741 2742 + hdev->id = atomic_inc_return(&id); 2743 + 2742 2744 /* XXX hack, any other cleaner solution after the driver core 2743 2745 * is converted to allow more than 20 bytes as the device name? */ 2744 2746 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, 2745 - hdev->vendor, hdev->product, atomic_inc_return(&id)); 2747 + hdev->vendor, hdev->product, hdev->id); 2746 2748 2747 2749 hid_debug_register(hdev, dev_name(&hdev->dev)); 2748 2750 ret = device_add(&hdev->dev);
+2
include/linux/hid.h
··· 658 658 struct list_head debug_list; 659 659 spinlock_t debug_list_lock; 660 660 wait_queue_head_t debug_wait; 661 + 662 + unsigned int id; /* system unique id */ 661 663 }; 662 664 663 665 #define to_hid_device(pdev) \