[lvc-project] [PATCH 5.10/6.1/6.12 4/4] HID: roccat: avoid unlocked report buffer access in roccat_poll()
Dmitry Antipov
dmantipov at yandex.ru
Tue Nov 24 16:24:34 MSK 2026
commit 8343dd786b4725c69e4352afc5a24dd796aadbcf upstream.
Since roccat_read() and roccat_report_event() uses per-device report
buffer holding 'cbuf_lock', grab the same mutex in roccat_poll() to
avoid race against them.
Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
Link: https://patch.msgid.link/20261022054454.238343-4-dmantipov@yandex.ru
Signed-off-by: Benjamin Tissoires <bentiss at kernel.org>
---
drivers/hid/hid-roccat.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index cd7385531eb4..ddf2f7dc1f7d 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -160,12 +160,18 @@ static ssize_t roccat_read(struct file *file, char __user *buffer,
static __poll_t roccat_poll(struct file *file, poll_table *wait)
{
struct roccat_reader *reader = file->private_data;
+ bool avail;
+
poll_wait(file, &reader->device->wait, wait);
- if (reader->cbuf_start != reader->device->cbuf_end)
- return EPOLLIN | EPOLLRDNORM;
+
if (!roccat_device_available(reader->device))
return EPOLLERR | EPOLLHUP;
- return 0;
+
+ mutex_lock(&reader->device->cbuf_lock);
+ avail = (reader->cbuf_start != reader->device->cbuf_end);
+ mutex_unlock(&reader->device->cbuf_lock);
+
+ return avail ? EPOLLIN | EPOLLRDNORM : 0;
}
static int roccat_open(struct inode *inode, struct file *file)
--
2.56.1
More information about the lvc-project
mailing list