bpf: replace pop/push emptiness check with bpf_list_empty()
Subsystems (3)
PATCH 1/1 bpf: replace pop/push emptiness check with bpf_list_empty()
Simplify fq_flows_is_empty() by replacing the pop/push based emptiness check with a direct call to bpf_list_empty().
This avoids unnecessary list mutation and simplifies the code while preserving correctness.
--- tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3 -7
@@ -197,17 +197,13 @@ static bool fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock) { struct bpf_list_node *node; +bool empty;bpf_spin_lock (lock); - node =bpf_list_pop_front (head); -if (node) { -bpf_list_push_front (head, node); -bpf_spin_unlock (lock); -return false; - } + empty =bpf_list_empty (head);bpf_spin_unlock (lock); -return true; +return empty; }/* flow->age is used to denote the state of the flow (not-detached, detached, throttled)
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The patch introduces a call to `bpf_list_empty()`, which does not exist in the BPF API. - [Low] The…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The patch introduces a call to bpf_list_empty(), which does not exist in the BPF API.
- [Low] The local variable node is declared but never used.
--
commit 0412c8130cf7d0d205c2cc937b2838067c31fb8b
Author: Suchit Karunakaran <[email protected]>
bpf: replace pop/push emptiness check with bpf_list_empty()
This commit attempts to simplify fq_flows_is_empty() by replacing the pop/push based emptiness check with a direct call to bpf_list_empty(). This is intended to avoid unnecessary list mutations.
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 199
Quoted 8 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0
-0@@ -197,17 +197,13 @@ static bool fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock) { struct bpf_list_node *node;
[Severity: Low]
Since the pop and push logic was removed, is the node variable still used anywhere? Leaving this declaration here might trigger an unused-variable compiler warning and break the selftests build.
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 203
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +2
-6+bool empty;bpf_spin_lock (lock); - node =bpf_list_pop_front (head); -if (node) { -bpf_list_push_front (head, node); -bpf_spin_unlock (lock); -return false; - } + empty =bpf_list_empty (head);
[Severity: Low]
Does bpf_list_empty() exist in the BPF API?
The BPF linked list API does not appear to define a bpf_list_empty() kfunc, helper function, or macro. Could this lead to an implicit declaration compilation error?
Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +1
-1bpf_spin_unlock (lock); -return true; +return empty; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThe variable 'node' is no longer used after removing the pop/push logic. Will this trigger an unused-variable compiler warning and break the selftests build?
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 199
Quoted 8 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0
-0@@ -197,17 +197,13 @@ static bool fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock) { struct bpf_list_node *node;
^^^^
The variable 'node' is no longer used after removing the pop/push logic. Will this trigger an unused-variable compiler warning and break the selftests build?
Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0
-2+ bool empty;bpf_spin_lock (lock); - node =bpf_list_pop_front (head); -if (node) {
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 207
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +2
-5-bpf_list_push_front (head, node); -bpf_spin_unlock (lock); -return false; - } + empty =bpf_list_empty (head);bpf_spin_unlock (lock); -return true; +return empty; }
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26340856238
Quoted 6 lines · Suchit Karunakaran
Simplify
fq_flows_is_empty()by replacing the pop/push based emptiness check with a direct call tobpf_list_empty().
This avoids unnecessary list mutation and simplifies the code while preserving correctness.Signed-off-by Suchit Karunakaran <[email protected]>
Imo the new code is way nicer, so even if this is a selftest the change is worth it. After addressing the AI feedback feel free to add:
Quoted 29 lines
--- tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3
-7@@ -197,17 +197,13 @@ static bool fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock) { struct bpf_list_node *node; +bool empty;bpf_spin_lock (lock); - node =bpf_list_pop_front (head); -if (node) { -bpf_list_push_front (head, node); -bpf_spin_unlock (lock); -return false; - } + empty =bpf_list_empty (head);bpf_spin_unlock (lock); -return true; +return empty; }/* flow->age is used to denote the state of the flow (not-detached, detached, throttled)