From: Dmitry Antipov <dmantipov@yandex.ru>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, lvc-project@linuxtesting.org,
Dmitry Antipov <dmantipov@yandex.ru>
Subject: [PATCH v3 2/4] HID: roccat: use device_is_registered() to check whether device is available
Date: Wed, 16 Sep 2026 11:00:11 +0300 [thread overview]
Message-ID: <20260916080013.56388-2-dmantipov@yandex.ru> (raw)
In-Reply-To: <20260916080013.56388-1-dmantipov@yandex.ru>
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@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
next prev parent reply other threads:[~2026-09-16 8:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 8:00 [PATCH v3 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() Dmitry Antipov
2026-09-16 8:00 ` Dmitry Antipov [this message]
2026-09-16 8:09 ` [PATCH v3 2/4] HID: roccat: use device_is_registered() to check whether device is available sashiko-bot
2026-09-16 8:00 ` [PATCH v3 3/4] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-16 8:00 ` [PATCH v3 4/4] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-09-16 8:17 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916080013.56388-2-dmantipov@yandex.ru \
--to=dmantipov@yandex.ru \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox