Content-Type: multipart/mixed; boundary="===============8961694725734853930==" MIME-Version: 1.0 From: Jiri Olsa To: kbuild-all@lists.01.org Subject: Re: [PATCH] lib: bpf: Optimized variable usage in the btf_parse_elf function Date: Sun, 09 Oct 2022 14:53:42 +0200 Message-ID: In-Reply-To: <20221009070827.525694-2-kunyu@nfschina.com> List-Id: --===============8961694725734853930== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Sun, Oct 09, 2022 at 03:08:28PM +0800, Li kunyu wrote: > 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 > --- > 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 =3D NULL, *btf_ext_data =3D NULL; > - int err =3D 0, fd =3D -1, idx =3D 0; > + int err, fd, idx =3D 0; > struct btf *btf =3D NULL; > - Elf_Scn *scn =3D NULL; > - Elf *elf =3D 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, st= ruct btf *base_btf, > = > fd =3D open(path, O_RDONLY | O_CLOEXEC); > if (fd < 0) { > - err =3D -errno; > pr_warn("failed to open %s: %s\n", path, strerror(errno)); > - return ERR_PTR(err); > + return ERR_PTR(-errno); hum, pr_warn could potentionally change errno jirka > } > = > err =3D -LIBBPF_ERRNO__FORMAT; > @@ -987,8 +986,6 @@ static struct btf *btf_parse_elf(const char *path, st= ruct btf *base_btf, > } > } > = > - err =3D 0; > - > if (!btf_data) { > err =3D -ENOENT; > goto done; > -- = > 2.18.2 >=20 --===============8961694725734853930==--