From 58e154e1bc4846a6a2afcb8397aa599cfb7ea6fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 1 May 2024 15:31:32 -0400 Subject: [PATCH] Reduce duplication --- aya/src/maps/perf/perf_buffer.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index 387dc183..72ef5fbd 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -219,9 +219,12 @@ impl PerfBuffer { let head = unsafe { (*header).data_head } as usize; let mut tail = unsafe { (*header).data_tail } as usize; - while head != tail { + let result = loop { + if head == tail { + break Ok(()); + } if buf_n == buffers.len() { - break; + break Ok(()); } let buf = &mut buffers[buf_n]; @@ -243,18 +246,16 @@ impl PerfBuffer { Err(e) => { // we got an error and we didn't process any events, propagate the error // and give the caller a chance to increase buffers - atomic::fence(Ordering::SeqCst); - unsafe { (*header).data_tail = tail as u64 }; - return Err(e); + break Err(e); } } tail += event_size; - } + }; atomic::fence(Ordering::SeqCst); unsafe { (*header).data_tail = tail as u64 }; - Ok(events) + result.map(|()| events) } }