Inside elf_functions__collect(), refactor portion of the code to be a helper elf_function__check_and_push_sym(). Such a helper will be used in the next patch. Signed-off-by: Yonghong Song --- btf_encoder.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 1c69577..d28af58 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2181,10 +2181,22 @@ static inline int elf_function__push_sym(struct elf_function *func, struct elf_f return 0; } +static int elf_function__check_and_push_sym(struct elf_function *func, const char *sym_name, int st_value) +{ + struct elf_function_sym func_sym; + + if (!func->name) + return -ENOMEM; + + func_sym.name = sym_name; + func_sym.addr = st_value; + + return elf_function__push_sym(func, &func_sym); +} + static int elf_functions__collect(struct elf_functions *functions) { uint32_t nr_symbols = elf_symtab__nr_symbols(functions->symtab); - struct elf_function_sym func_sym; struct elf_function *func, *tmp; const char *sym_name, *suffix; Elf32_Word sym_sec_idx; @@ -2224,15 +2236,7 @@ static int elf_functions__collect(struct elf_functions *functions) else func->name = strdup(sym_name); - if (!func->name) { - err = -ENOMEM; - goto out_free; - } - - func_sym.name = sym_name; - func_sym.addr = sym.st_value; - - err = elf_function__push_sym(func, &func_sym); + err = elf_function__check_and_push_sym(func, sym_name, sym.st_value); if (err) goto out_free; -- 2.47.3