diff options
| author | Leon Hwang <leon.hwang@linux.dev> | 2025-11-25 17:58:50 +0300 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2025-11-26 02:27:48 +0300 |
| commit | 8f6ddc0587606c4be7ffcbdb20a4a99647e0c362 (patch) | |
| tree | d0cb29a327e3ba86a62d4979487761d8fc8b8c50 /include/linux | |
| parent | 8c868a34ea851713eca6bb90db111c7bf091b34b (diff) | |
| download | linux-8f6ddc0587606c4be7ffcbdb20a4a99647e0c362.tar.xz | |
bpf: Introduce internal bpf_map_check_op_flags helper function
It is to unify map flags checking for lookup_elem, update_elem,
lookup_batch and update_batch APIs.
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20251125145857.98134-2-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/bpf.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a9b788c7b4aa..6498be4c44f8 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -3829,4 +3829,15 @@ bpf_prog_update_insn_ptrs(struct bpf_prog *prog, u32 *offsets, void *image) } #endif +static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 allowed_flags) +{ + if (flags & ~allowed_flags) + return -EINVAL; + + if ((flags & BPF_F_LOCK) && !btf_record_has_field(map->record, BPF_SPIN_LOCK)) + return -EINVAL; + + return 0; +} + #endif /* _LINUX_BPF_H */ |
