From nobody Wed Apr 8 12:13:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CA69C4332F for ; Sat, 8 Oct 2022 08:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbiJHIVm (ORCPT ); Sat, 8 Oct 2022 04:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbiJHIVj (ORCPT ); Sat, 8 Oct 2022 04:21:39 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28828564CF; Sat, 8 Oct 2022 01:21:37 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 623C51E80D9F; Sat, 8 Oct 2022 16:15:33 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MHHnS3oqJkSU; Sat, 8 Oct 2022 16:15:30 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 5AB221E80D9D; Sat, 8 Oct 2022 16:15:29 +0800 (CST) From: Li kunyu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] lib: bpf: Optimized variable usage in the btf_parse_elf function Date: Sat, 8 Oct 2022 16:21:00 +0800 Message-Id: <20221008082100.4323-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, st= ruct 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; =20 @@ -924,9 +924,8 @@ static struct btf *btf_parse_elf(const char *path, stru= ct btf *base_btf, =20 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); } =20 err =3D -LIBBPF_ERRNO__FORMAT; @@ -987,8 +986,6 @@ static struct btf *btf_parse_elf(const char *path, stru= ct btf *base_btf, } } =20 - err =3D 0; - if (!btf_data) { err =3D -ENOENT; goto done; --=20 2.18.2