Skip to content

usbhid: Retry fetching the report descriptor - #390

Merged
ericbsd merged 1 commit into
releng/15.1from
usbhid-rdesc-retry
Nov 13, 2026
Merged

ericbsd merged 1 commit into
releng/15.1from
usbhid-rdesc-retry

Conversation

@ericbsd

@ericbsd ericbsd commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

So far only seen with a wireless mouse on a Logitech Unifying receiver. The receiver can time out on GET_DESCRIPTOR(REPORT) while still starting up after power is applied, for example after resume or when switched back through a USB switch. On failure, hms falls back to the boot protocol descriptor and the mouse loses its wheel. Wired mice have not shown the problem.

Retry the request up to five times with a 100 ms pause, stopping early on a stall since that means the device has no descriptor. Linux usbhid retries this request in the same way.

Summary by Sourcery

Bug Fixes:

  • Retry USB HID report descriptor requests up to five times with 100 ms delays to handle transient startup or resume failures and preserve full device functionality.

So far only seen with a wireless mouse on a Logitech Unifying
receiver. The receiver can time out on GET_DESCRIPTOR(REPORT) while
still starting up after power is applied, for example after resume
or when switched back through a USB switch. On failure, hms falls
back to the boot protocol descriptor and the mouse loses its wheel.
Wired mice have not shown the problem.

Retry the request up to five times with a 100 ms pause, stopping
early on a stall since that means the device has no descriptor.
Linux usbhid retries this request in the same way.
@ericbsd ericbsd self-assigned this Nov 12, 2026
@ericbsd
ericbsd requested review from a team as code owners November 12, 2026 21:28
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Retry report-descriptor requests up to five times with 100 ms pauses, stop immediately on a stall, and log successful retries.

  • sys/dev/usb/input/usbhid.c L544-562

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

Thank you for taking the time to contribute to FreeBSD!
There is an issue that needs to be fixed:

  • Missing Signed-off-by lines4e6bf0e

Please review CONTRIBUTING.md, then update and push your branch again.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="sys/dev/usb/input/usbhid.c" line_range="551-556" />
<code_context>
+	 * right after resume. A failure makes hms fall back to the boot
+	 * protocol descriptor and lose the wheel, so retry a few times.
+	 */
+	for (retry = 0;; retry++) {
+		error = usbd_req_get_report_descriptor(sc->sc_udev, NULL,
+		    buf, len, sc->sc_iface_index);
+		if (error == 0 || error == USB_ERR_STALLED || retry == 4)
+			break;
+		usb_pause_mtx(NULL, USB_MS_TO_TICKS(100));
+	}

</code_context>
<issue_to_address>
**Repeated timeouts delay device attachment**

When the descriptor request times out on all five attempts, a report-descriptor request that times out on every attempt consumes the 5-second default timeout each time, so this loop can block HID child attachment for roughly 25 seconds before returning failure.

Bound the total retry time or use a shorter timeout for each retry.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: sys/dev/usb/input/usbhid.c:556


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread sys/dev/usb/input/usbhid.c Resolved
@ericbsd
ericbsd merged commit d02482a into releng/15.1 Nov 13, 2026
6 checks passed
@ericbsd
ericbsd deleted the usbhid-rdesc-retry branch November 13, 2026 02:15
@github-project-automation github-project-automation Bot moved this from In Review to Done in Development Tracker Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant