From: sashiko-bot@kernel.org
To: "Erlend Jacobsen" <erlendjacobsen@pm.me>, linux-input@vger.kernel.org
Cc: dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3] HID: rdmctmzt: add RDMCTMZT keyboard battery driver
Date: Mon, 23 Nov 2026 17:49:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-229783@kernel.org> (raw)
In-Reply-To: <20261123-b4-rdmctmzt-v3-1-5ce2359df0aa@pm.me>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: rdmctmzt: split-lock rdm->link update in
rdm_dongle_linked()
--
commit 6c486e725a5b70b38d74595b3572ef11e0c655ce
Author: Erlend Jacobsen <erlendjacobsen@pm.me>
HID: rdmctmzt: add RDMCTMZT keyboard battery driver
This commit adds a HID driver for RDMCTMZT keyboards and their 2.4 GHz
dongles to poll battery status over the vendor HID interface and report
wireless link status.
> diff --git a/drivers/hid/hid-rdmctmzt.c b/drivers/hid/hid-rdmctmzt.c
> new file mode 100644
> index 0000000000000..fc740c7a4e482
> --- /dev/null
> +++ b/drivers/hid/hid-rdmctmzt.c
[ ... ]
> +/* The dongle's link byte, asked for now: an 0xd0 may have been missed */
> +static int rdm_dongle_linked(struct rdm_device *rdm, bool *linked)
> +{
> + u8 reply[RDM_ANSWER_LEN];
> + int ret;
> +
> + ret = rdm_command(rdm, RDM_DONGLE_STATUS, reply);
> + if (ret == -ESHUTDOWN)
> + return ret;
> +
> + scoped_guard(spinlock_irqsave, &rdm->lock) {
> + if (!ret)
> + rdm->link = reply[RDM_LINK_BYTE];
> + *linked = rdm_link_may_be_up(rdm->link);
> + }
> + if (ret)
> + hid_dbg(rdm->hdev, "no link status: %d\n", ret);
> + return 0;
> +}
[ ... ]
> +static int rdm_raw_event(struct hid_device *hdev, struct hid_report *report,
> + u8 *data, int size)
> +{
> + struct rdm_device *rdm = hid_get_drvdata(hdev);
> +
> + if (!rdm || size < RDM_ANSWER_LEN || data[RDM_PREFIX_BYTE] != RDM_PREFIX)
> + return 0;
> +
> + guard(spinlock_irqsave)(&rdm->lock);
> + if (rdm->expect && data[RDM_CMD_BYTE] == rdm->expect) {
> + memcpy(rdm->answer, data, RDM_ANSWER_LEN);
> + rdm->expect = 0;
> + complete(&rdm->done);
> + } else if (data[RDM_CMD_BYTE] == RDM_DONGLE_STATUS && rdm->dongle &&
> + data[RDM_LINK_BYTE] != rdm->link) {
> + /* The link to the keyboard came or went: ask now */
> + rdm->link = data[RDM_LINK_BYTE];
> + if (rdm->expect && !rdm_link_may_be_up(rdm->link)) {
> + rdm->expect = 0;
> + complete(&rdm->done);
> + }
> + if (!rdm->stopping)
> + mod_delayed_work(system_dfl_wq, &rdm->work, 0);
> + }
> + return 0;
> +}
[Severity: Medium]
Can rdm_dongle_linked() overwrite a newer rdm->link update or cause
rdm_raw_event() to drop an unsolicited link-change event?
When rdm_dongle_linked() requests RDM_DONGLE_STATUS, rdm_raw_event() takes
the rdm->expect branch and completes rdm->done without updating rdm->link.
If the dongle sends an unsolicited RDM_DONGLE_STATUS report before the
worker updates rdm->link in rdm_dongle_linked(), the two updates race:
kworker <hardirq>
rdm_dongle_linked()
rdm_command(RDM_DONGLE_STATUS)
rdm->expect = 0xd0
rdm_raw_event() [reply: link = 0x02]
memcpy(rdm->answer, data, ...)
rdm->expect = 0
complete(&rdm->done)
rdm_raw_event() [event: link = 0x00]
data[13] != rdm->link (0x00 == 0x00)
/* reconnect event ignored */
rdm->link = reply[13] (0x02)
*linked = false <-- stale link state kept
Because rdm->link still held 0x00 when the unsolicited reconnect report
arrived, rdm_raw_event() did not reschedule rdm->work, and
rdm_dongle_linked() then stores the older RDM_LINK_NONE (0x02) reply,
leaving the reconnected keyboard unpolled for RDM_POLL_MS (60 s). In the
opposite transition (reply 0x00 followed by unsolicited 0x02),
rdm_dongle_linked() overwrites the newer 0x02 in rdm->link with the stale
0x00 from reply[].
Updating rdm->link inside rdm_raw_event() whenever a valid
RDM_DONGLE_STATUS report arrives (and having rdm_dongle_linked() only read
rdm->link under rdm->lock) would avoid this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-rdmctmzt-v3-1-5ce2359df0aa@pm.me?part=1
next prev parent reply other threads:[~2026-11-23 17:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:38 [PATCH v3] HID: rdmctmzt: add RDMCTMZT keyboard battery driver Erlend Jacobsen
2026-11-23 17:38 ` Erlend Jacobsen via B4 Relay
2026-11-23 17:49 ` sashiko-bot [this message]
2026-11-24 6:11 ` Erlend Jacobsen
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-229783@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=erlendjacobsen@pm.me \
--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.