Skip to content

fix(usb_host): clamp copied input-report length; document the failed-teardown state - #793

Merged
finger563 merged 2 commits into
mainfrom
fix/usb-host-review
Sep 13, 2026
Merged

fix(usb_host): clamp copied input-report length; document the failed-teardown state#793
finger563 merged 2 commits into
mainfrom
fix/usb-host-review

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Two small follow-ups to espp::UsbHost (#791) raised by the Copilot review on #792 against usb_host code that is now on main:

  • Clamp the copied Input-report length (on_interface_event): len from hid_host_device_get_raw_input_report_data() is now bounded to the buffer capacity we handed the driver (with a truncation warning), so Event::data() can never form an out-of-bounds span even if the driver ever reported the full report length instead of the copied length.
  • Document the failed-teardown state (deinitialize): when hid_host_uninstall() keeps failing, the root port is deliberately left powered off — powering it back up would make the driver re-enumerate and re-track the very device a retry needs gone. The header docs and the error log now state that in this state event delivery is stopped, devices are retired, and the only valid next steps are retrying deinitialize() or destroying the object.

No behaviour change on the success path. components/usb_host/example builds clean (IDF v6.1, esp32s3).

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

…teardown state

Two follow-ups from the Copilot review of #792 that concern code now on main:

- on_interface_event(): never trust the driver-reported input-report length
  beyond the buffer we handed it -- clamp `len` to the copy capacity (logging
  the truncation) so Event::data() can never form an out-of-bounds span.
- deinitialize(): when hid_host_uninstall() keeps failing the root port is
  deliberately left powered off (powering it back up would only make the
  driver re-track the device a retry needs gone). Document that state in the
  header and the error log: event delivery is stopped, devices are retired,
  and the only valid next steps are retrying deinitialize() or destroying
  the object.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Copilot AI lite review requested due to automatic review settings September 12, 2026 20:55
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Follow-up fixes to espp::UsbHost to guard against out-of-bounds report spans and to clarify the teardown failure behavior when hid_host_uninstall() cannot complete.

Changes:

  • Clamp copied HID input-report length to the configured buffer capacity with a truncation warning.
  • Expand documentation and logging around the “failed teardown” state, noting the root port remains powered off and what recovery steps are valid.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
components/usb_host/src/usb_host.cpp Adds input-report length clamping and expands failed-uninstall logging to describe the powered-off root port behavior.
components/usb_host/include/usb_host.hpp Documents the non-usable “failed teardown” state and the only valid next steps (retry deinitialize or destroy).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread components/usb_host/src/usb_host.cpp Outdated
…r log

Only ESP_ERR_INVALID_STATE means the driver still tracks a device; report any
other error as-is instead of guessing at a cause. Keeps the "root port left
powered off, retry deinitialize()" guidance.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@finger563
finger563 merged commit 038eea4 into main Sep 13, 2026
160 checks passed
@finger563
finger563 deleted the fix/usb-host-review branch September 13, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants