← Back to Pull requests

boot: zephyr: serial_adapter: fix CDC ACM data loss on line buffer exhaustion #2977

Closed
unknown closed this pull request without merging on Nov 24, 2026 16:29 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 14:04 UTC
Author

Fixes #2949.

Problem


The non-RAW CDC ACM receive path in serial_adapter.c sizes uart_fifo_read() batches by an estimate of free bytes, but completed lines consume whole line buffers. A batch containing more newline-terminated lines than free buffers hit the sys_slist_get(&avail_queue) failure path, logged "Not enough memory to store incoming data!" and returned — discarding the unconsumed tail of the already-read batch (those bytes were already out of the USB FIFO).

Fix


  • Retain the unconsumed batch cursor (rx_batch_off/rx_batch_len) instead of dropping the tail.

  • Apply backpressure: stop reading and disable RX when no line buffer is free, so the CDC FIFO backs up (USB NAK) instead of losing data.

  • Drain the pending tail when a line buffer is recycled in boot_uart_fifo_getline(), under the existing irq_lock() — on the USB device-next stack the RX callback runs on a work-queue thread and can interleave with the caller without it.

  • Also drain when the FIFO has gone empty, since enabling RX alone does not guarantee another callback for application-owned bytes.
  • Plain UART and RAW protocol paths are unchanged. No heap, threads, or work items are added.

    Testing


    Serial recovery has no CI coverage, so this was validated on hardware (Raspberry Pi Pico W / RP2040, USB FS CDC ACM, SMP over console):

  • Before fix: mcumgr image upload stalled at 0.00% (3/3 attempts); 198/200 pipelined short SMP requests lost.

  • After fix: upload completes 100% repeatedly (39,636-byte signed image, ~17 s) and validates/lists as bootable+confirmed.

  • Host regression harness compiling the real translation unit against mocked Zephyr/UART interfaces: 13/13 scenarios pass, plus a byte-exact 12,000-line / 380,665-byte stress stream through 4,633 pause/resume cycles.

  • Regression builds (all -Werror): rpi_pico CDC, frdm_k22f plain UART, rpi_pico RAW protocol, clang syntax check; replicated zephyr_build.yaml twister invocation: 0 errors, 0 failures.
  • Notes


    The pre-existing RP2040 USB-device-stack wedge under fully pipelined floods reproduces on pristine upstream and is unaffected by this change (out of scope).

    Thank you for taking the time to review this. Any feedback is very welcome — I'm glad to rework the approach or add anything that's missing.

    Diff: 285 lines (+213 / -72) across 3 files Reviewer: d3zd3z Review duration: 15984m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 285 lines diff across 3 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.338
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #2977"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%