Skip to content

Commit

Permalink
HID: core: store the unique system identifier in hid_device
Browse files Browse the repository at this point in the history
[ Upstream commit 1e83914 ]

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 <[email protected]>
Signed-off-by: Benjamin Tissoires <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Stable-dep-of: fc43e9c ("HID: fix HID device resource race between HID core and debugging support")
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
bentiss authored and gregkh committed Dec 8, 2023
1 parent 650e43d commit 2f0ea5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2444,10 +2444,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);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,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) \
Expand Down

0 comments on commit 2f0ea5e

Please sign in to comment.