[PATCH] perf/ring-buffer: refactor code of reading the value of data_tail

From: Donglin Peng
Date: Sat Jan 27 2024 - 23:19:52 EST


The tail variable will only be accessed when overwrite is 0, so we can
put the assignment statement in the if branch.

Fixes: d1b26c70246b ("perf/ring_buffer: Prepare writing into the ring-buffer from the end")
Signed-off-by: Donglin Peng <dolinux.peng@xxxxxxxxx>
---
kernel/events/ring_buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 60ed43d1c29e..86b150a822b7 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -194,8 +194,8 @@ __perf_output_begin(struct perf_output_handle *handle,
offset = local_read(&rb->head);
do {
head = offset;
- tail = READ_ONCE(rb->user_page->data_tail);
if (!rb->overwrite) {
+ tail = READ_ONCE(rb->user_page->data_tail);
if (unlikely(!ring_buffer_has_space(head, tail,
perf_data_size(rb),
size, backward)))
--
2.25.1