HID: core: store the unique system identifier in hid_device
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Fri, 2 Sep 2022 13:29:23 +0000 (15:29 +0200)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Tue, 20 Sep 2022 10:53:32 +0000 (11:53 +0100)
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
drivers/hid/hid-core.c
include/linux/hid.h

index b7f5566e338d77dffb4ba48f5c817a09dcb854f0..a00dd43db8bff33c66e34a81bc5b33b18f73415d 100644 (file)
@@ -2739,10 +2739,12 @@ int hid_add_device(struct hid_device *hdev)
                        hid_warn(hdev, "bad device descriptor (%d)\n", ret);
        }
 
+       hdev->id = atomic_inc_return(&id);
+
        /* XXX hack, any other cleaner solution after the driver core
         * is converted to allow more than 20 bytes as the device name? */
        dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
-                    hdev->vendor, hdev->product, atomic_inc_return(&id));
+                    hdev->vendor, hdev->product, hdev->id);
 
        hid_debug_register(hdev, dev_name(&hdev->dev));
        ret = device_add(&hdev->dev);
index 4363a63b9775ef27e4193cd507b77394fd854b9e..a43dd17bc78fdf7f059684ada23bab66ff62a292 100644 (file)
@@ -658,6 +658,8 @@ struct hid_device {                                                 /* device report descriptor */
        struct list_head debug_list;
        spinlock_t  debug_list_lock;
        wait_queue_head_t debug_wait;
+
+       unsigned int id;                                                /* system unique id */
 };
 
 #define to_hid_device(pdev) \