From nobody Tue Apr 7 00:20:30 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 65949C433FE for ; Sun, 9 Oct 2022 07:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbiJIHJq (ORCPT ); Sun, 9 Oct 2022 03:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiJIHJh (ORCPT ); Sun, 9 Oct 2022 03:09:37 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A083E1F5; Sun, 9 Oct 2022 00:09:34 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id CAEA81E80CAE; Sun, 9 Oct 2022 15:03:29 +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 2Egupsgxpkmd; Sun, 9 Oct 2022 15:03:27 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id D3C5B1E80CE4; Sun, 9 Oct 2022 15:03:19 +0800 (CST) From: Li kunyu 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 Message-Id: <20221009070827.525694-2-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <202210082050.nPzAbV1v-lkp@intel.com> References: <202210082050.nPzAbV1v-lkp@intel.com> 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