public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()
@ 2022-11-15 13:00 Tiezhu Yang
  2022-11-15 18:42 ` sdf
  2022-11-16  5:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Tiezhu Yang @ 2022-11-15 13:00 UTC (permalink / raw)
  To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko
  Cc: bpf, linux-kernel

If the parameters for batch are more than 2, check argc first can
return immediately, no need to use is_prefix() 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.

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 741e50e..337ab79 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 (!is_prefix(*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 (!is_prefix(*argv, "file")) {
+		p_err("expected 'file', got: %s", *argv);
+		return -1;
 	}
 	NEXT_ARG();
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()
  2022-11-15 13:00 [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
@ 2022-11-15 18:42 ` sdf
  2022-11-15 20:19   ` Quentin Monnet
  2022-11-16  5:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: sdf @ 2022-11-15 18:42 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, bpf, linux-kernel

On 11/15, Tiezhu Yang wrote:
> If the parameters for batch are more than 2, check argc first can
> return immediately, no need to use is_prefix() 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.

> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>   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 741e50e..337ab79 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 (!is_prefix(*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 (!is_prefix(*argv, "file")) {
> +		p_err("expected 'file', got: %s", *argv);
> +		return -1;
>   	}
>   	NEXT_ARG();

> --
> 2.1.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()
  2022-11-15 18:42 ` sdf
@ 2022-11-15 20:19   ` Quentin Monnet
  0 siblings, 0 replies; 4+ messages in thread
From: Quentin Monnet @ 2022-11-15 20:19 UTC (permalink / raw)
  To: sdf
  Cc: Tiezhu Yang, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, linux-kernel

On Tue, 15 Nov 2022 at 18:42, <sdf@google.com> wrote:
>
> On 11/15, Tiezhu Yang wrote:
> > If the parameters for batch are more than 2, check argc first can
> > return immediately, no need to use is_prefix() 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.
>
> > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>
> Acked-by: Stanislav Fomichev <sdf@google.com>

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()
  2022-11-15 13:00 [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
  2022-11-15 18:42 ` sdf
@ 2022-11-16  5:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-16  5:40 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: quentin, ast, daniel, andrii, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue, 15 Nov 2022 21:00:07 +0800 you wrote:
> If the parameters for batch are more than 2, check argc first can
> return immediately, no need to use is_prefix() 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.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] bpftool: Check argc first before "file" in do_batch()
    https://git.kernel.org/bpf/bpf-next/c/df9c41e9db2d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-16  5:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-15 13:00 [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
2022-11-15 18:42 ` sdf
2022-11-15 20:19   ` Quentin Monnet
2022-11-16  5:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox