Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v8] HID: intel-thc-hid: intel-thc: restore PRD table capacity
Date: Fri, 27 Nov 2026 15:49:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-237786@kernel.org> (raw)
In-Reply-To: <20261127234500.424242-1-emfox@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-thc-hid: stale buffer use on stopped-engine
  thc_dma_read()
--

commit 0cc3c55388fa9f5be9c9821cafb9f0a08de39647
Author: Emfox Zhou <emfox@debian.org>

HID: intel-thc-hid: intel-thc: restore PRD table capacity

This commit rebuilds PRD tables before restarting DMA engines, adds a
prd_lock mutex to serialize PRD table operations with the DMA read path,
and skips reading from stopped DMA engines via an is_started flag.

> diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
> index 01b96c00d5da7..8bff8d5b36051 100644
> --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
> +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
[ ... ]
> @@ -703,6 +762,18 @@ static int thc_dma_read(struct thc_device *dev,
>  
>  	*read_len = 0;
>  
> +	guard(mutex)(&dev->dma_ctx->prd_lock);
> +
> +	/*
> +	 * Nothing in the ring is ours until the engine is started: after a
> +	 * reset the pointers alone say nothing about what was written.
> +	 */
> +	if (!READ_ONCE(read_config->is_started)) {
> +		if (read_finished)
> +			*read_finished = 1;
> +		return 0;
> +	}

[Severity: Medium]
Can returning 0 here with *read_len = 0 and read_buff untouched cause the
RxDMA callers to re-process stale or concurrently modified buffers?

Neither handle_input_report() in pci-quicki2c.c nor
quickspi_irq_thread_handler() in pci-quickspi.c checks whether the
returned length is 0 when thc_rxdma_read_safe() returns 0:

drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c:handle_input_report() {
    ...
		ret = thc_rxdma_read_safe(qcdev->thc_hw, THC_RXDMA2, (u8 *)pkt,
					  HIDI2C_PACKET_LEN(qcdev->input_len), &report_len,
					  &rx_dma_finished);
		if (ret == -EMSGSIZE)
			continue;

		if (ret)
			return ret;

		if (!pkt->len) {
    ...
}

When a threaded IRQ drain in handle_input_report() races with
quicki2c_get_report() -> thc_swdma_read_safe() pausing THC_RXDMA2 (or with
thc_rxdma_reset()), thc_dma_read() returns 0 without writing to
qcdev->input_buf.  handle_input_report() then either replays the previous
frame in qcdev->input_buf via quicki2c_hid_send_report(), races on
qcdev->input_buf while quicki2c_get_report() writes the SWDMA response
into that same buffer, or treats a zero pkt->len as a Device-Initiated
Reset.

On the SPI side, quickspi_irq_thread_handler() passes input_len = 0 to
quickspi_handle_input_data(), where HIDSPI_INPUT_BODY_SIZE(input_len) >
buf_len is always true for buf_len == 0 and logs a spurious "Wrong input
report length" error.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127234500.424242-1-emfox@debian.org?part=1

      reply	other threads:[~2026-11-27 15:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:37 [PATCH v8] HID: intel-thc-hid: intel-thc: restore PRD table capacity Emfox Zhou
2026-11-27 15:49 ` sashiko-bot [this message]

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-237786@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=emfox@debian.org \
    --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