This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit bcb951fde442afe2b513869469d31dfae70ddfdd Author: yezhonghui <[email protected]> AuthorDate: Fri Oct 23 16:55:05 2026 +0800 ring: guard skipto against a target lapped by the writer ring_*_skipto computed the skip count as ring_dist(target, cons), a modular forward distance. A target no longer ahead of the consumer (already consumed, or lapped by the writer) wraps that distance into a near-full-ring count, so the skip would evict almost all still-live data instead of doing nothing. Check ring_is_valid_cons against the same cons snapshot before taking the distance, and no-op when the target is not ahead. Signed-off-by: yezhonghui <[email protected]> --- include/nuttx/ring.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/nuttx/ring.h b/include/nuttx/ring.h index 00377e1eee4..2ea5d50fa45 100644 --- a/include/nuttx/ring.h +++ b/include/nuttx/ring.h @@ -1799,8 +1799,14 @@ ring_sc_skipto(FAR struct ring_s *r, uint32_t target) { FAR struct ring_blob_s *blob = r->blob; uint32_t cons_index = RTS_IDX(blob->cons_tail); - uint32_t count = ring_dist(r, target, cons_index); + uint32_t count; + /* Clamp a stale target: ring_dist would otherwise wrap it to a + * near-full-ring count and evict still-live data. + */ + + target = ring_clamp_cons(r, target, cons_index); + count = ring_dist(r, target, cons_index); if (count != 0) { return ring_sc_skip(r, count); @@ -1845,8 +1851,14 @@ ring_mc_skipto(FAR struct ring_s *r, uint32_t target) { FAR struct ring_blob_s *blob = r->blob; uint32_t cons_index = RTS_IDX(atomic_read(&blob->cons_tail)); - uint32_t count = ring_dist(r, target, cons_index); + uint32_t count; + + /* Clamp a stale target: ring_dist would otherwise wrap it to a + * near-full-ring count and evict still-live data. + */ + target = ring_clamp_cons(r, target, cons_index); + count = ring_dist(r, target, cons_index); if (count != 0) { return ring_mc_skip(r, count);
