]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: rbtree: Fix incorrect global variable usage
authorRong Tao <rongtao@cestc.cn>
Thu, 5 Jun 2025 08:45:14 +0000 (16:45 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 5 Jun 2025 20:55:26 +0000 (13:55 -0700)
Within __add_three() function, should use function parameters instead of
global variables. So that the variables groot_nested.inner.root and
groot_nested.inner.glock in rbtree_add_nodes_nested() are tested
correctly.

Signed-off-by: Rong Tao <rongtao@cestc.cn>
Link: https://lore.kernel.org/r/tencent_3DD7405C0839EBE2724AC5FA357B5402B105@qq.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/rbtree.c

index a3620c15c13675ec378f7920c525b0b1f7a2afb4..49fe93d7e0595da031855b9e35f72d995d915ad5 100644 (file)
@@ -61,19 +61,19 @@ static long __add_three(struct bpf_rb_root *root, struct bpf_spin_lock *lock)
        }
        m->key = 1;
 
-       bpf_spin_lock(&glock);
-       bpf_rbtree_add(&groot, &n->node, less);
-       bpf_rbtree_add(&groot, &m->node, less);
-       bpf_spin_unlock(&glock);
+       bpf_spin_lock(lock);
+       bpf_rbtree_add(root, &n->node, less);
+       bpf_rbtree_add(root, &m->node, less);
+       bpf_spin_unlock(lock);
 
        n = bpf_obj_new(typeof(*n));
        if (!n)
                return 3;
        n->key = 3;
 
-       bpf_spin_lock(&glock);
-       bpf_rbtree_add(&groot, &n->node, less);
-       bpf_spin_unlock(&glock);
+       bpf_spin_lock(lock);
+       bpf_rbtree_add(root, &n->node, less);
+       bpf_spin_unlock(lock);
        return 0;
 }