From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v4 3/5] HID: intel-thc-hid: intel-ipts: register the HID device
Date: Sat, 14 Nov 2026 21:54:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-215052@kernel.org> (raw)
In-Reply-To: <20261114214026.2809740-4-emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-thc-hid: broken feature_seq check in
thc_ipts_get_feature()
--
commit 933c7f8eb6c2821b64a9386be774666dc0883345
Author: Emfox Zhou <emfox@debian.org>
HID: intel-thc-hid: intel-ipts: register the HID device
This commit registers a HID device for the IPTS port and implements report
descriptor parsing, input report forwarding, and raw feature/output report
requests over DMA.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index b48199448dbec..80973944a8994 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> +/* The report is collected in a private buffer; the caller copies it out. */
> +static void thc_ipts_feature(struct thc_ipts *idev, const u8 *data,
> + size_t len)
> +{
> + if (!len)
> + return;
> +
> + /*
> + * A request that timed out is dropped by the sender, which may be
> + * asking for another report by now: check and copy in one step. The
> + * serial number tells an earlier answer from the one asked for.
> + */
> + spin_lock_irq(&idev->feature_lock);
> + if (!idev->feature_pending ||
> + (idev->feature_id && data[0] != idev->feature_id)) {
> + spin_unlock_irq(&idev->feature_lock);
> + return;
> + }
> +
> + len = min(len, idev->max_rx);
> + memcpy(idev->feature, data, len);
> + idev->feature_len = len;
> + idev->feature_pending = false;
> + idev->feature_ack = idev->feature_seq;
> + WRITE_ONCE(idev->feature_done, true);
> + spin_unlock_irq(&idev->feature_lock);
> +
> + wake_up(&idev->wq);
> +}
[ ... ]
> +/*
> + * A feature report is not pushed by the controller: it is asked for and comes
> + * back as a frame of its own, so the request waits for the handler.
> + */
> +static int thc_ipts_get_feature(struct thc_ipts *idev, unsigned char reportnum,
> + u8 *buf, size_t len)
> +{
> + int ret = -ETIMEDOUT;
> + unsigned long timeout = msecs_to_jiffies(THC_IPTS_REQ_TIMEOUT_MS);
> + unsigned int seq;
> + int try;
> +
> + guard(mutex)(&idev->req_lock);
> +
> + /*
> + * The same report may be asked for twice in a row and the answer to
> + * the first request can still be in flight: the ID alone cannot tell
> + * the two apart, so every request carries a serial number.
> + */
> + spin_lock_irq(&idev->feature_lock);
> + WRITE_ONCE(idev->feature_done, false);
> + idev->feature_id = reportnum;
> + idev->feature_pending = true;
> + seq = ++idev->feature_seq;
> + spin_unlock_irq(&idev->feature_lock);
> +
> + for (try = 0; try < THC_IPTS_REQ_TRIES; try++) {
> + ret = thc_ipts_send(idev, THC_IPTS_TX_GET_FEATURE, &reportnum,
> + 1);
> + if (ret)
> + break;
> +
> + if (wait_event_timeout(idev->wq,
> + READ_ONCE(idev->feature_done) &&
> + READ_ONCE(idev->feature_ack) == seq,
> + timeout)) {
> + ret = 0;
> + break;
> + }
> +
> + ret = -ETIMEDOUT;
> + }
[Severity: Medium]
Can idev->feature_seq distinguish a delayed reply to an earlier request from
the current request?
thc_ipts_get_feature() only transmits reportnum on the wire, and
thc_ipts_feature() unconditionally sets idev->feature_ack = idev->feature_seq
whenever a matching report ID arrives while idev->feature_pending is true.
Because idev->feature_seq is only updated under idev->req_lock at the start
of thc_ipts_get_feature(), a late reply from a timed-out request for the
same report ID will be stamped with the new request's sequence number and
consumed as the new answer.
In addition, idev->feature_done and idev->feature_pending are initialized
once before the retry loop rather than on each attempt. If
wait_event_timeout() expires on try 0 and the delayed reply arrives just as
try 1 begins, thc_ipts_feature() sets feature_done = true and
feature_pending = false before try 1 calls thc_ipts_send(). Try 1 then
sends a duplicate THC_IPTS_TX_GET_FEATURE frame before checking
feature_done, leaving an extra reply in flight (or failing the request if
thc_ipts_send() returns an error even though the reply already arrived).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114214026.2809740-1-emfox@debian.org?part=3
next prev parent reply other threads:[~2026-11-14 21:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 21:40 [PATCH v4 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-14 21:40 ` [PATCH v4 1/5] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-14 21:40 ` [PATCH v4 2/5] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-14 22:00 ` sashiko-bot
2026-11-14 21:40 ` [PATCH v4 3/5] HID: intel-thc-hid: intel-ipts: register the HID device Emfox Zhou
2026-11-14 21:54 ` sashiko-bot [this message]
2026-11-14 21:40 ` [PATCH v4 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-14 21:40 ` [PATCH v4 5/5] HID: intel-thc-hid: intel-ipts: document the IPTS mode Emfox Zhou
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-215052@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 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.