[PATCH v3] kbuffer: Update kbuf->next in kbuffer_refresh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

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).

Fixes: 7a4d5b24 ("kbuffer: Add kbuffer_refresh() API")
Reported-by: Vincent Donnefort <vdonnefort@xxxxxxxxxx>
Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
Changes since v2: https://lore.kernel.org/linux-trace-devel/20240108123859.32db3407@xxxxxxxxxxxxxxxxxx

- Remove leftover prototypes of old_update_pointers() and update_pointers()
  that was needed for v1 but not v2.

 src/kbuffer-parse.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c
index 691d53678f5f..9b7278036ba8 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;
 }
 
-- 
2.43.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux