libbpf: fix ring_buffer__consume_n() return result logic
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 30 Apr 2024 20:19:52 +0000 (13:19 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 2 May 2024 23:41:03 +0000 (16:41 -0700)
Add INT_MAX check to ring_buffer__consume_n(). We do the similar check
to handle int return result of all these ring buffer APIs in other APIs
and ring_buffer__consume_n() is missing one. This patch fixes this
omission.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20240430201952.888293-2-andrii@kernel.org
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/lib/bpf/ringbuf.c

index 37c5a2d86a782e78ae62b5a9c269c964bc1a3e78..bfd8dac4c0cc0c9ab235a121c7ddb55bc8875d3a 100644 (file)
@@ -301,7 +301,7 @@ int ring_buffer__consume_n(struct ring_buffer *rb, size_t n)
                if (n == 0)
                        break;
        }
-       return res;
+       return res > INT_MAX ? INT_MAX : res;
 }
 
 /* Consume available ring buffer(s) data without event polling.