Commit 6298399b authored by Jiri Olsa's avatar Jiri Olsa Committed by Alexei Starovoitov

bpf: Move btf_resolve_size into __btf_resolve_size

Moving btf_resolve_size into __btf_resolve_size and
keeping btf_resolve_size public with just first 3
arguments, because the rest of the arguments are not
used by outside callers.

Following changes are adding more arguments, which
are not useful to outside callers. They will be added
to the __btf_resolve_size function.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200825192124.710397-4-jolsa@kernel.org
parent a5f53b1d
...@@ -64,8 +64,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, ...@@ -64,8 +64,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf,
u32 id, u32 *res_id); u32 id, u32 *res_id);
const struct btf_type * const struct btf_type *
btf_resolve_size(const struct btf *btf, const struct btf_type *type, btf_resolve_size(const struct btf *btf, const struct btf_type *type,
u32 *type_size, const struct btf_type **elem_type, u32 *type_size);
u32 *total_nelems);
#define for_each_member(i, struct_type, member) \ #define for_each_member(i, struct_type, member) \
for (i = 0, member = btf_type_member(struct_type); \ for (i = 0, member = btf_type_member(struct_type); \
......
...@@ -298,8 +298,7 @@ static int check_zero_holes(const struct btf_type *t, void *data) ...@@ -298,8 +298,7 @@ static int check_zero_holes(const struct btf_type *t, void *data)
return -EINVAL; return -EINVAL;
mtype = btf_type_by_id(btf_vmlinux, member->type); mtype = btf_type_by_id(btf_vmlinux, member->type);
mtype = btf_resolve_size(btf_vmlinux, mtype, &msize, mtype = btf_resolve_size(btf_vmlinux, mtype, &msize);
NULL, NULL);
if (IS_ERR(mtype)) if (IS_ERR(mtype))
return PTR_ERR(mtype); return PTR_ERR(mtype);
prev_mend = moff + msize; prev_mend = moff + msize;
...@@ -396,8 +395,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, ...@@ -396,8 +395,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
u32 msize; u32 msize;
mtype = btf_type_by_id(btf_vmlinux, member->type); mtype = btf_type_by_id(btf_vmlinux, member->type);
mtype = btf_resolve_size(btf_vmlinux, mtype, &msize, mtype = btf_resolve_size(btf_vmlinux, mtype, &msize);
NULL, NULL);
if (IS_ERR(mtype)) { if (IS_ERR(mtype)) {
err = PTR_ERR(mtype); err = PTR_ERR(mtype);
goto reset_unlock; goto reset_unlock;
......
...@@ -1088,8 +1088,8 @@ static const struct resolve_vertex *env_stack_peak(struct btf_verifier_env *env) ...@@ -1088,8 +1088,8 @@ static const struct resolve_vertex *env_stack_peak(struct btf_verifier_env *env)
* *elem_type: same as return type ("struct X") * *elem_type: same as return type ("struct X")
* *total_nelems: 1 * *total_nelems: 1
*/ */
const struct btf_type * static const struct btf_type *
btf_resolve_size(const struct btf *btf, const struct btf_type *type, __btf_resolve_size(const struct btf *btf, const struct btf_type *type,
u32 *type_size, const struct btf_type **elem_type, u32 *type_size, const struct btf_type **elem_type,
u32 *total_nelems) u32 *total_nelems)
{ {
...@@ -1150,6 +1150,13 @@ btf_resolve_size(const struct btf *btf, const struct btf_type *type, ...@@ -1150,6 +1150,13 @@ btf_resolve_size(const struct btf *btf, const struct btf_type *type,
return array_type ? : type; return array_type ? : type;
} }
const struct btf_type *
btf_resolve_size(const struct btf *btf, const struct btf_type *type,
u32 *type_size)
{
return __btf_resolve_size(btf, type, type_size, NULL, NULL);
}
/* The input param "type_id" must point to a needs_resolve type */ /* The input param "type_id" must point to a needs_resolve type */
static const struct btf_type *btf_type_id_resolve(const struct btf *btf, static const struct btf_type *btf_type_id_resolve(const struct btf *btf,
u32 *type_id) u32 *type_id)
...@@ -3976,7 +3983,7 @@ int btf_struct_access(struct bpf_verifier_log *log, ...@@ -3976,7 +3983,7 @@ int btf_struct_access(struct bpf_verifier_log *log,
mtype = btf_type_by_id(btf_vmlinux, member->type); mtype = btf_type_by_id(btf_vmlinux, member->type);
mname = __btf_name_by_offset(btf_vmlinux, member->name_off); mname = __btf_name_by_offset(btf_vmlinux, member->name_off);
mtype = btf_resolve_size(btf_vmlinux, mtype, &msize, mtype = __btf_resolve_size(btf_vmlinux, mtype, &msize,
&elem_type, &total_nelems); &elem_type, &total_nelems);
if (IS_ERR(mtype)) { if (IS_ERR(mtype)) {
bpf_log(log, "field %s doesn't have size\n", mname); bpf_log(log, "field %s doesn't have size\n", mname);
...@@ -3991,7 +3998,7 @@ int btf_struct_access(struct bpf_verifier_log *log, ...@@ -3991,7 +3998,7 @@ int btf_struct_access(struct bpf_verifier_log *log,
if (btf_type_is_array(mtype)) { if (btf_type_is_array(mtype)) {
u32 elem_idx; u32 elem_idx;
/* btf_resolve_size() above helps to /* __btf_resolve_size() above helps to
* linearize a multi-dimensional array. * linearize a multi-dimensional array.
* *
* The logic here is treating an array * The logic here is treating an array
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment