Skip to content

Commit 7362311

Browse files
d-e-s-odanielocfb
authored andcommitted
Remove create_bpf_entity_checked() helper
Remove the create_bpf_entity_checked() and create_bpf_entity_checked_opt() helpers now that nobody is using them anymore. Signed-off-by: Daniel Müller <[email protected]>
1 parent c983f58 commit 7362311

File tree

1 file changed

+0
-38
lines changed

1 file changed

+0
-38
lines changed

libbpf-rs/src/util.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::any::type_name;
21
use std::ffi::CStr;
32
use std::ffi::CString;
4-
use std::io;
53
use std::mem::transmute;
64
use std::ops::Deref;
75
use std::os::raw::c_char;
@@ -95,42 +93,6 @@ pub fn validate_bpf_ret<T>(ptr: *mut T) -> Result<NonNull<T>> {
9593
}
9694

9795

98-
pub fn create_bpf_entity_checked<B: 'static, F: FnOnce() -> *mut B>(f: F) -> Result<NonNull<B>> {
99-
create_bpf_entity_checked_opt(f).and_then(|ptr| {
100-
ptr.ok_or_else(|| {
101-
Error::with_io_error(
102-
io::ErrorKind::Other,
103-
format!(
104-
"bpf call {:?} returned NULL",
105-
type_name::<F>() /* this is usually a library bug, hopefully this will
106-
* help diagnose the bug.
107-
*
108-
* One way to fix the bug might be to change to calling
109-
* create_bpf_entity_checked_opt and handling Ok(None)
110-
* as a meaningful value. */
111-
),
112-
)
113-
})
114-
})
115-
}
116-
117-
fn create_bpf_entity_checked_opt<B: 'static, F: FnOnce() -> *mut B>(
118-
f: F,
119-
) -> Result<Option<NonNull<B>>> {
120-
let ptr = f();
121-
if ptr.is_null() {
122-
return Ok(None);
123-
}
124-
// SAFETY: `libbpf_get_error` is always safe to call.
125-
match unsafe { libbpf_sys::libbpf_get_error(ptr as *const _) } {
126-
0 => Ok(Some(unsafe {
127-
// SAFETY: We checked if the pointer was non null before.
128-
NonNull::new_unchecked(ptr)
129-
})),
130-
err => Err(Error::from_raw_os_error(-err as i32)),
131-
}
132-
}
133-
13496
// Fix me, If std::sync::LazyLock is stable(https://github.com/rust-lang/rust/issues/109736).
13597
pub(crate) struct LazyLock<T> {
13698
cell: OnceLock<T>,

0 commit comments

Comments
 (0)