xref: /linux/tools/testing/selftests/bpf/progs/test_global_func13.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <stddef.h>
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_misc.h"
6 
7 struct S {
8 	int x;
9 };
10 
11 __noinline int foo(const struct S *s)
12 {
13 	if (s)
14 		return bpf_get_prandom_u32() < s->x;
15 
16 	return 0;
17 }
18 
19 SEC("cgroup_skb/ingress")
20 __failure __msg("Caller passes invalid args into func#1")
21 int global_func13(struct __sk_buff *skb)
22 {
23 	const struct S *s = (const struct S *)(0xbedabeda);
24 
25 	return foo(s);
26 }
27