From: Yonghong Song <yonghong.song@linux.dev>
To: Alan Maguire <alan.maguire@oracle.com>,
Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
dwarves@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, David Faust <david.faust@oracle.com>,
"Jose E . Marchesi" <jose.marchesi@oracle.com>,
kernel-team@fb.com
Subject: [PATCH dwarves 2/3] bpf_encoder: Refactor a helper elf_function__check_and_push_sym()
Date: Tue, 11 Nov 2025 09:04:34 -0800 [thread overview]
Message-ID: <20251111170434.287807-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20251111170424.286892-1-yonghong.song@linux.dev>
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 <yonghong.song@linux.dev>
---
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
next prev parent reply other threads:[~2025-11-11 17:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-11 17:04 [PATCH dwarves 0/3] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-11-11 17:04 ` [PATCH dwarves 1/3] btf_encoder: Refactor elf_functions__new() with struct btf_encoder as argument Yonghong Song
2025-11-11 17:04 ` Yonghong Song [this message]
2025-11-11 17:04 ` [PATCH dwarves 3/3] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-11-13 16:45 ` [PATCH dwarves 0/3] " Alan Maguire
2025-11-13 17:36 ` Alexei Starovoitov
2025-11-14 15:57 ` Alan Maguire
2025-11-14 20:11 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251111170434.287807-1-yonghong.song@linux.dev \
--to=yonghong.song@linux.dev \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=david.faust@oracle.com \
--cc=dwarves@vger.kernel.org \
--cc=jose.marchesi@oracle.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox