Commit b47a0bd2 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Alexei Starovoitov

bpf: btf: Break up btf_type_is_void()

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: default avatarMartin KaFai Lau <kafai@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent bbe5d311
...@@ -306,15 +306,22 @@ static bool btf_type_is_modifier(const struct btf_type *t) ...@@ -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) static bool btf_type_is_void(const struct btf_type *t)
{ {
/* void => no type and size info. return t == &btf_void;
* Hence, FWD is also treated as void. }
*/
return t == &btf_void || BTF_INFO_KIND(t->info) == BTF_KIND_FWD; 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: /* union is only a special case of struct:
...@@ -826,7 +833,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf, ...@@ -826,7 +833,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf,
u32 size = 0; u32 size = 0;
size_type = btf_type_by_id(btf, size_type_id); 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; return NULL;
if (btf_type_has_size(size_type)) { if (btf_type_has_size(size_type)) {
...@@ -842,7 +849,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf, ...@@ -842,7 +849,7 @@ const struct btf_type *btf_type_id_size(const struct btf *btf,
size = btf->resolved_sizes[size_type_id]; size = btf->resolved_sizes[size_type_id];
size_type_id = btf->resolved_ids[size_type_id]; size_type_id = btf->resolved_ids[size_type_id];
size_type = btf_type_by_id(btf, 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; return NULL;
} }
...@@ -1164,7 +1171,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env, ...@@ -1164,7 +1171,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env,
} }
/* "typedef void new_void", "const void"...etc */ /* "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; goto resolved;
if (!env_type_is_resolve_sink(env, next_type) && if (!env_type_is_resolve_sink(env, next_type) &&
...@@ -1178,7 +1185,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env, ...@@ -1178,7 +1185,7 @@ static int btf_modifier_resolve(struct btf_verifier_env *env,
* pretty print). * pretty print).
*/ */
if (!btf_type_id_size(btf, &next_type_id, &next_type_size) && 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"); btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL; return -EINVAL;
} }
...@@ -1205,7 +1212,7 @@ static int btf_ptr_resolve(struct btf_verifier_env *env, ...@@ -1205,7 +1212,7 @@ static int btf_ptr_resolve(struct btf_verifier_env *env,
} }
/* "void *" */ /* "void *" */
if (btf_type_is_void(next_type)) if (btf_type_is_void(next_type) || btf_type_is_fwd(next_type))
goto resolved; goto resolved;
if (!env_type_is_resolve_sink(env, next_type) && if (!env_type_is_resolve_sink(env, next_type) &&
...@@ -1235,7 +1242,7 @@ static int btf_ptr_resolve(struct btf_verifier_env *env, ...@@ -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) && 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"); btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL; return -EINVAL;
} }
...@@ -1396,7 +1403,7 @@ static int btf_array_resolve(struct btf_verifier_env *env, ...@@ -1396,7 +1403,7 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->index_type */ /* Check array->index_type */
index_type_id = array->index_type; index_type_id = array->index_type;
index_type = btf_type_by_id(btf, index_type_id); 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"); btf_verifier_log_type(env, v->t, "Invalid index");
return -EINVAL; return -EINVAL;
} }
...@@ -1415,7 +1422,7 @@ static int btf_array_resolve(struct btf_verifier_env *env, ...@@ -1415,7 +1422,7 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->type */ /* Check array->type */
elem_type_id = array->type; elem_type_id = array->type;
elem_type = btf_type_by_id(btf, elem_type_id); 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, btf_verifier_log_type(env, v->t,
"Invalid elem"); "Invalid elem");
return -EINVAL; return -EINVAL;
...@@ -1615,7 +1622,7 @@ static int btf_struct_resolve(struct btf_verifier_env *env, ...@@ -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, const struct btf_type *member_type = btf_type_by_id(env->btf,
member_type_id); 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, btf_verifier_log_member(env, v->t, member,
"Invalid member"); "Invalid member");
return -EINVAL; return -EINVAL;
......
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