1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
3
4#include <vmlinux.h>
5#include <bpf/bpf_tracing.h>
6#include <bpf/bpf_helpers.h>
7#include <bpf/bpf_core_read.h>
8#include "bpf_experimental.h"
9
10struct node_data {
11 int key;
12 int data;
13 struct bpf_rb_node node;
14};
15
16struct node_data2 {
17 int key;
18 struct bpf_rb_node node;
19 int data;
20};
21
22static bool less2(struct bpf_rb_node *a, const struct bpf_rb_node *b)
23{
24 struct node_data2 *node_a;
25 struct node_data2 *node_b;
26
27 node_a = container_of(a, struct node_data2, node);
28 node_b = container_of(b, struct node_data2, node);
29
30 return node_a->key < node_b->key;
31}
32
33#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
34private(A) struct bpf_spin_lock glock;
35private(A) struct bpf_rb_root groot __contains(node_data, node);
36
37SEC("tc")
38long rbtree_api_add__add_wrong_type(void *ctx)
39{
40 struct node_data2 *n;
41
42 n = bpf_obj_new(typeof(*n));
43 if (!n)
44 return 1;
45
46 bpf_spin_lock(&glock);
47 bpf_rbtree_add(&groot, &n->node, less2);
48 bpf_spin_unlock(&glock);
49 return 0;
50}
51
52char _license[] SEC("license") = "GPL";
53

source code of linux/tools/testing/selftests/bpf/progs/rbtree_btf_fail__add_wrong_type.c