BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Liu Jing <liujing@cmss.chinamobile.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpftool: optimize if statement code
Date: Tue, 15 Oct 2024 13:11:48 +0100	[thread overview]
Message-ID: <fe9261d8-1e1d-4060-9a7e-1902d75cff7a@kernel.org> (raw)
In-Reply-To: <20241015110944.6975-1-liujing@cmss.chinamobile.com>

2024-10-15 19:09 UTC+0800 ~ Liu Jing <liujing@cmss.chinamobile.com>
> Since both conditions are used to check whether len is valid, we can combine the two conditions into a single if statement
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
>   tools/bpf/bpftool/feature.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
> index 4dbc4fcdf473..0121e0fd6949 100644
> --- a/tools/bpf/bpftool/feature.c
> +++ b/tools/bpf/bpftool/feature.c
> @@ -158,10 +158,9 @@ static int get_vendor_id(int ifindex)
>   
>   	len = read(fd, buf, sizeof(buf));
>   	close(fd);
> -	if (len < 0)
> -		return -1;
> -	if (len >= (ssize_t)sizeof(buf))
> +	if ((len < 0) || (len >= (ssize_t)sizeof(buf)))
>   		return -1;
> +
>   	buf[len] = '\0';
>   
>   	return strtol(buf, NULL, 0);


Thanks. I'm not strictly opposed to the change, but it doesn't bring 
much value in my opinion. I don't think this will "optimize" the 
statement beyond what the compiler does already.

Quentin

  reply	other threads:[~2024-10-15 12:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 11:09 [PATCH] bpftool: optimize if statement code Liu Jing
2024-10-15 12:11 ` Quentin Monnet [this message]
2024-10-15 18:16   ` Martin KaFai Lau

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=fe9261d8-1e1d-4060-9a7e-1902d75cff7a@kernel.org \
    --to=qmo@kernel.org \
    --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=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liujing@cmss.chinamobile.com \
    --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