From: Li kunyu <kunyu@nfschina.com>
To: lkp@intel.com
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, haoluo@google.com,
john.fastabend@gmail.com, jolsa@kernel.org,
kbuild-all@lists.01.org, kpsingh@kernel.org, kunyu@nfschina.com,
linux-kernel@vger.kernel.org, martin.lau@linux.dev,
sdf@google.com, song@kernel.org, yhs@fb.com
Subject: [PATCH] lib: bpf: Optimized variable usage in the btf_parse_elf function
Date: Sun, 9 Oct 2022 15:08:28 +0800 [thread overview]
Message-ID: <20221009070827.525694-2-kunyu@nfschina.com> (raw)
In-Reply-To: <202210082050.nPzAbV1v-lkp@intel.com>
The following changes were made in the btf_parse_elf function:
1. The initialization assignments of err, fd, scn and elf variables are
removed, and they do not affect function security after analysis.
2. Remove unnecessary assignments to err variable (-error).
Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
tools/lib/bpf/btf.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 2d14f1a52d7a..fa9d5fa03da4 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -910,10 +910,10 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
struct btf_ext **btf_ext)
{
Elf_Data *btf_data = NULL, *btf_ext_data = NULL;
- int err = 0, fd = -1, idx = 0;
+ int err, fd, idx = 0;
struct btf *btf = NULL;
- Elf_Scn *scn = NULL;
- Elf *elf = NULL;
+ Elf_Scn *scn;
+ Elf *elf;
GElf_Ehdr ehdr;
size_t shstrndx;
@@ -924,9 +924,8 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
- err = -errno;
pr_warn("failed to open %s: %s\n", path, strerror(errno));
- return ERR_PTR(err);
+ return ERR_PTR(-errno);
}
err = -LIBBPF_ERRNO__FORMAT;
@@ -987,8 +986,6 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
}
}
- err = 0;
-
if (!btf_data) {
err = -ENOENT;
goto done;
--
2.18.2
next parent reply other threads:[~2022-10-09 7:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <202210082050.nPzAbV1v-lkp@intel.com>
2022-10-09 7:08 ` Li kunyu [this message]
2022-10-09 12:53 ` [PATCH] lib: bpf: Optimized variable usage in the btf_parse_elf function Jiri Olsa
2022-10-08 8:21 Li kunyu
2022-10-08 11:06 ` kernel test robot
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=20221009070827.525694-2-kunyu@nfschina.com \
--to=kunyu@nfschina.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kbuild-all@lists.01.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@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