From: sashiko-bot@kernel.org
To: "Erlend Jacobsen" <erlendjacobsen@pm.me>, linux-input@vger.kernel.org
Cc: dmitry.torokhov@gmail.com
Subject: Re: [PATCH] HID: rdmctmzt: add RDMCTMZT keyboard battery driver
Date: Sun, 22 Nov 2026 19:47:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-228283@kernel.org> (raw)
In-Reply-To: <20261122-b4-rdmctmzt-v1-1-d45883e1fe33@pm.me>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] HID: rdmctmzt: stale fails count delays reconnect retry in
rdm_battery_work()
- [Medium] HID: rdmctmzt: battery polling stops permanently on -ENODEV
during USB reset
--
commit df75940f34ec97cd0e02102aba217a05fb6752a4
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 raw-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..9966025b40587
> --- /dev/null
> +++ b/drivers/hid/hid-rdmctmzt.c
> @@ -0,0 +1,654 @@
[ ... ]
> +/* Send one command; its answer arrives in rdm_raw_event() */
> +static int rdm_send(struct rdm_device *rdm, u8 cmd)
> +{
> + size_t raw_len = rdm->len + 1;
> + int ret;
> +
> + memset(rdm->buf, 0, raw_len);
> + rdm->buf[0] = 0x00; /* unnumbered report ID */
> + rdm->buf[1 + RDM_PREFIX_BYTE] = RDM_PREFIX;
> + rdm->buf[1 + RDM_CMD_BYTE] = cmd;
> + rdm->buf[1 + RDM_SIZE_BYTE] = rdm->len;
> +
> + ret = hid_hw_output_report(rdm->hdev, rdm->buf, raw_len);
> + /*
> + * -ESHUTDOWN from the transport (an endpoint flushed by a USB reset)
> + * is a lost poll; it must not end the polling like rdm->stopping does.
> + */
> + if (ret == -ESHUTDOWN)
> + return -EIO;
> + if (ret < 0)
> + return ret;
> + if (ret != raw_len)
> + return -EIO;
> +
> + return 0;
> +}
[ ... ]
> +/* 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 == -ENODEV || ret == -ESHUTDOWN)
> + return ret;
[ ... ]
> +static void rdm_battery_work(struct work_struct *work)
> +{
> + struct rdm_device *rdm = container_of(to_delayed_work(work),
> + struct rdm_device, work);
> + enum usb_wireless_status wireless = rdm->wireless;
> + bool linked = true, answered = false, got = false;
> + bool changed, present;
> + unsigned int delay;
> + u8 capacity = 0;
> + int status = 0;
> +
> + if (rdm->dongle && rdm_dongle_linked(rdm, &linked))
> + return;
> +
> + if (linked && rdm_poll_keyboard(rdm, &linked, &answered, &got,
> + &capacity, &status))
> + return;
[Severity: Medium]
Can a runtime USB reset stop rdm->work permanently when usb_submit_urb()
returns -ENODEV?
During usb_reset_and_verify_device(), usbhid runs hid_pre_reset() and
hid_post_reset() without calling the driver's suspend or reset_resume
callbacks, and hub_port_init() temporarily places udev->state in
USB_STATE_DEFAULT and USB_STATE_ADDRESS. If hid_hw_output_report() runs
during that window, usb_submit_urb() fails with -ENODEV (while
dev->state < USB_STATE_CONFIGURED), causing rdm_dongle_linked() or
rdm_poll_keyboard() to abort rdm_battery_work() before
queue_delayed_work().
Since rdm_stop_polling() sets rdm->stopping and cancels the work on unplug
and suspend, should rdm_dongle_linked() and rdm_poll_keyboard() only bail
out on -ESHUTDOWN (or should rdm_send() also map -ENODEV to -EIO)?
> +
> + if (!got)
> + hid_dbg(rdm->hdev, "no battery status (linked %d, answered %d)\n",
> + linked, answered);
> +
> + rdm->silent = answered ? 0 : min(rdm->silent + 1, RDM_MAX_FAILS);
> + rdm->fails = got ? 0 : min(rdm->fails + 1, RDM_MAX_FAILS);
> + if (!linked) {
> + rdm->fails = RDM_MAX_FAILS;
> + wireless = USB_WIRELESS_STATUS_DISCONNECTED;
> + } else if (answered) {
> + wireless = USB_WIRELESS_STATUS_CONNECTED;
> + } else if (rdm->silent >= RDM_MAX_FAILS ||
> + rdm->wireless == USB_WIRELESS_STATUS_NA) {
> + wireless = USB_WIRELESS_STATUS_DISCONNECTED;
> + }
> +
> + /* Without a link the dongle reports when it comes back */
> + if (got || !linked)
> + delay = RDM_POLL_MS;
> + else if (rdm->fails < RDM_MAX_FAILS)
> + delay = RDM_RETRY_MS;
> + else if (rdm->dongle && rdm->silent >= RDM_MAX_FAILS)
> + delay = RDM_SEARCH_MS;
> + else
> + delay = RDM_POLL_MS;
[Severity: Medium]
Does a stale rdm->fails count after the keyboard reconnects delay the next
retry for RDM_POLL_MS (60 s) instead of RDM_RETRY_MS (5 s)?
While the keyboard is off or unlinked, rdm->fails reaches RDM_MAX_FAILS.
When the keyboard powers on, the dongle's 0xd0 report in rdm_raw_event()
queues rdm->work with delay 0 without resetting rdm->fails. If that
immediate poll runs before the newly booted keyboard has measured its
battery, the keyboard answers RDM_CMD_START (answered = true) and refuses
RDM_CMD_BATTERY with 0x0f (got = false): rdm->silent is reset to 0 while
rdm->fails stays at RDM_MAX_FAILS, so the delay check skips both
RDM_RETRY_MS and RDM_SEARCH_MS and falls through to RDM_POLL_MS, leaving
the battery unregistered or marked not present for a full minute. The same
60 s stall happens if one !linked poll sets rdm->fails = RDM_MAX_FAILS
while rdm->silent is 1, and the immediate poll on reconnect times out
(leaving rdm->silent at 2).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-b4-rdmctmzt-v1-1-d45883e1fe33@pm.me?part=1
prev parent reply other threads:[~2026-11-22 19:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 19:34 [PATCH] HID: rdmctmzt: add RDMCTMZT keyboard battery driver Erlend Jacobsen via B4 Relay
2026-11-22 19:47 ` 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-228283@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox