[lvc-project] [PATCH v3 2/4] HID: roccat: use device_is_registered() to check whether device is available
Dmitry Antipov
dmantipov at yandex.ru
Wed Sep 16 11:00:11 MSK 2026
Introduce roccat_device_available() to check whether device
is actually available (i.e. not disconnected), thus removing
explicit 'exist' flag from 'struct roccat_device'.
Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
---
v3: initial version to join the series
---
drivers/hid/hid-roccat.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 5deb6da8d4f7..454b201c0524 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -40,7 +40,6 @@ struct roccat_device {
unsigned int minor;
int report_size;
int open;
- int exist;
wait_queue_head_t wait;
struct device *dev;
struct hid_device *hid;
@@ -70,6 +69,11 @@ static struct roccat_device *devices[ROCCAT_MAX_DEVICES];
/* protects modifications of devices array */
static DEFINE_MUTEX(devices_lock);
+static bool roccat_device_available(struct roccat_device *device)
+{
+ return device->dev ? device_is_registered(device->dev) : false;
+}
+
static void roccat_free_device(struct roccat_device *device)
{
int i;
@@ -105,7 +109,7 @@ static ssize_t roccat_read(struct file *file, char __user *buffer,
retval = -ERESTARTSYS;
break;
}
- if (!device->exist) {
+ if (!roccat_device_available(device)) {
retval = -EIO;
break;
}
@@ -149,7 +153,7 @@ static __poll_t roccat_poll(struct file *file, poll_table *wait)
poll_wait(file, &reader->device->wait, wait);
if (reader->cbuf_start != reader->device->cbuf_end)
return EPOLLIN | EPOLLRDNORM;
- if (!reader->device->exist)
+ if (!roccat_device_available(reader->device))
return EPOLLERR | EPOLLHUP;
return 0;
}
@@ -231,7 +235,7 @@ static int roccat_release(struct inode *inode, struct file *file)
if (!--device->open) {
/* removing last reader */
- if (device->exist) {
+ if (roccat_device_available(device)) {
hid_hw_power(device->hid, PM_HINT_NORMAL);
hid_hw_close(device->hid);
} else {
@@ -350,7 +354,6 @@ int roccat_connect(const struct class *klass, struct hid_device *hid, int report
mutex_init(&device->cbuf_lock);
device->minor = minor;
device->hid = hid;
- device->exist = 1;
device->cbuf_end = 0;
device->report_size = report_size;
@@ -369,10 +372,8 @@ void roccat_disconnect(int minor)
mutex_lock(&devices_lock);
device = devices[minor];
- device->exist = 0; /* TODO exist maybe not needed */
-
device_destroy(device->dev->class, MKDEV(roccat_major, minor));
-
+ device->dev = NULL;
devices[minor] = NULL;
if (device->open) {
--
2.55.0
More information about the lvc-project
mailing list