Skip to content

Commit b2e7c6e

Browse files
committed
ring-buffer: Simplify ring_buffer_read_page() with guard()
The function ring_buffer_read_page() had two gotos. One was simply returning "ret" and the other was unlocking the reader_lock. There's no reason to use goto to simply return the "ret" variable. Instead just return the value. The jump to the unlocking of the reader_lock can be replaced by guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock). With these two changes the "ret" variable is no longer used and can be removed. The return value on non-error is what was read and is stored in the "read" variable. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/20250527145216.0187cf36@gandalf.local.home Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent f0d8cbc commit b2e7c6e

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

kernel/trace/ring_buffer.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,38 +6531,37 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
65316531
struct buffer_data_page *bpage;
65326532
struct buffer_page *reader;
65336533
unsigned long missed_events;
6534-
unsigned long flags;
65356534
unsigned int commit;
65366535
unsigned int read;
65376536
u64 save_timestamp;
6538-
int ret = -1;
65396537

65406538
if (!cpumask_test_cpu(cpu, buffer->cpumask))
6541-
goto out;
6539+
return -1;
65426540

65436541
/*
65446542
* If len is not big enough to hold the page header, then
65456543
* we can not copy anything.
65466544
*/
65476545
if (len <= BUF_PAGE_HDR_SIZE)
6548-
goto out;
6546+
return -1;
65496547

65506548
len -= BUF_PAGE_HDR_SIZE;
65516549

65526550
if (!data_page || !data_page->data)
6553-
goto out;
6551+
return -1;
6552+
65546553
if (data_page->order != buffer->subbuf_order)
6555-
goto out;
6554+
return -1;
65566555

65576556
bpage = data_page->data;
65586557
if (!bpage)
6559-
goto out;
6558+
return -1;
65606559

6561-
raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
6560+
guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock);
65626561

65636562
reader = rb_get_reader_page(cpu_buffer);
65646563
if (!reader)
6565-
goto out_unlock;
6564+
return -1;
65666565

65676566
event = rb_reader_event(cpu_buffer);
65686567

@@ -6596,7 +6595,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
65966595
if (full &&
65976596
(!read || (len < (commit - read)) ||
65986597
cpu_buffer->reader_page == cpu_buffer->commit_page))
6599-
goto out_unlock;
6598+
return -1;
66006599

66016600
if (len > (commit - read))
66026601
len = (commit - read);
@@ -6605,7 +6604,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
66056604
size = rb_event_ts_length(event);
66066605

66076606
if (len < size)
6608-
goto out_unlock;
6607+
return -1;
66096608

66106609
/* save the current timestamp, since the user will need it */
66116610
save_timestamp = cpu_buffer->read_stamp;
@@ -6663,7 +6662,6 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
66636662
if (reader->real_end)
66646663
local_set(&bpage->commit, reader->real_end);
66656664
}
6666-
ret = read;
66676665

66686666
cpu_buffer->lost_events = 0;
66696667

@@ -6690,11 +6688,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
66906688
if (commit < buffer->subbuf_size)
66916689
memset(&bpage->data[commit], 0, buffer->subbuf_size - commit);
66926690

6693-
out_unlock:
6694-
raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
6695-
6696-
out:
6697-
return ret;
6691+
return read;
66986692
}
66996693
EXPORT_SYMBOL_GPL(ring_buffer_read_page);
67006694

0 commit comments

Comments
 (0)