aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2024-01-08 15:14:37 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2024-01-08 15:31:51 -0500
commitb29b19275b0d9d3469e3b3eb55b3e8c6dff24a50 (patch)
tree0525141aabe79a9b93773d328cf8ed58a740b962
parent4b2286c3ef8317239ed5290f381970c14d8b3fe9 (diff)
downloadlibtraceevent-b29b19275b0d9d3469e3b3eb55b3e8c6dff24a50.tar.gz
kbuffer: Update kbuf->next in kbuffer_refresh
If the kbuffer was read to completion, the kbuf->curr would equal both the size and kbuf->next. The kbuffer_refresh() is to update the kbuf if more data was added to the buffer. But if curr is at the end, the next pointer was not updated, which is incorrect. The next pointer needs to be moved to the end of the newly written event. Update the pointers in kbuffer_refresh() just as if it was loaded new (but still keeping curr at the correct location). Link: https://lore.kernel.org/linux-trace-devel/20240108151437.3c23a4f9@gandalf.local.home Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API") Reported-by: Vincent Donnefort <vdonnefort@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/kbuffer-parse.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c
index 691d536..9b72780 100644
--- a/src/kbuffer-parse.c
+++ b/src/kbuffer-parse.c
@@ -180,6 +180,7 @@ static int calc_index(struct kbuffer *kbuf, void *ptr)
return (unsigned long)ptr - (unsigned long)kbuf->data;
}
+static int next_event(struct kbuffer *kbuf);
static int __next_event(struct kbuffer *kbuf);
/*
@@ -309,13 +310,20 @@ void kbuffer_free(struct kbuffer *kbuf)
int kbuffer_refresh(struct kbuffer *kbuf)
{
unsigned long long flags;
+ unsigned int old_size;
if (!kbuf || !kbuf->subbuffer)
return -1;
+ old_size = kbuf->size;
+
flags = read_long(kbuf, kbuf->subbuffer + 8);
kbuf->size = (unsigned int)flags & COMMIT_MASK;
+ /* Update next to be the next element */
+ if (kbuf->size != old_size && kbuf->curr == kbuf->next)
+ next_event(kbuf);
+
return 0;
}