Skip to content

Commit

Permalink
bpf: btf: Break up btf_type_is_void()
Browse files Browse the repository at this point in the history
This patch breaks up btf_type_is_void() into
btf_type_is_void() and btf_type_is_fwd().

It also adds btf_type_nosize() to better describe it is
testing a type has nosize info.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
iamkafai authored and Alexei Starovoitov committed Nov 20, 2018
1 parent bbe5d31 commit b47a0bd
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions kernel/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,22 @@ static bool btf_type_is_modifier(const struct btf_type *t)

static bool btf_type_is_void(const struct btf_type *t)
{
/* void => no type and size info.
* Hence, FWD is also treated as void.
*/
return t == &btf_void || BTF_INFO_KIND(t->info) == BTF_KIND_FWD;
return t == &btf_void;
}

static bool btf_type_is_fwd(const struct btf_type *t)
{
return BTF_INFO_KIND(t->info) == BTF_KIND_FWD;
}

static bool btf_type_nosize(const struct btf_type *t)
{
return btf_type_is_void(t) || btf_type_is_fwd(t);
}

static bool btf_type_is_void_or_null(const struct btf_type *t)
static bool btf_type_nosize_or_null(const struct btf_type *t)
{
return !t || btf_type_is_void(t);
return !t || btf_type_nosize(t);
}

/* union is only a special case of struct:
Expand Down Expand Up @@ -826,7 +833,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf,
u32 size = 0;

size_type = btf_type_by_id(btf, size_type_id);
if (btf_type_is_void_or_null(size_type))
if (btf_type_nosize_or_null(size_type))
return NULL;

if (btf_type_has_size(size_type)) {
Expand All @@ -842,7 +849,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf,
size = btf->resolved_sizes[size_type_id];
size_type_id = btf->resolved_ids[size_type_id];
size_type = btf_type_by_id(btf, size_type_id);
if (btf_type_is_void(size_type))
if (btf_type_nosize_or_null(size_type))
return NULL;
}

Expand Down Expand Up @@ -1164,7 +1171,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env,
}

/* "typedef void new_void", "const void"...etc */
if (btf_type_is_void(next_type))
if (btf_type_is_void(next_type) || btf_type_is_fwd(next_type))
goto resolved;

if (!env_type_is_resolve_sink(env, next_type) &&
Expand All @@ -1178,7 +1185,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env,
* pretty print).
*/
if (!btf_type_id_size(btf, &next_type_id, &next_type_size) &&
!btf_type_is_void(btf_type_id_resolve(btf, &next_type_id))) {
!btf_type_nosize(btf_type_id_resolve(btf, &next_type_id))) {
btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL;
}
Expand All @@ -1205,7 +1212,7 @@ static int btf_ptr_resolve(struct btf_verifier_env *env,
}

/* "void *" */
if (btf_type_is_void(next_type))
if (btf_type_is_void(next_type) || btf_type_is_fwd(next_type))
goto resolved;

if (!env_type_is_resolve_sink(env, next_type) &&
Expand Down Expand Up @@ -1235,7 +1242,7 @@ static int btf_ptr_resolve(struct btf_verifier_env *env,
}

if (!btf_type_id_size(btf, &next_type_id, &next_type_size) &&
!btf_type_is_void(btf_type_id_resolve(btf, &next_type_id))) {
!btf_type_nosize(btf_type_id_resolve(btf, &next_type_id))) {
btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL;
}
Expand Down Expand Up @@ -1396,7 +1403,7 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->index_type */
index_type_id = array->index_type;
index_type = btf_type_by_id(btf, index_type_id);
if (btf_type_is_void_or_null(index_type)) {
if (btf_type_nosize_or_null(index_type)) {
btf_verifier_log_type(env, v->t, "Invalid index");
return -EINVAL;
}
Expand All @@ -1415,7 +1422,7 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->type */
elem_type_id = array->type;
elem_type = btf_type_by_id(btf, elem_type_id);
if (btf_type_is_void_or_null(elem_type)) {
if (btf_type_nosize_or_null(elem_type)) {
btf_verifier_log_type(env, v->t,
"Invalid elem");
return -EINVAL;
Expand Down Expand Up @@ -1615,7 +1622,7 @@ static int btf_struct_resolve(struct btf_verifier_env *env,
const struct btf_type *member_type = btf_type_by_id(env->btf,
member_type_id);

if (btf_type_is_void_or_null(member_type)) {
if (btf_type_nosize_or_null(member_type)) {
btf_verifier_log_member(env, v->t, member,
"Invalid member");
return -EINVAL;
Expand Down

0 comments on commit b47a0bd

Please sign in to comment.