libbpf: Refactor btf__add_enum() for future code sharing
Refactor btf__add_enum() function to create a separate function btf_add_enum_common() so later the common function can be used to add enum64 btf type. There is no functionality change for this patch. Acked-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/r/20220607062615.3718063-1-yhs@fb.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
b58b2b3a31
commit
8479aa7522
@ -2129,20 +2129,8 @@ int btf__add_field(struct btf *btf, const char *name, int type_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append new BTF_KIND_ENUM type with:
|
||||
* - *name* - name of the enum, can be NULL or empty for anonymous enums;
|
||||
* - *byte_sz* - size of the enum, in bytes.
|
||||
*
|
||||
* Enum initially has no enum values in it (and corresponds to enum forward
|
||||
* declaration). Enumerator values can be added by btf__add_enum_value()
|
||||
* immediately after btf__add_enum() succeeds.
|
||||
*
|
||||
* Returns:
|
||||
* - >0, type ID of newly added BTF type;
|
||||
* - <0, on error.
|
||||
*/
|
||||
int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
||||
static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz,
|
||||
bool is_signed, __u8 kind)
|
||||
{
|
||||
struct btf_type *t;
|
||||
int sz, name_off = 0;
|
||||
@ -2167,12 +2155,30 @@ int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
||||
|
||||
/* start out with vlen=0; it will be adjusted when adding enum values */
|
||||
t->name_off = name_off;
|
||||
t->info = btf_type_info(BTF_KIND_ENUM, 0, 0);
|
||||
t->info = btf_type_info(kind, 0, is_signed);
|
||||
t->size = byte_sz;
|
||||
|
||||
return btf_commit_type(btf, sz);
|
||||
}
|
||||
|
||||
/*
|
||||
* Append new BTF_KIND_ENUM type with:
|
||||
* - *name* - name of the enum, can be NULL or empty for anonymous enums;
|
||||
* - *byte_sz* - size of the enum, in bytes.
|
||||
*
|
||||
* Enum initially has no enum values in it (and corresponds to enum forward
|
||||
* declaration). Enumerator values can be added by btf__add_enum_value()
|
||||
* immediately after btf__add_enum() succeeds.
|
||||
*
|
||||
* Returns:
|
||||
* - >0, type ID of newly added BTF type;
|
||||
* - <0, on error.
|
||||
*/
|
||||
int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
||||
{
|
||||
return btf_add_enum_common(btf, name, byte_sz, false, BTF_KIND_ENUM);
|
||||
}
|
||||
|
||||
/*
|
||||
* Append new enum value for the current ENUM type with:
|
||||
* - *name* - name of the enumerator value, can't be NULL or empty;
|
||||
|
Loading…
Reference in New Issue
Block a user