[lvc-project] [PATCH 5.10/6.1/6.12 1/4] HID: roccat: fix device access in roccat_release()
Dmitry Antipov
dmantipov at yandex.ru
Tue Nov 24 16:24:31 MSK 2026
commit b0a42af46363b65d6e5018d971189c4882d689c3 upstream.
In roccat_release(), access the device using file-specific
reader data rather than global array, thus preventing the
case when original device was disconnected and a new device
has connected using the same slot indexed by minor number.
Reported-by: Sashiko <sashiko-bot at kernel.org>
Link: https://sashiko.dev/#/patchset/20260902094551.200587-1-dmantipov@yandex.ru?part=2
Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
Signed-off-by: Benjamin Tissoires <bentiss at kernel.org>
---
drivers/hid/hid-roccat.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 77042c7edf76..12953852b465 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -211,24 +211,19 @@ static int roccat_open(struct inode *inode, struct file *file)
static int roccat_release(struct inode *inode, struct file *file)
{
- unsigned int minor = iminor(inode);
struct roccat_reader *reader = file->private_data;
- struct roccat_device *device;
-
- mutex_lock(&devices_lock);
+ struct roccat_device *device = reader->device;
- device = devices[minor];
- if (!device) {
- mutex_unlock(&devices_lock);
- pr_emerg("roccat device with minor %d doesn't exist\n", minor);
+ if (WARN_ON(!device))
return -ENODEV;
- }
mutex_lock(&device->readers_lock);
list_del(&reader->node);
mutex_unlock(&device->readers_lock);
kfree(reader);
+ mutex_lock(&devices_lock);
+
if (!--device->open) {
/* removing last reader */
if (device->exist) {
--
2.56.1
More information about the lvc-project
mailing list