Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v11 1/4] HID: hid-msi: Add MSI Claw configuration driver
Date: Fri, 29 May 2026 07:59:40 +0000	[thread overview]
Message-ID: <20260529075941.60FE61F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260529072111.7565-2-derekjohn.clark@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Mixing `goto`-based error handling with scope-based cleanup (`__free`/`guard`).
- [High] TOCTOU race condition causing lost device configuration updates.
--

commit 5c893bbc0296560ff4fc46c1a17db05f45daeaf6
Author: Derek J. Clark <derekjohn.clark@gmail.com>

HID: hid-msi: Add MSI Claw configuration driver

This commit adds a configuration HID driver for the MSI Claw series of
handheld PCs. It introduces sysfs attributes to change the gamepad mode,
M-key behavior, and perform a device reset.

> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> +static int claw_hw_output_report(struct hid_device *hdev, u8 index, u8 *data,
> +				 size_t len, unsigned int timeout)
> +{
> +	unsigned char *dmabuf __free(kfree) = NULL;
> +	u8 header[] = { CLAW_OUTPUT_REPORT_ID, 0, 0, 0x3c, index };
[ ... ]
> +	guard(mutex)(&drvdata->cfg_mutex);
> +	if (timeout) {
[ ... ]
> +	ret = hid_hw_output_report(hdev, dmabuf, CLAW_PACKET_SIZE);
> +	if (ret < 0)
> +		goto err_clear_state;

[Severity: High]
Is it intended to mix goto-based error handling with scope-based cleanup
in this function?

The cleanup subsystem guidelines mention that functions should either
convert all resources that need cleanup to scope-based cleanup, or convert
none of them. Using guard and __free alongside a goto label can create
confusing ownership and lock lifetime semantics. 

Could this be converted entirely to scope-based cleanup?

> +
> +	ret = ret == CLAW_PACKET_SIZE ? 0 : -EIO;
> +	if (ret)
> +		goto err_clear_state;
[ ... ]
> +err_clear_state:
> +	if (timeout) {
> +		guard(spinlock_irqsave)(&drvdata->cmd_lock);
> +		drvdata->waiting_cmd = CLAW_COMMAND_TYPE_NONE;
> +		drvdata->waiting_for_ack = false;
> +	}
> +
> +	return ret;
> +}
[ ... ]
> +static ssize_t gamepad_mode_store(struct device *dev, struct device_attribute *attr,
> +				  const char *buf, size_t count)
> +{
[ ... ]
> +	data[0] = ret;
> +	scoped_guard(spinlock_irqsave, &drvdata->mode_lock)
> +		data[1] = drvdata->mkeys_function;
> +
> +	ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SWITCH_MODE, data, ARRAY_SIZE(data), 0);

[Severity: High]
Does this sequence introduce a time-of-check to time-of-use race condition?

The current state of mkeys_function is read while holding mode_lock, but the
lock is released before claw_hw_output_report() acquires cfg_mutex. If two
threads concurrently write to gamepad_mode and mkeys_function, both could
read the other's state before either acquires cfg_mutex.

This could result in the second thread sending a command that uses stale
data, silently reverting the first thread's update when the device
acknowledges the command. 

Should the read of the current state and the device update be atomic under
a single lock?

> +	if (ret)
> +		return ret;
> +
> +	return count;
> +}
[ ... ]
> +static ssize_t mkeys_function_store(struct device *dev, struct device_attribute *attr,
> +				    const char *buf, size_t count)
> +{
[ ... ]
> +	scoped_guard(spinlock_irqsave, &drvdata->mode_lock)
> +		data[0] = drvdata->gamepad_mode;
> +	data[1] = ret;
> +
> +	ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SWITCH_MODE, data, ARRAY_SIZE(data), 0);

[Severity: High]
A similar sequence happens here. Can concurrent writes to these attributes
lead to lost device configuration updates due to the locks being acquired and
released separately?

> +	if (ret)
> +		return ret;
> +
> +	return count;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260529072111.7565-1-derekjohn.clark@gmail.com?part=1

  reply	other threads:[~2026-05-29  7:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29  7:21 [PATCH v11 0/4] Add MSI Claw HID Configuration Driver Derek J. Clark
2026-05-29  7:21 ` [PATCH v11 1/4] HID: hid-msi: Add MSI Claw configuration driver Derek J. Clark
2026-05-29  7:59   ` sashiko-bot [this message]
2026-05-29  7:21 ` [PATCH v11 2/4] HID: hid-msi: Add M-key mapping attributes Derek J. Clark
2026-05-29  8:40   ` sashiko-bot
2026-05-29  7:21 ` [PATCH v11 3/4] HID: hid-msi: Add RGB control interface Derek J. Clark
2026-05-29  9:13   ` sashiko-bot
2026-05-29  7:21 ` [PATCH v11 4/4] HID: hid-msi: Add Rumble Intensity Attributes Derek J. Clark
2026-05-29  9:53   ` 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=20260529075941.60FE61F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=derekjohn.clark@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox