All of lore.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Quentin Monnet <quentin@isovalent.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch()
Date: Mon, 14 Nov 2022 09:30:17 -0800	[thread overview]
Message-ID: <Y3J7KW1xQc7aO18/@google.com> (raw)
In-Reply-To: <1668396484-4596-3-git-send-email-yangtiezhu@loongson.cn>

On 11/14, Tiezhu Yang wrote:
> If the parameters for batch are more than 2, check argc first can
> return immediately, no need to use strcmp() to check "file" with
> a little overhead and then check argc, it is better to check "file"
> only when the parameters for batch are 2.

Seems fine if you respin with is_prefix instead of strcmp.
Has the potential of breaking some buggy users which pass
more than one file, but I don't think it's a good justification
no to do the fix? Quentin?


> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>   tools/bpf/bpftool/main.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index 4ef87c2..27d6dbf 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -337,12 +337,12 @@ static int do_batch(int argc, char **argv)
>   	if (argc < 2) {
>   		p_err("too few parameters for batch");
>   		return -1;
> -	} else if (strcmp(*argv, "file")) {
> -		p_err("expected 'file', got: %s", *argv);
> -		return -1;
>   	} else if (argc > 2) {
>   		p_err("too many parameters for batch");
>   		return -1;
> +	} else if (strcmp(*argv, "file")) {
> +		p_err("expected 'file', got: %s", *argv);
> +		return -1;
>   	}
>   	NEXT_ARG();

> --
> 2.1.0


  reply	other threads:[~2022-11-14 17:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14  3:28 [PATCH bpf-next 0/2] Some small changes about bpftool Tiezhu Yang
2022-11-14  3:28 ` [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters Tiezhu Yang
2022-11-14 17:25   ` sdf
2022-11-14 20:45     ` Quentin Monnet
2022-11-14  3:28 ` [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
2022-11-14 17:30   ` sdf [this message]
2022-11-14 20:53     ` Quentin Monnet

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=Y3J7KW1xQc7aO18/@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin@isovalent.com \
    --cc=yangtiezhu@loongson.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.