Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andrii Nakryiko and committed by
Martin KaFai Lau
8374b56b 93d1c2da

+3 -10
+3 -10
tools/lib/bpf/libbpf.c
··· 1152 1152 return -ENOTSUP; 1153 1153 } 1154 1154 1155 - prog = st_ops->progs[i]; 1156 - if (prog) { 1155 + if (st_ops->progs[i]) { 1157 1156 /* If we had declaratively set struct_ops callback, we need to 1158 - * first validate that it's actually a struct_ops program. 1159 - * And then force its autoload to false, because it doesn't have 1157 + * force its autoload to false, because it doesn't have 1160 1158 * a chance of succeeding from POV of the current struct_ops map. 1161 1159 * If this program is still referenced somewhere else, though, 1162 1160 * then bpf_object_adjust_struct_ops_autoload() will update its 1163 1161 * autoload accordingly. 1164 1162 */ 1165 - if (!is_valid_st_ops_program(obj, prog)) { 1166 - pr_warn("struct_ops init_kern %s: member %s is declaratively assigned a non-struct_ops program\n", 1167 - map->name, mname); 1168 - return -EINVAL; 1169 - } 1170 - prog->autoload = false; 1163 + st_ops->progs[i]->autoload = false; 1171 1164 st_ops->progs[i] = NULL; 1172 1165 } 1173 1166