From 764eb309b082a2e54b0d98782bb9cecd1243ff42 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 18 Jul 2023 11:54:47 +0100 Subject: [PATCH] Clippy fixes for latest nightly Signed-off-by: Dave Tucker --- aya/src/maps/hash_map/mod.rs | 4 ++-- aya/src/maps/perf/perf_buffer.rs | 24 ++++++++++++------------ aya/src/programs/extension.rs | 15 +++++++-------- aya/src/programs/mod.rs | 7 ++----- aya/src/sys/bpf.rs | 2 +- aya/src/sys/netlink.rs | 4 ++-- bpf/aya-bpf/src/helpers.rs | 2 +- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/aya/src/maps/hash_map/mod.rs b/aya/src/maps/hash_map/mod.rs index 4ae4d712..72d8583d 100644 --- a/aya/src/maps/hash_map/mod.rs +++ b/aya/src/maps/hash_map/mod.rs @@ -15,7 +15,7 @@ pub use per_cpu_hash_map::*; use super::MapData; pub(crate) fn insert( - map: &mut MapData, + map: &MapData, key: &K, value: &V, flags: u64, @@ -31,7 +31,7 @@ pub(crate) fn insert( Ok(()) } -pub(crate) fn remove(map: &mut MapData, key: &K) -> Result<(), MapError> { +pub(crate) fn remove(map: &MapData, key: &K) -> Result<(), MapError> { let fd = map.fd_or_err()?; bpf_map_delete_elem(fd, key) .map(|_| ()) diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index e32be94d..e3e99e3e 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -328,7 +328,7 @@ mod tests { data: [u8; PAGE_SIZE * 2], } - fn fake_mmap(buf: &mut MMappedBuf) { + fn fake_mmap(buf: &MMappedBuf) { override_syscall(|call| match call { Syscall::PerfEventOpen { .. } | Syscall::PerfEventIoctl { .. } => Ok(42), _ => panic!(), @@ -355,10 +355,10 @@ mod tests { #[test] #[cfg_attr(miri, ignore)] fn test_no_out_bufs() { - let mut mmapped_buf = MMappedBuf { + let mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); assert_matches!(buf.read_events(&mut []), Err(PerfBufferError::NoBuffers)) @@ -367,10 +367,10 @@ mod tests { #[test] #[cfg_attr(miri, ignore)] fn test_no_events() { - let mut mmapped_buf = MMappedBuf { + let mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let out_buf = BytesMut::with_capacity(4); @@ -386,7 +386,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let evt = LostSamples { header: perf_event_header { @@ -451,7 +451,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); write_sample(&mut mmapped_buf, 0, 0xCAFEBABEu32); @@ -469,7 +469,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let next = write_sample(&mut mmapped_buf, 0, 0xCAFEBABEu32); @@ -492,7 +492,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let next = write_sample(&mut mmapped_buf, 0, 0xCAFEBABEu32); @@ -514,7 +514,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let offset = PAGE_SIZE - mem::size_of::>(); @@ -534,7 +534,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let header = perf_event_header { @@ -563,7 +563,7 @@ mod tests { let mut mmapped_buf = MMappedBuf { data: [0; PAGE_SIZE * 2], }; - fake_mmap(&mut mmapped_buf); + fake_mmap(&mmapped_buf); let mut buf = PerfBuffer::open(1, PAGE_SIZE, 1).unwrap(); let sample = PerfSample { diff --git a/aya/src/programs/extension.rs b/aya/src/programs/extension.rs index 1826a101..682d14ad 100644 --- a/aya/src/programs/extension.rs +++ b/aya/src/programs/extension.rs @@ -172,17 +172,16 @@ fn get_btf_info(prog_fd: i32, func_name: &str) -> Result<(RawFd, u32), ProgramEr // we need to read the btf bytes into a buffer but we don't know the size ahead of time. // assume 4kb. if this is too small we can resize based on the size obtained in the response. let mut buf = vec![0u8; 4096]; - let btf_info = match sys::btf_obj_get_info_by_fd(btf_fd, &mut buf) { + let btf_info = match sys::btf_obj_get_info_by_fd(btf_fd, &buf) { Ok(info) => { if info.btf_size > buf.len() as u32 { buf.resize(info.btf_size as usize, 0u8); - let btf_info = - sys::btf_obj_get_info_by_fd(btf_fd, &mut buf).map_err(|io_error| { - ProgramError::SyscallError { - call: "bpf_prog_get_info_by_fd", - io_error, - } - })?; + let btf_info = sys::btf_obj_get_info_by_fd(btf_fd, &buf).map_err(|io_error| { + ProgramError::SyscallError { + call: "bpf_prog_get_info_by_fd", + io_error, + } + })?; Ok(btf_info) } else { Ok(info) diff --git a/aya/src/programs/mod.rs b/aya/src/programs/mod.rs index 68ebe748..0e20ef3f 100644 --- a/aya/src/programs/mod.rs +++ b/aya/src/programs/mod.rs @@ -523,10 +523,7 @@ fn unload_program(data: &mut ProgramData) -> Result<(), ProgramError Ok(()) } -fn pin_program>( - data: &mut ProgramData, - path: P, -) -> Result<(), PinError> { +fn pin_program>(data: &ProgramData, path: P) -> Result<(), PinError> { let fd = data.fd.ok_or(PinError::NoFd { name: data .name @@ -783,7 +780,7 @@ macro_rules! impl_program_pin{ /// Any directories in the the path provided should have been created by the caller. pub fn pin>(&mut self, path: P) -> Result<(), PinError> { self.data.path = Some(path.as_ref().to_path_buf()); - pin_program(&mut self.data, path) + pin_program(&self.data, path) } /// Removes the pinned link from the filesystem. diff --git a/aya/src/sys/bpf.rs b/aya/src/sys/bpf.rs index 5809d4c6..89b7e0e0 100644 --- a/aya/src/sys/bpf.rs +++ b/aya/src/sys/bpf.rs @@ -518,7 +518,7 @@ pub(crate) fn bpf_link_get_info_by_fd(link_fd: RawFd) -> Result Result { let mut attr = unsafe { mem::zeroed::() }; let mut info = unsafe { mem::zeroed::() }; diff --git a/aya/src/sys/netlink.rs b/aya/src/sys/netlink.rs index b0526cc3..44b0643b 100644 --- a/aya/src/sys/netlink.rs +++ b/aya/src/sys/netlink.rs @@ -575,8 +575,8 @@ impl From for io::Error { } unsafe fn request_attributes(req: &mut T, msg_len: usize) -> &mut [u8] { - let attrs_addr = align_to(req as *const _ as usize + msg_len, NLMSG_ALIGNTO as usize); - let attrs_end = req as *const _ as usize + mem::size_of::(); + let attrs_addr = align_to(req as *mut _ as usize + msg_len, NLMSG_ALIGNTO as usize); + let attrs_end = req as *mut _ as usize + mem::size_of::(); slice::from_raw_parts_mut(attrs_addr as *mut u8, attrs_end - attrs_addr) } diff --git a/bpf/aya-bpf/src/helpers.rs b/bpf/aya-bpf/src/helpers.rs index ca408601..169c83ac 100644 --- a/bpf/aya-bpf/src/helpers.rs +++ b/bpf/aya-bpf/src/helpers.rs @@ -410,7 +410,7 @@ pub unsafe fn bpf_probe_read_user_str_bytes( read_str_bytes(len, dest) } -fn read_str_bytes(len: i64, dest: &mut [u8]) -> Result<&[u8], c_long> { +fn read_str_bytes(len: i64, dest: &[u8]) -> Result<&[u8], c_long> { // The lower bound is 0, since it's what is returned for b"\0". See the // bpf_probe_read_user_[user|kernel]_bytes_empty integration tests. The upper bound // check is not needed since the helper truncates, but the verifier doesn't