[PATCH v2 3/4] HID: roccat: examine readers to check whether the device is opened
From: Dmitry Antipov <hidden>
Date: 2026-09-14 12:10:34
Subsystem:
hid core layer, roccat drivers, the rest · Maintainers:
Jiri Kosina, Benjamin Tissoires, Stefan Achatz, Linus Torvalds
Use list_empty() to check whether the device has active readers, thus dropping explicit 'open' flag from 'struct roccat_device'. Signed-off-by: Dmitry Antipov <redacted> --- v2: initial version to join the series --- drivers/hid/hid-roccat.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 007778922c21..d1df4ec34a1e 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c@@ -39,7 +39,6 @@ struct roccat_report { struct roccat_device { unsigned int minor; int report_size; - int open; int exist; wait_queue_head_t wait; struct device *dev;
@@ -177,18 +176,15 @@ static int roccat_open(struct inode *inode, struct file *file) mutex_lock(&device->readers_lock); - if (!device->open++) { + if (list_empty(&device->readers)) { /* power on device on adding first reader */ error = hid_hw_power(device->hid, PM_HINT_FULLON); - if (error < 0) { - --device->open; + if (error < 0) goto exit_err_readers; - } error = hid_hw_open(device->hid); if (error < 0) { hid_hw_power(device->hid, PM_HINT_NORMAL); - --device->open; goto exit_err_readers; } }
@@ -213,18 +209,20 @@ static int roccat_release(struct inode *inode, struct file *file) { struct roccat_reader *reader = file->private_data; struct roccat_device *device = reader->device; + bool open; if (WARN_ON_ONCE(!device)) return -ENODEV; mutex_lock(&device->readers_lock); list_del(&reader->node); + open = !list_empty(&device->readers); mutex_unlock(&device->readers_lock); kfree(reader); mutex_lock(&devices_lock); - if (!--device->open) { + if (!open) { /* removing last reader */ if (device->exist) { hid_hw_power(device->hid, PM_HINT_NORMAL);
@@ -360,6 +358,7 @@ EXPORT_SYMBOL_GPL(roccat_connect); void roccat_disconnect(int minor) { struct roccat_device *device; + bool open; mutex_lock(&devices_lock); device = devices[minor];
@@ -370,7 +369,11 @@ void roccat_disconnect(int minor) devices[minor] = NULL; - if (device->open) { + mutex_lock(&device->readers_lock); + open = !list_empty(&device->readers); + mutex_unlock(&device->readers_lock); + + if (open) { hid_hw_close(device->hid); wake_up_interruptible(&device->wait); } else {
--
2.55.0