mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Jianyun Gao <jianyungao89@gmail.com>
Cc: linux-kernel@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	"open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)"
	<bpf@vger.kernel.org>
Subject: Re: [PATCH] libbpf: optimize the redundant code in the bpf_object__init_user_btf_maps() function.
Date: Fri, 24 Oct 2025 08:57:13 +0200	[thread overview]
Message-ID: <aPsjSZtNxeQK239J@krava> (raw)
In-Reply-To: <20251024060720.634826-1-jianyungao89@gmail.com>

On Fri, Oct 24, 2025 at 02:07:20PM +0800, Jianyun Gao wrote:
> In the elf_sec_data() function, the input parameter 'scn' will be
> evaluated. If it is NULL, then it will directly return NULL. Therefore,
> the return value of the elf_sec_data() function already takes into
> account the case where the input parameter scn is NULL. Therefore,
> subsequently, the code only needs to check whether the return value of
> the elf_sec_data() function is NULL.
> 
> Signed-off-by: Jianyun Gao <jianyungao89@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index b90574f39d1c..9e66104a61eb 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2988,15 +2988,15 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,
>  	int nr_types, i, vlen, err;
>  	const struct btf_type *t;
>  	const char *name;
> -	Elf_Data *data;
> +	Elf_Data *scn_data;

makes sense to me, but this rename breaks compilation later on

libbpf.c:3027:53: error: ‘data’ undeclared (first use in this function)

jirka

>  	Elf_Scn *scn;
>  
>  	if (obj->efile.btf_maps_shndx < 0)
>  		return 0;
>  
>  	scn = elf_sec_by_idx(obj, obj->efile.btf_maps_shndx);
> -	data = elf_sec_data(obj, scn);
> -	if (!scn || !data) {
> +	scn_data = elf_sec_data(obj, scn);
> +	if (!scn_data) {
>  		pr_warn("elf: failed to get %s map definitions for %s\n",
>  			MAPS_ELF_SEC, obj->path);
>  		return -EINVAL;
> -- 
> 2.34.1
> 

  reply	other threads:[~2025-10-24  6:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-24  6:07 Jianyun Gao
2025-10-24  6:57 ` Jiri Olsa [this message]
2025-10-24  7:55   ` Jianyun Gao

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=aPsjSZtNxeQK239J@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jianyungao89@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®