Browse Source

aya-bpf, aya-bpf-bindings: fix clippy lints

Alessandro Decina 3 years ago
parent
commit
a68ff47246

+ 1 - 0
bpf/aya-bpf-bindings/src/aarch64/mod.rs

@@ -1,3 +1,4 @@
+#![allow(clippy::all, dead_code)]
 pub mod bindings;
 pub mod getters;
 pub mod helpers;

+ 1 - 0
bpf/aya-bpf-bindings/src/armv7/mod.rs

@@ -1,3 +1,4 @@
+#![allow(clippy::all, dead_code)]
 pub mod bindings;
 pub mod getters;
 pub mod helpers;

+ 1 - 0
bpf/aya-bpf-bindings/src/x86_64/mod.rs

@@ -1,3 +1,4 @@
+#![allow(clippy::all, dead_code)]
 pub mod bindings;
 pub mod getters;
 pub mod helpers;

+ 1 - 0
bpf/aya-bpf-macros/src/expand.rs

@@ -274,6 +274,7 @@ fn name_arg(args: &mut Args) -> Result<Option<String>> {
     Ok(name)
 }
 
+#[allow(clippy::enum_variant_names)]
 #[derive(Debug, Copy, Clone)]
 pub enum ProbeKind {
     KProbe,

+ 4 - 3
bpf/aya-bpf/src/helpers.rs

@@ -21,12 +21,13 @@ pub unsafe fn bpf_probe_read<T>(src: *const T) -> Result<T, c_long> {
 }
 
 #[inline]
-pub fn bpf_get_current_comm() -> Result<[c_char; 16], ()> {
+pub fn bpf_get_current_comm() -> Result<[c_char; 16], c_long> {
     let mut comm: [c_char; 16usize] = [0; 16];
-    if unsafe { gen::bpf_get_current_comm(&mut comm as *mut _ as *mut c_void, 16u32) } == 0 {
+    let ret = unsafe { gen::bpf_get_current_comm(&mut comm as *mut _ as *mut c_void, 16u32) };
+    if ret == 0 {
         Ok(comm)
     } else {
-        Err(())
+        Err(ret)
     }
 }
 

+ 3 - 2
bpf/aya-bpf/src/lib.rs

@@ -1,3 +1,4 @@
+#![allow(clippy::missing_safety_doc)]
 #![no_std]
 
 pub use aya_bpf_bindings::bindings;
@@ -9,7 +10,7 @@ pub mod programs;
 pub use aya_bpf_cty as cty;
 
 use core::ffi::c_void;
-use cty::c_char;
+use cty::{c_char, c_long};
 use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid};
 
 pub use aya_bpf_macros as macros;
@@ -20,7 +21,7 @@ pub trait BpfContext {
     fn as_ptr(&self) -> *mut c_void;
 
     #[inline]
-    fn command(&self) -> Result<[c_char; TASK_COMM_LEN], ()> {
+    fn command(&self) -> Result<[c_char; TASK_COMM_LEN], c_long> {
         bpf_get_current_comm()
     }
 

+ 2 - 3
bpf/aya-bpf/src/maps/sock_hash.rs

@@ -51,12 +51,11 @@ impl<K> SockHash<K> {
     }
 
     pub unsafe fn redirect(&mut self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 {
-        let ret = bpf_msg_redirect_hash(
+        bpf_msg_redirect_hash(
             ctx.as_ptr() as *mut _,
             &mut self.def as *mut _ as *mut _,
             key as *mut _ as *mut _,
             flags,
-        );
-        ret
+        )
     }
 }

+ 2 - 3
bpf/aya-bpf/src/maps/sock_map.rs

@@ -49,12 +49,11 @@ impl SockMap {
     }
 
     pub unsafe fn redirect(&mut self, ctx: &SkMsgContext, index: u32, flags: u64) -> i64 {
-        let ret = bpf_msg_redirect_map(
+        bpf_msg_redirect_map(
             ctx.as_ptr() as *mut _,
             &mut self.def as *mut _ as *mut _,
             index,
             flags,
-        );
-        ret
+        )
     }
 }

+ 1 - 0
bpf/aya-bpf/src/programs/sk_skb.rs

@@ -20,6 +20,7 @@ impl SkSkbContext {
         SkSkbContext { skb }
     }
 
+    #[allow(clippy::len_without_is_empty)]
     #[inline]
     pub fn len(&self) -> u32 {
         unsafe { *self.skb }.len