From: sashiko-bot@kernel.org
To: "Jingyuan Liang" <jingyliang@chromium.org>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v4 07/11] HID: spi_hid: add ACPI support for SPI over HID
Date: Tue, 09 Jun 2026 05:01:21 +0000 [thread overview]
Message-ID: <20260609050122.480F71F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-send-upstream-v4-7-b843d5e6ced3@chromium.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] spi_hid_acpi_deassert_reset() silently fails to execute the ACPI _RST method, breaking device initialization.
- [High] Use-After-Free due to flawed cleanup ordering: the reset workqueue is cancelled before the HID device is destroyed.
- [High] The shared buffer `shid->response` is read without holding `output_lock`, leading to data corruption if concurrent HID requests occur.
--
commit 8f475e9d4e137ed8f5267ef4406acd64e1baca61
Author: Angela Czubak <acz@semihalf.com>
Subject: HID: spi_hid: add ACPI support for SPI over HID
This commit detects and adds ACPI support for SPI HID devices.
> diff --git a/drivers/hid/spi-hid/spi-hid-acpi.c b/drivers/hid/spi-hid/spi-hid-acpi.c
> new file mode 100644
> index 0000000000000..298e3ba44d8a0
> --- /dev/null
> +++ b/drivers/hid/spi-hid/spi-hid-acpi.c
> @@ -0,0 +1,253 @@
[ ... ]
> +static int spi_hid_acpi_deassert_reset(struct spihid_ops *ops)
> +{
> + struct spi_hid_acpi_config *conf = container_of(ops,
> + struct spi_hid_acpi_config,
> + ops);
> +
> + return device_reset(&conf->adev->dev);
[Severity: High]
Does device_reset() work correctly here?
Since conf->adev->dev is the internal ACPI device structure without its fwnode
set, ACPI_HANDLE() will return null, causing __device_reset() to skip the ACPI
reset.
Also, looking at spi_hid_dev_init(), the return value of deassert_reset()
is ignored:
drivers/hid/spi-hid/spi-hid-core.c:spi_hid_dev_init() {
...
shid->ops->deassert_reset(shid->ops);
...
}
Should it evaluate _RST directly or use &spi->dev instead, and should the
return value be checked to prevent hardware reset from silently failing?
> +}
[Severity: High]
Can the cleanup ordering lead to a use-after-free regression during removal?
In spi_hid_core_remove(), cancel_work_sync() is called before
spi_hid_stop_hid():
drivers/hid/spi-hid/spi-hid-core.c:spi_hid_core_remove() {
...
cancel_work_sync(&shid->reset_work);
spi_hid_stop_hid(shid);
...
}
Since spi_hid_stop_hid() calls hid_destroy_device(), the HID device is still
accessible to userspace between the work cancellation and device destruction.
If a userspace process concurrently issues an ioctl during this window,
spi_hid_sync_request() will timeout, and the error handler in
spi_hid_get_request() could incorrectly schedule reset_work. Once removal
finishes and devm frees the shid structure, could the mistakenly scheduled
work execute and dereference the freed shid pointer?
Should spi_hid_stop_hid() be called before cancel_work_sync() to prevent this?
[Severity: High]
Can the shared buffer shid->response be read while corrupted if concurrent
HID requests occur?
In spi_hid_sync_request(), output_lock is acquired via scoped guard and is
implicitly released upon function return:
drivers/hid/spi-hid/spi-hid-core.c:spi_hid_sync_request() {
...
guard(mutex)(&shid->output_lock);
...
}
Functions like spi_hid_ll_raw_request() call into spi_hid_sync_request()
and then read from shid->response after the lock has been released:
drivers/hid/spi-hid/spi-hid-core.c:spi_hid_ll_raw_request() {
...
ret = spi_hid_sync_request(shid, ...);
...
ret = min_t(size_t, len,
(shid->response->body[1] | (shid->response->body[2] << 8)) + 1);
buf[0] = shid->response->body[3];
memcpy(&buf[1], &shid->response->content, ret);
...
}
If multiple threads concurrently issue ioctls, could the second thread acquire
output_lock and overwrite shid->response with its own data before the first
thread has finished reading it?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-send-upstream-v4-0-b843d5e6ced3@chromium.org?part=7
next prev parent reply other threads:[~2026-06-09 5:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 4:40 [PATCH v4 00/11] Add spi-hid transport driver Jingyuan Liang
2026-06-09 4:40 ` [PATCH v4 01/11] Documentation: Correction in HID output_report callback description Jingyuan Liang
2026-06-09 4:40 ` [PATCH v4 02/11] HID: Add BUS_SPI support and define HID_SPI_DEVICE macro Jingyuan Liang
2026-06-09 4:40 ` [PATCH v4 03/11] HID: spi-hid: add transport driver skeleton for HID over SPI bus Jingyuan Liang
2026-06-09 4:56 ` sashiko-bot
2026-06-09 4:40 ` [PATCH v4 04/11] HID: spi-hid: add spi-hid driver HID layer Jingyuan Liang
2026-06-09 4:54 ` sashiko-bot
2026-06-09 4:40 ` [PATCH v4 05/11] HID: spi-hid: add HID SPI protocol implementation Jingyuan Liang
2026-06-09 5:00 ` sashiko-bot
2026-06-09 4:40 ` [PATCH v4 06/11] HID: spi_hid: add spi_hid traces Jingyuan Liang
2026-06-09 4:55 ` sashiko-bot
2026-06-09 4:40 ` [PATCH v4 07/11] HID: spi_hid: add ACPI support for SPI over HID Jingyuan Liang
2026-06-09 5:01 ` sashiko-bot [this message]
2026-06-09 4:40 ` [PATCH v4 08/11] HID: spi_hid: add device tree " Jingyuan Liang
2026-06-09 4:54 ` sashiko-bot
2026-06-09 4:41 ` [PATCH v4 09/11] dt-bindings: input: Document hid-over-spi DT schema Jingyuan Liang
2026-06-09 4:50 ` sashiko-bot
2026-06-09 4:41 ` [PATCH v4 10/11] HID: spi-hid: add power management implementation Jingyuan Liang
2026-06-09 5:00 ` sashiko-bot
2026-06-09 4:41 ` [PATCH v4 11/11] HID: spi-hid: add panel follower support Jingyuan Liang
2026-06-09 4:58 ` 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=20260609050122.480F71F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jingyliang@chromium.org \
--cc=linux-input@vger.kernel.org \
--cc=robh@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