diff options
author | Yonghong Song <yhs@fb.com> | 2022-08-07 10:51:16 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-08-09 10:30:45 -0700 |
commit | a00ed8430199abbc9d9bf43ea31795bfe98998ca (patch) | |
tree | 696ad86a479b12120fdf4a3a26a840da5591ff59 /kernel/bpf/btf.c | |
parent | 11b9148590146ff8a4e90c7f0186efe06009ec1b (diff) | |
download | lwn-a00ed8430199abbc9d9bf43ea31795bfe98998ca.tar.gz lwn-a00ed8430199abbc9d9bf43ea31795bfe98998ca.zip |
bpf: Always return corresponding btf_type in __get_type_size()
Currently in funciton __get_type_size(), the corresponding
btf_type is returned only in invalid cases. Let us always
return btf_type regardless of valid or invalid cases.
Such a new functionality will be used in subsequent patches.
Signed-off-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220807175116.4179242-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/btf.c')
-rw-r--r-- | kernel/bpf/btf.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index d3e4c86b8fcd..903719b89238 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5864,26 +5864,25 @@ again: } static int __get_type_size(struct btf *btf, u32 btf_id, - const struct btf_type **bad_type) + const struct btf_type **ret_type) { const struct btf_type *t; + *ret_type = btf_type_by_id(btf, 0); if (!btf_id) /* void */ return 0; t = btf_type_by_id(btf, btf_id); while (t && btf_type_is_modifier(t)) t = btf_type_by_id(btf, t->type); - if (!t) { - *bad_type = btf_type_by_id(btf, 0); + if (!t) return -EINVAL; - } + *ret_type = t; if (btf_type_is_ptr(t)) /* kernel size of pointer. Not BPF's size of pointer*/ return sizeof(void *); if (btf_type_is_int(t) || btf_is_any_enum(t)) return t->size; - *bad_type = t; return -EINVAL; } |