mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-22 09:19:06 +08:00
btf: Refactor the code by calling str_is_empty
Calling the str_is_empty function to clarify the code and no functional changes are introduced. Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260109130003.3313716-12-dolinux.peng@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
ad9c763445
commit
8a090ef1e5
34
src/btf.c
34
src/btf.c
@@ -2134,7 +2134,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
|
||||
int sz, name_off;
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
/* byte_sz must be power of 2 */
|
||||
if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
|
||||
@@ -2182,7 +2182,7 @@ int btf__add_float(struct btf *btf, const char *name, size_t byte_sz)
|
||||
int sz, name_off;
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
/* byte_sz must be one of the explicitly allowed values */
|
||||
@@ -2237,7 +2237,7 @@ static int btf_add_ref_kind(struct btf *btf, int kind, const char *name, int ref
|
||||
if (!t)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
if (name && name[0]) {
|
||||
if (!str_is_empty(name)) {
|
||||
name_off = btf__add_str(btf, name);
|
||||
if (name_off < 0)
|
||||
return name_off;
|
||||
@@ -2314,7 +2314,7 @@ static int btf_add_composite(struct btf *btf, int kind, const char *name, __u32
|
||||
if (!t)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
if (name && name[0]) {
|
||||
if (!str_is_empty(name)) {
|
||||
name_off = btf__add_str(btf, name);
|
||||
if (name_off < 0)
|
||||
return name_off;
|
||||
@@ -2415,7 +2415,7 @@ int btf__add_field(struct btf *btf, const char *name, int type_id,
|
||||
if (!m)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
if (name && name[0]) {
|
||||
if (!str_is_empty(name)) {
|
||||
name_off = btf__add_str(btf, name);
|
||||
if (name_off < 0)
|
||||
return name_off;
|
||||
@@ -2453,7 +2453,7 @@ static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz,
|
||||
if (!t)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
if (name && name[0]) {
|
||||
if (!str_is_empty(name)) {
|
||||
name_off = btf__add_str(btf, name);
|
||||
if (name_off < 0)
|
||||
return name_off;
|
||||
@@ -2511,7 +2511,7 @@ int btf__add_enum_value(struct btf *btf, const char *name, __s64 value)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
if (value < INT_MIN || value > UINT_MAX)
|
||||
return libbpf_err(-E2BIG);
|
||||
@@ -2588,7 +2588,7 @@ int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
/* decompose and invalidate raw data */
|
||||
@@ -2628,7 +2628,7 @@ int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value)
|
||||
*/
|
||||
int btf__add_fwd(struct btf *btf, const char *name, enum btf_fwd_kind fwd_kind)
|
||||
{
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
switch (fwd_kind) {
|
||||
@@ -2664,7 +2664,7 @@ int btf__add_fwd(struct btf *btf, const char *name, enum btf_fwd_kind fwd_kind)
|
||||
*/
|
||||
int btf__add_typedef(struct btf *btf, const char *name, int ref_type_id)
|
||||
{
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
return btf_add_ref_kind(btf, BTF_KIND_TYPEDEF, name, ref_type_id, 0);
|
||||
@@ -2716,7 +2716,7 @@ int btf__add_restrict(struct btf *btf, int ref_type_id)
|
||||
*/
|
||||
int btf__add_type_tag(struct btf *btf, const char *value, int ref_type_id)
|
||||
{
|
||||
if (!value || !value[0])
|
||||
if (str_is_empty(value))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
return btf_add_ref_kind(btf, BTF_KIND_TYPE_TAG, value, ref_type_id, 0);
|
||||
@@ -2733,7 +2733,7 @@ int btf__add_type_tag(struct btf *btf, const char *value, int ref_type_id)
|
||||
*/
|
||||
int btf__add_type_attr(struct btf *btf, const char *value, int ref_type_id)
|
||||
{
|
||||
if (!value || !value[0])
|
||||
if (str_is_empty(value))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
return btf_add_ref_kind(btf, BTF_KIND_TYPE_TAG, value, ref_type_id, 1);
|
||||
@@ -2752,7 +2752,7 @@ int btf__add_func(struct btf *btf, const char *name,
|
||||
{
|
||||
int id;
|
||||
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
if (linkage != BTF_FUNC_STATIC && linkage != BTF_FUNC_GLOBAL &&
|
||||
linkage != BTF_FUNC_EXTERN)
|
||||
@@ -2838,7 +2838,7 @@ int btf__add_func_param(struct btf *btf, const char *name, int type_id)
|
||||
if (!p)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
if (name && name[0]) {
|
||||
if (!str_is_empty(name)) {
|
||||
name_off = btf__add_str(btf, name);
|
||||
if (name_off < 0)
|
||||
return name_off;
|
||||
@@ -2873,7 +2873,7 @@ int btf__add_var(struct btf *btf, const char *name, int linkage, int type_id)
|
||||
int sz, name_off;
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
if (linkage != BTF_VAR_STATIC && linkage != BTF_VAR_GLOBAL_ALLOCATED &&
|
||||
linkage != BTF_VAR_GLOBAL_EXTERN)
|
||||
@@ -2922,7 +2922,7 @@ int btf__add_datasec(struct btf *btf, const char *name, __u32 byte_sz)
|
||||
int sz, name_off;
|
||||
|
||||
/* non-empty name */
|
||||
if (!name || !name[0])
|
||||
if (str_is_empty(name))
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
if (btf_ensure_modifiable(btf))
|
||||
@@ -2999,7 +2999,7 @@ static int btf_add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
|
||||
struct btf_type *t;
|
||||
int sz, value_off;
|
||||
|
||||
if (!value || !value[0] || component_idx < -1)
|
||||
if (str_is_empty(value) || component_idx < -1)
|
||||
return libbpf_err(-EINVAL);
|
||||
|
||||
if (validate_type_id(ref_type_id))
|
||||
|
||||
@@ -2904,7 +2904,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
|
||||
var_extra = btf_var(var);
|
||||
map_name = btf__name_by_offset(obj->btf, var->name_off);
|
||||
|
||||
if (map_name == NULL || map_name[0] == '\0') {
|
||||
if (str_is_empty(map_name)) {
|
||||
pr_warn("map #%d: empty name.\n", var_idx);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -4281,7 +4281,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj)
|
||||
if (!sym_is_extern(sym))
|
||||
continue;
|
||||
ext_name = elf_sym_str(obj, sym->st_name);
|
||||
if (!ext_name || !ext_name[0])
|
||||
if (str_is_empty(ext_name))
|
||||
continue;
|
||||
|
||||
ext = obj->externs;
|
||||
|
||||
Reference in New Issue
Block a user