From: Tamir Duberstein ringbuf_process_ring() checks the record bound only after advancing the consumer position and invoking the callback. A zero bound therefore consumes the first available record. Return before reading the ring positions when the bound is zero so ring_buffer__consume_n() and ring__consume_n() leave all records queued. Fixes: 4d22ea94ea33 ("libbpf: Add ring__consume_n / ring_buffer__consume_n") Reviewed-by: Emil Tsalapatis Acked-by: Eduard Zingerman Signed-off-by: Tamir Duberstein Signed-off-by: Kumar Kartikeya Dwivedi --- tools/lib/bpf/ringbuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index c8fe57401a8b..6e88ac209298 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -240,6 +240,9 @@ static int64_t ringbuf_process_ring(struct ring *r, size_t n) bool got_new_data; void *sample; + if (n == 0) + return 0; + cons_pos = smp_load_acquire(r->consumer_pos); do { got_new_data = false; -- 2.53.0