public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Liu Jing <liujing@cmss.chinamobile.com>
Cc: Quentin Monnet <qmo@kernel.org>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	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 11:16:42 -0700	[thread overview]
Message-ID: <dd4be9f4-71e3-4d71-bd71-1fda2c9572b6@linux.dev> (raw)
In-Reply-To: <fe9261d8-1e1d-4060-9a7e-1902d75cff7a@kernel.org>

On 10/15/24 5:11 AM, Quentin Monnet wrote:
> 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.

+1

The current code is good as is.

pw-bot: cr


      reply	other threads:[~2024-10-15 18:16 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
2024-10-15 18:16   ` Martin KaFai Lau [this message]

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=dd4be9f4-71e3-4d71-bd71-1fda2c9572b6@linux.dev \
    --to=martin.lau@linux.dev \
    --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=qmo@kernel.org \
    --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