summaryrefslogtreecommitdiff
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2024-05-06 17:13:29 -0700
committerMartin KaFai Lau <martin.lau@kernel.org>2024-05-07 16:21:59 -0700
commit8374b56b1df5566d19d645e49da2bf31b660bcfd (patch)
treea2ee3b0a2aa6b786ab10b3836c1f7bcaf09f6739 /tools/lib/bpf
parent93d1c2da15017a443cad812468450b72f43e3bd8 (diff)
libbpf: remove unnecessary struct_ops prog validity check
libbpf ensures that BPF program references set in map->st_ops->progs[i] during open phase are always valid STRUCT_OPS programs. This is done in bpf_object__collect_st_ops_relos(). So there is no need to double-check that in bpf_map__init_kern_struct_ops(). Simplify the code by removing unnecessary check. Also, we avoid using local prog variable to keep code similar to the upcoming fix, which adds similar logic in another part of bpf_map__init_kern_struct_ops(). Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20240507001335.1445325-2-andrii@kernel.org Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/libbpf.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a3566a456bc8..7d77a1b158ce 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1152,22 +1152,15 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
return -ENOTSUP;
}
- prog = st_ops->progs[i];
- if (prog) {
+ if (st_ops->progs[i]) {
/* If we had declaratively set struct_ops callback, we need to
- * first validate that it's actually a struct_ops program.
- * And then force its autoload to false, because it doesn't have
+ * force its autoload to false, because it doesn't have
* a chance of succeeding from POV of the current struct_ops map.
* If this program is still referenced somewhere else, though,
* then bpf_object_adjust_struct_ops_autoload() will update its
* autoload accordingly.
*/
- if (!is_valid_st_ops_program(obj, prog)) {
- pr_warn("struct_ops init_kern %s: member %s is declaratively assigned a non-struct_ops program\n",
- map->name, mname);
- return -EINVAL;
- }
- prog->autoload = false;
+ st_ops->progs[i]->autoload = false;
st_ops->progs[i] = NULL;
}