From: sashiko-bot@kernel.org
To: "Jizhou Tong" <fqwqf@fqwqf.xyz>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [RFC PATCH v3 1/5] HID: spi-hid: isolate DMA transfers from protocol buffers
Date: Thu, 05 Nov 2026 19:33:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-199924@kernel.org> (raw)
In-Reply-To: <010601a1ad2a17c0-5662bcf3-7e66-41d1-9c33-1edff447995e-000000@ap-northeast-1.amazonses.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] HID: spi-hid: TX/RX overlap in spi_hid_input_sync() if ARCH_DMA_MINALIGN < 5
--
commit 62a7cf26838a2cb27b111ff47187ee064977f44a
Author: Jizhou Tong <fqwqf@fqwqf.xyz>
HID: spi-hid: isolate DMA transfers from protocol buffers
This commit allocates a separate DMA-aligned transfer buffer in struct
spi_hid and copies TX and RX protocol data through it under io_lock to
avoid DMA mapping unaligned or adjacent protocol buffers.
> diff --git a/drivers/hid/spi-hid/spi-hid-core.c b/drivers/hid/spi-hid/spi-hid-core.c
> index f2b21066003cb..db0432251732e 100644
> --- a/drivers/hid/spi-hid/spi-hid-core.c
> +++ b/drivers/hid/spi-hid/spi-hid-core.c
> @@ -193,14 +193,19 @@ static void spi_hid_populate_output_header(u8 *buf,
> static int spi_hid_input_sync(struct spi_hid *shid, void *buf, u16 length,
> bool is_header)
> {
> + u8 *rx = shid->xfer_buf + ARCH_DMA_MINALIGN;
> int error;
>
> - shid->input_transfer[0].tx_buf = is_header ?
> - shid->read_approval_header :
> - shid->read_approval_body;
> + if (length > shid->xfer_size - ARCH_DMA_MINALIGN)
> + return -EMSGSIZE;
> +
> + memcpy(shid->xfer_buf, is_header ? shid->read_approval_header :
> + shid->read_approval_body,
> + SPI_HID_READ_APPROVAL_LEN);
> + shid->input_transfer[0].tx_buf = shid->xfer_buf;
> shid->input_transfer[0].len = SPI_HID_READ_APPROVAL_LEN;
>
> - shid->input_transfer[1].rx_buf = buf;
> + shid->input_transfer[1].rx_buf = rx;
[Severity: Medium]
Can shid->input_transfer[0].tx_buf and shid->input_transfer[1].rx_buf
overlap in spi_hid_input_sync() when ARCH_DMA_MINALIGN is smaller than
SPI_HID_READ_APPROVAL_LEN?
In drivers/hid/spi-hid/spi-hid-core.h, SPI_HID_READ_APPROVAL_LEN is 5:
#define SPI_HID_READ_APPROVAL_LEN 5
In include/linux/cache.h, architectures that do not define
ARCH_DMA_MINALIGN fall back to __alignof__(unsigned long long):
#ifdef ARCH_DMA_MINALIGN
#define ARCH_HAS_DMA_MINALIGN
#else
#define ARCH_DMA_MINALIGN __alignof__(unsigned long long)
#endif
On 32-bit architectures where 64-bit integers have 4-byte or 2-byte
alignment (such as OpenRISC or m68k), ARCH_DMA_MINALIGN evaluates to 4 or
2.
When spi_hid_dev_irq() calls spi_hid_input_sync(), the 5-byte read
approval is copied to shid->xfer_buf[0..4] for input_transfer[0].tx_buf,
while rx for input_transfer[1].rx_buf is placed at shid->xfer_buf +
ARCH_DMA_MINALIGN. If ARCH_DMA_MINALIGN is 4, both transfers in the same
spi_message share shid->xfer_buf[4] (and spi_hid_alloc_buffers() only
reserves a single ARCH_DMA_MINALIGN unit for the TX region in
shid->xfer_size).
Should spi_hid_alloc_buffers() and spi_hid_input_sync() use
ALIGN(SPI_HID_READ_APPROVAL_LEN, ARCH_DMA_MINALIGN) for the TX region size
and the rx offset instead of bare ARCH_DMA_MINALIGN?
--
Sashiko AI review · https://sashiko.dev/#/patchset/010601a1ad274a9c-ca2fc8f5-d3fb-435d-8572-c0d3eb701649-000000@ap-northeast-1.amazonses.com?part=1
next prev parent reply other threads:[~2026-11-05 19:33 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 22:25 [PATCH v5 00/11] Add spi-hid transport driver Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 01/11] Documentation: Correction in HID output_report callback description Jingyuan Liang
2026-10-09 22:29 ` sashiko-bot
2026-10-13 20:49 ` Jingyuan Liang
2026-10-12 6:04 ` Krzysztof Kozlowski
2026-10-13 20:49 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 02/11] HID: Add BUS_SPI support and define HID_SPI_DEVICE macro Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 03/11] HID: spi-hid: add transport driver skeleton for HID over SPI bus Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 04/11] HID: spi-hid: add spi-hid driver HID layer Jingyuan Liang
2026-10-09 22:42 ` sashiko-bot
2026-10-13 21:21 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 05/11] HID: spi-hid: add HID SPI protocol implementation Jingyuan Liang
2026-10-09 22:42 ` sashiko-bot
2026-10-13 22:07 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 06/11] HID: spi-hid: add spi_hid traces Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 07/11] HID: spi-hid: add ACPI support for HID over SPI Jingyuan Liang
2026-10-09 22:41 ` sashiko-bot
2026-10-13 22:15 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 08/11] HID: spi-hid: add device tree " Jingyuan Liang
2026-10-12 12:49 ` Uwe Kleine-König
2026-10-13 22:26 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 09/11] dt-bindings: input: Document hid-over-spi DT schema Jingyuan Liang
2026-10-12 6:05 ` Krzysztof Kozlowski
2026-10-13 22:28 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 10/11] HID: spi-hid: add power management implementation Jingyuan Liang
2026-10-09 22:43 ` sashiko-bot
2026-10-13 22:57 ` Jingyuan Liang
2026-10-09 22:25 ` [PATCH v5 11/11] HID: spi-hid: add panel follower support Jingyuan Liang
2026-10-09 22:36 ` sashiko-bot
2026-10-13 23:06 ` Jingyuan Liang
2026-10-10 16:57 ` [RFC PATCH 0/6] HID: spi-hid: add Romulus13 quad-SPI support on v5 fQwQf
2026-10-13 3:13 ` [RFC PATCH v2 " Jizhou Tong
2026-10-13 3:28 ` [RFC PATCH v2 1/6] HID: spi-hid: isolate DMA transfers from protocol buffers Jizhou Tong
2026-10-13 3:28 ` [RFC PATCH v2 2/6] HID: spi-hid: add spi-mem quad-SPI transfers Jizhou Tong
2026-10-13 3:28 ` [RFC PATCH v2 3/6] HID: spi-hid: assemble bounded fragmented input reports Jizhou Tong
2026-10-13 3:28 ` [RFC PATCH v2 4/6] dt-bindings: input: describe the Romulus13 QSPI touchpad Jizhou Tong
2026-10-28 17:58 ` Conor Dooley
2026-10-13 3:28 ` [RFC PATCH v2 5/6] HID: spi-hid: support " Jizhou Tong
2026-10-13 3:28 ` [RFC PATCH v2 6/6] HID: spi-hid: expose readiness for reset diagnostics Jizhou Tong
2026-11-05 19:19 ` [RFC PATCH v3 0/5] HID: spi-hid: add quad-SPI support for Romulus13 Jizhou Tong
2026-11-05 19:22 ` [RFC PATCH v3 1/5] HID: spi-hid: isolate DMA transfers from protocol buffers Jizhou Tong
2026-11-05 19:33 ` sashiko-bot [this message]
2026-11-05 19:23 ` [RFC PATCH v3 2/5] HID: spi-hid: add spi-mem quad-SPI transfers Jizhou Tong
2026-11-05 19:23 ` [RFC PATCH v3 3/5] HID: spi-hid: assemble bounded fragmented input reports Jizhou Tong
2026-11-05 19:23 ` [RFC PATCH v3 4/5] dt-bindings: input: hid-over-spi: add the Surface Laptop 7 touchpad Jizhou Tong
2026-11-06 17:43 ` Conor Dooley
2026-11-21 16:24 ` Jizhou Tong
2026-11-05 19:23 ` [RFC PATCH v3 5/5] HID: spi-hid: support the Romulus13 QSPI touchpad Jizhou Tong
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=sashiko-outbox-199924@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=fqwqf@fqwqf.xyz \
--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