libbpf: Wrap libbpf API direct err with libbpf_err

Just wrap the direct err with libbpf_err, keep consistency
with other APIs.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20250219153711.29651-1-chen.dylane@linux.dev
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
This commit is contained in:
Tao Chen
2025-02-19 23:37:11 +08:00
committed by Andrii Nakryiko
parent d7a4ab1548
commit 39a589c74e

View File

@@ -9145,12 +9145,12 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
struct bpf_gen *gen; struct bpf_gen *gen;
if (!opts) if (!opts)
return -EFAULT; return libbpf_err(-EFAULT);
if (!OPTS_VALID(opts, gen_loader_opts)) if (!OPTS_VALID(opts, gen_loader_opts))
return -EINVAL; return libbpf_err(-EINVAL);
gen = calloc(sizeof(*gen), 1); gen = calloc(sizeof(*gen), 1);
if (!gen) if (!gen)
return -ENOMEM; return libbpf_err(-ENOMEM);
gen->opts = opts; gen->opts = opts;
gen->swapped_endian = !is_native_endianness(obj); gen->swapped_endian = !is_native_endianness(obj);
obj->gen_loader = gen; obj->gen_loader = gen;
@@ -9262,13 +9262,13 @@ int bpf_program__set_insns(struct bpf_program *prog,
struct bpf_insn *insns; struct bpf_insn *insns;
if (prog->obj->loaded) if (prog->obj->loaded)
return -EBUSY; return libbpf_err(-EBUSY);
insns = libbpf_reallocarray(prog->insns, new_insn_cnt, sizeof(*insns)); insns = libbpf_reallocarray(prog->insns, new_insn_cnt, sizeof(*insns));
/* NULL is a valid return from reallocarray if the new count is zero */ /* NULL is a valid return from reallocarray if the new count is zero */
if (!insns && new_insn_cnt) { if (!insns && new_insn_cnt) {
pr_warn("prog '%s': failed to realloc prog code\n", prog->name); pr_warn("prog '%s': failed to realloc prog code\n", prog->name);
return -ENOMEM; return libbpf_err(-ENOMEM);
} }
memcpy(insns, new_insns, new_insn_cnt * sizeof(*insns)); memcpy(insns, new_insns, new_insn_cnt * sizeof(*insns));
@@ -9379,11 +9379,11 @@ const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_siz
int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size) int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size)
{ {
if (log_size && !log_buf) if (log_size && !log_buf)
return -EINVAL; return libbpf_err(-EINVAL);
if (prog->log_size > UINT_MAX) if (prog->log_size > UINT_MAX)
return -EINVAL; return libbpf_err(-EINVAL);
if (prog->obj->loaded) if (prog->obj->loaded)
return -EBUSY; return libbpf_err(-EBUSY);
prog->log_buf = log_buf; prog->log_buf = log_buf;
prog->log_size = log_size; prog->log_size = log_size;
@@ -10307,7 +10307,7 @@ int bpf_map__set_value_size(struct bpf_map *map, __u32 size)
int err; int err;
if (map->def.type != BPF_MAP_TYPE_ARRAY) if (map->def.type != BPF_MAP_TYPE_ARRAY)
return -EOPNOTSUPP; return libbpf_err(-EOPNOTSUPP);
mmap_old_sz = bpf_map_mmap_sz(map); mmap_old_sz = bpf_map_mmap_sz(map);
mmap_new_sz = array_map_mmap_sz(size, map->def.max_entries); mmap_new_sz = array_map_mmap_sz(size, map->def.max_entries);
@@ -10315,7 +10315,7 @@ int bpf_map__set_value_size(struct bpf_map *map, __u32 size)
if (err) { if (err) {
pr_warn("map '%s': failed to resize memory-mapped region: %s\n", pr_warn("map '%s': failed to resize memory-mapped region: %s\n",
bpf_map__name(map), errstr(err)); bpf_map__name(map), errstr(err));
return err; return libbpf_err(err);
} }
err = map_btf_datasec_resize(map, size); err = map_btf_datasec_resize(map, size);
if (err && err != -ENOENT) { if (err && err != -ENOENT) {
@@ -13070,17 +13070,17 @@ int bpf_link__update_map(struct bpf_link *link, const struct bpf_map *map)
int err; int err;
if (!bpf_map__is_struct_ops(map)) if (!bpf_map__is_struct_ops(map))
return -EINVAL; return libbpf_err(-EINVAL);
if (map->fd < 0) { if (map->fd < 0) {
pr_warn("map '%s': can't use BPF map without FD (was it created?)\n", map->name); pr_warn("map '%s': can't use BPF map without FD (was it created?)\n", map->name);
return -EINVAL; return libbpf_err(-EINVAL);
} }
st_ops_link = container_of(link, struct bpf_link_struct_ops, link); st_ops_link = container_of(link, struct bpf_link_struct_ops, link);
/* Ensure the type of a link is correct */ /* Ensure the type of a link is correct */
if (st_ops_link->map_fd < 0) if (st_ops_link->map_fd < 0)
return -EINVAL; return libbpf_err(-EINVAL);
err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0); err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0);
/* It can be EBUSY if the map has been used to create or /* It can be EBUSY if the map has been used to create or