Clippy fixes for latest nightly

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/671/head
Dave Tucker 1 year ago
parent 78ede184bd
commit 764eb309b0

@ -15,7 +15,7 @@ pub use per_cpu_hash_map::*;
use super::MapData;
pub(crate) fn insert<K: Pod, V: Pod>(
map: &mut MapData,
map: &MapData,
key: &K,
value: &V,
flags: u64,
@ -31,7 +31,7 @@ pub(crate) fn insert<K: Pod, V: Pod>(
Ok(())
}
pub(crate) fn remove<K: Pod>(map: &mut MapData, key: &K) -> Result<(), MapError> {
pub(crate) fn remove<K: Pod>(map: &MapData, key: &K) -> Result<(), MapError> {
let fd = map.fd_or_err()?;
bpf_map_delete_elem(fd, key)
.map(|_| ())

@ -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::<PerfSample<u32>>();
@ -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 {

@ -172,12 +172,11 @@ 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| {
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,

@ -523,10 +523,7 @@ fn unload_program<T: Link>(data: &mut ProgramData<T>) -> Result<(), ProgramError
Ok(())
}
fn pin_program<T: Link, P: AsRef<Path>>(
data: &mut ProgramData<T>,
path: P,
) -> Result<(), PinError> {
fn pin_program<T: Link, P: AsRef<Path>>(data: &ProgramData<T>, 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<P: AsRef<Path>>(&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.

@ -518,7 +518,7 @@ pub(crate) fn bpf_link_get_info_by_fd(link_fd: RawFd) -> Result<bpf_link_info, i
pub(crate) fn btf_obj_get_info_by_fd(
prog_fd: RawFd,
buf: &mut [u8],
buf: &[u8],
) -> Result<bpf_btf_info, io::Error> {
let mut attr = unsafe { mem::zeroed::<bpf_attr>() };
let mut info = unsafe { mem::zeroed::<bpf_btf_info>() };

@ -575,8 +575,8 @@ impl From<NlAttrError> for io::Error {
}
unsafe fn request_attributes<T>(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::<T>();
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::<T>();
slice::from_raw_parts_mut(attrs_addr as *mut u8, attrs_end - attrs_addr)
}

@ -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

Loading…
Cancel
Save