2022-11-15 13:27:37

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()

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 <[email protected]>
---
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



2022-11-15 19:04:46

by Stanislav Fomichev

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()

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 <[email protected]>

Acked-by: Stanislav Fomichev <[email protected]>

> ---
> 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


2022-11-15 21:42:26

by Quentin Monnet

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()

On Tue, 15 Nov 2022 at 18:42, <[email protected]> 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 <[email protected]>
>
> Acked-by: Stanislav Fomichev <[email protected]>

Reviewed-by: Quentin Monnet <[email protected]>

Thanks

2022-11-16 06:27:51

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2] bpftool: Check argc first before "file" in do_batch()

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <[email protected]>:

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 <[email protected]>
>
> [...]

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