From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 3/4] HID: roccat: examine readers to check whether the device is opened
Date: Mon, 14 Sep 2026 12:53:42 +0000 [thread overview]
Message-ID: <20260914125342.9AE741F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260914120240.1625442-3-dmantipov@yandex.ru>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Caching `list_empty()` state outside `devices_lock` in `roccat_release()` creates a TOCTOU race with `roccat_open()` and `roccat_disconnect()`, leading to device state corruption and leaked hardware open counts.
--
commit 8f711f83c5a599f7dd523be3cd4112f138217007
Author: Dmitry Antipov <dmantipov@yandex.ru>
HID: roccat: examine readers to check whether the device is opened
This patch replaces the explicit open counter in struct roccat_device with
a check against list_empty(&device->readers). The goal is to determine if
active readers exist without maintaining a separate integer count.
> diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
> index 007778922c21a..d1df4ec34a1e6 100644
> --- a/drivers/hid/hid-roccat.c
> +++ b/drivers/hid/hid-roccat.c
[ ... ]
> @@ -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);
[Severity: High]
Does evaluating the list state here and dropping the lock introduce a race
condition?
If another thread calls roccat_open() before devices_lock is acquired below,
it will observe an empty list, power on the device, and add a new reader.
> 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);
> hid_hw_close(device->hid);
> }
[Severity: High]
Since this uses the cached open flag, could it unconditionally power down and
close the hardware here, cutting off the newly added reader from the
concurrent roccat_open() call?
[ ... ]
> @@ -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 {
[Severity: High]
Can a concurrent roccat_disconnect() and roccat_release() race here,
resulting in neither function closing the hardware?
If roccat_release() removes the last reader, it evaluates the local open
variable to false. If roccat_disconnect() then acquires readers_lock, it will
also evaluate open to false since the list is already empty, and it will skip
calling hid_hw_close().
When roccat_release() subsequently acquires devices_lock, it observes that
device->exist is 0 (set earlier by roccat_disconnect()) and also skips calling
hid_hw_close().
Will this result in a permanent leak of the HID hardware open count?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914120240.1625442-1-dmantipov@yandex.ru?part=3
next prev parent reply other threads:[~2026-09-14 12:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 12:02 [PATCH v2 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() Dmitry Antipov
2026-09-14 12:02 ` [PATCH v2 2/4] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-14 12:44 ` sashiko-bot
2026-09-14 12:02 ` [PATCH v2 3/4] HID: roccat: examine readers to check whether the device is opened Dmitry Antipov
2026-09-14 12:53 ` sashiko-bot [this message]
2026-09-14 12:02 ` [PATCH v2 4/4] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-09-14 13:07 ` sashiko-bot
2026-09-14 12:26 ` [PATCH v2 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() 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=20260914125342.9AE741F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.