zephyr: Rework the IIOD USB class pipe lifecycle #1586
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1586"
general
weight: 0.35
petejohanson-adi
PR Description
This branch fixes a series of correctness bugs in
zephyr/iiod/usb.c's pipe handling, reworks how each pipe is served so those bugs can't recur, and backs it with a new hardware-free test suite.Bug fixes — each only reachable via specific host behavior (replug,
SET_INTERFACE) or hardware, which is why none surfaced until hunted for on a bench:.init(it runs once per speed, high-speed first, so the full-speed pass's placeholder values stuck by luck until overwritten). MAX32 assigns IN and OUT asymmetrically (IN at 0x87, OUT at 0x01), which broke.Fix: resolve addresses from the speed-correct array at each use, as CDC ACM and MSC do, and validate the resolved map at
.enablewhere the negotiated speed is known..init, which doesn't run untilusbd_init(). A composite device calls that later, so the thread waited on an uninitialized semaphore and faulted.Fix: initialize the semaphore statically in the instance definition, as CDC ECM and Bluetooth HCI do.
Fix: drop the ring buffer. Each received
net_bufis now queued to the interpreter as-is, stamped with the session it arrived for, so staleness is a per-buffer check instead of a cross-thread reset — one fewer copy per received byte, andrx-fifo-size's byte buffer is replaced by a smallrx-depthbuffer count (10296 bytes of RAM back on apard32690).OPEN_PIPEafter an abnormal session end.OPEN_PIPEreturned early when the pipe's open flag was already set, assuming only the control handler ends a session. A receive error or aSET_INTERFACE(which cancels every queued buffer, even re-selecting the same alternate) ends one too, leaving the flag stuck and every laterOPEN_PIPErefused for the rest of the configuration.Fix: always start a fresh session unconditionally; the flag still gates whether the completion handler drops packets, but no longer gates whether the pipe can reopen.
OPEN_PIPEhad a matching reset of the same semaphore, out from under a writer that could be blocked on it.Fix: drop both the synthesized give and the reset — nothing manufactures a stale count, so nothing needs resetting.
OPEN_PIPEcreated the interpreter thread for a session, andCLOSE_PIPEonly asked it to leave, so a reopen had to join it — from the control handler, on the USB stack's single cooperative thread. That stalls every endpoint while it waits, and deadlocks outright if the thread being joined is itself blocked on a write completion that only that same cooperative thread delivers.Fix: the largest change in the branch — give every pipe one thread, created once at startup, that parks between sessions and is signalled to start and stop one, so no join is needed; a reader leaves as soon as its session number is superseded rather than being waited on. Pipe 0 (the command channel) drops its special-case handling and runs the same loop, so
RESET_PIPESactually ends its session instead of only discarding what it had buffered.Also included
tx-buf-sizepaid one round trip per 64 bytes. Default raised to 512 — one round trip per chunk at high speed instead of eight.num-pipesandtx-buf-sizeget lower bounds in the binding, so a config the code can't actually run (an array too small to hold the pipes, a chunk size that isn't a whole packet) is caught at build time instead of at a client's next handshake.Tests
Adds
zephyr/tests/iiod_usb_class, a native_sim suite (libiio.iiod.usb_class) that puts both ends of the bus in one image — the class on a virtual UDC driven through the real USB host stack — so it exercises the actual libiio vendor requests and BINARY handshake with no board, no USB/IP, and no root, and runs in a fraction of a second. 14 cases, covering:SET_INTERFACEand after a full reconfigurationRESET_PIPES, including repeated resetsEach covers a bug above or a hazard the rework introduces (e.g. the parked-thread handoff), catching regressions that previously needed a real board to reproduce.
PR Type
PR Checklist