From 05419829d3aa62da075d458b1d2b3c2f6f11c369 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sat, 28 May 2022 14:20:51 +0900 Subject: [PATCH] Return non error only when helper function returns `0` in queue map As described in https://github.com/aya-rs/aya/issues/288, queue does not return `error` even calling pop() from the empty queue. This is because the helper functions (`bpf_map_pop_elem()`) does not return negative value for Rust/aya correctly. The `bpf_map_pop_elem()` and `bpf_map_push_elem()` returns `0` on success - https://man7.org/linux/man-pages/man7/bpf-helpers.7.html, so this patch changes the condition as only `0` on success. Fix https://github.com/aya-rs/aya/issues/288 --- bpf/aya-bpf/src/maps/queue.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bpf/aya-bpf/src/maps/queue.rs b/bpf/aya-bpf/src/maps/queue.rs index 663db494..320a7bd3 100644 --- a/bpf/aya-bpf/src/maps/queue.rs +++ b/bpf/aya-bpf/src/maps/queue.rs @@ -51,7 +51,7 @@ impl Queue { flags, ) }; - (ret >= 0).then(|| ()).ok_or(ret) + (ret == 0).then(|| ()).ok_or(ret) } pub fn pop(&mut self) -> Option { @@ -61,7 +61,7 @@ impl Queue { &mut self.def as *mut _ as *mut _, value.as_mut_ptr() as *mut _, ); - (ret >= 0).then(|| value.assume_init()) + (ret == 0).then(|| value.assume_init()) } } }