Skip to content

Fix garbage messages on device de-enumeration#53

Open
CristianManca wants to merge 1 commit into
qualcomm:mainfrom
CristianManca:fix/wdfserial-clear-ringbuffer-d3final
Open

Fix garbage messages on device de-enumeration#53
CristianManca wants to merge 1 commit into
qualcomm:mainfrom
CristianManca:fix/wdfserial-clear-ringbuffer-d3final

Conversation

@CristianManca

@CristianManca CristianManca commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This patch fixes an issue where qcwdfser emitted copies of the last AT commands replies (garbage messages) when the device de-enumerated.
Root cause: stale data remained in the serial ring buffer could re-deliver buffered data during D3 transitions.

This patch prevents qcwdfser from emitting stale copies of the last AT replies on device de‑enumeration by clearing the serial ring buffer at D3Final.

Changes:

Ring buffer and power state management:

  • When the device transitions to the D3Final power state, the read ring buffer is now explicitly cleared and the in-queue byte count reset, ensuring no stale data remains when the device is powered down.

@CristianManca CristianManca force-pushed the fix/wdfserial-clear-ringbuffer-d3final branch from 6142c6b to b896853 Compare June 9, 2026 09:59
@5656hcx

5656hcx commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Hi @CristianManca,

Is this issue introduced by interval timeout implementation only?
Can you explain more why interval timeout will re-deliver outdated data?
If interval timeout is disabled, will this issue happen?

Best,
Chenxi

@5656hcx 5656hcx added the bug Something isn't working label Jun 12, 2026
@CristianManca

CristianManca commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Hi @5656hcx ,

I removed the changes in src/windows/wdfserial/QCRD.c regarding interval timeout.
That change was not related to garbage messages issue.

Regards,
Cristian

Clear ring buffer at D3Final to prevent garbage messages.

Signed-off-by: Cristian Manca <Cristian.Manca@telit.com>
@CristianManca CristianManca force-pushed the fix/wdfserial-clear-ringbuffer-d3final branch from b896853 to 9caf3ff Compare June 17, 2026 15:35
@hangzqcom

Copy link
Copy Markdown
Contributor

This patch fixes an issue where qcwdfser emitted copies of the last AT commands replies (garbage messages) when the device de-enumerated. Root cause: stale data remained in the serial ring buffer and ReadIntervalTimeout behavior could re-deliver buffered data during D3 transitions.

This patch prevents qcwdfser from emitting stale copies of the last AT replies on device de‑enumeration by clearing the serial ring buffer at D3Final. That change exposed a timing/regression where reads could still wait on the inter-byte timer (or re-deliver buffered data) and cause latency/throughput issues. To address that, read handling was updated to immediately drain available buffer data and cancel any pending interval timer, restoring correct behavior and timing.

Changes:

Ring buffer and power state management:

  • When the device transitions to the D3Final power state, the read ring buffer is now explicitly cleared and the in-queue byte count reset, ensuring no stale data remains when the device is powered down.

Read request handling and latency improvements:

  • The read handler now bypasses the inter-byte gap timer when data is already present in the ring buffer, delivering data immediately instead of waiting for the timer. This significantly reduces per-byte latency and prevents throughput loss. Additionally, any pending read interval timer is canceled before draining the buffer. [1] [2]
  • The logging in the read handler was corrected to report the actual number of available bytes, not the buffer capacity, for more accurate diagnostics.

Read completion and diagnostics:

  • The read completion routine now distinguishes between requested, transferred, and used byte counts for improved trace logs and ensures failed URBs do not contribute bytes to the ring buffer. Logging is updated to reflect these changes and to avoid dereferencing possibly-null pointers.

PR description needs to be updated to reflect final changes

@5656hcx 5656hcx 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.

Please update the pull request description to reflect the latest changes.
Also, making the buffer cleanup outside read thread is unsafe.

("<%ws> QCPNP_EvtDeviceD0Exit D3Final: clearing ring buffer\n", pDevContext->PortName)
);
QCUTIL_RingBufferClear(&pDevContext->ReadRingBuffer);
pDevContext->AmountInInQueue = 0;

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.

Updating the ReadRingBuffer outside read thread may experience race condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants