diff options
author | Kui-Feng Lee <thinker.li@gmail.com> | 2024-02-08 18:37:48 -0800 |
---|---|---|
committer | Martin KaFai Lau <martin.lau@kernel.org> | 2024-02-13 15:16:44 -0800 |
commit | 6115a0aeef01aef152ad7738393aad11422bfb82 (patch) | |
tree | 347d202fac2f91df9dcdc3c772c970860390fc86 /kernel/bpf/btf.c | |
parent | 77c0208e199ccb0986fb3612f2409c8cdcb036ad (diff) | |
download | lwn-6115a0aeef01aef152ad7738393aad11422bfb82.tar.gz lwn-6115a0aeef01aef152ad7738393aad11422bfb82.zip |
bpf: Move __kfunc_param_match_suffix() to btf.c.
Move __kfunc_param_match_suffix() to btf.c and rename it as
btf_param_match_suffix(). It can be reused by bpf_struct_ops later.
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240209023750.1153905-3-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'kernel/bpf/btf.c')
-rw-r--r-- | kernel/bpf/btf.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index cf100b5573ca..447da964f217 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8904,3 +8904,21 @@ errout: } EXPORT_SYMBOL_GPL(__register_bpf_struct_ops); #endif + +bool btf_param_match_suffix(const struct btf *btf, + const struct btf_param *arg, + const char *suffix) +{ + int suffix_len = strlen(suffix), len; + const char *param_name; + + /* In the future, this can be ported to use BTF tagging */ + param_name = btf_name_by_offset(btf, arg->name_off); + if (str_is_empty(param_name)) + return false; + len = strlen(param_name); + if (len <= suffix_len) + return false; + param_name += len - suffix_len; + return !strncmp(param_name, suffix, suffix_len); +} |