linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: Fix check in global_data_init.
@ 2020-09-03 20:05 Hao Luo
  2020-09-03 20:36 ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Hao Luo @ 2020-09-03 20:05 UTC (permalink / raw)
  To: netdev, bpf, linux-kernel, linux-kselftest
  Cc: Shuah Khan, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh, Hao Luo

The returned value of bpf_object__open_file() should be checked with
libbpf_get_error() rather than NULL. This fix prevents test_progs from
crash when test_global_data.o is not present.

Signed-off-by: Hao Luo <haoluo@google.com>
---
 tools/testing/selftests/bpf/prog_tests/global_data_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 3bdaa5a40744..ee46b11f1f9a 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -12,7 +12,8 @@ void test_global_data_init(void)
 	size_t sz;
 
 	obj = bpf_object__open_file(file, NULL);
-	if (CHECK_FAIL(!obj))
+	err = libbpf_get_error(obj);
+	if (CHECK_FAIL(err))
 		return;
 
 	map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
-- 
2.28.0.526.ge36021eeef-goog


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

* Re: [PATCH] selftests/bpf: Fix check in global_data_init.
  2020-09-03 20:05 [PATCH] selftests/bpf: Fix check in global_data_init Hao Luo
@ 2020-09-03 20:36 ` Andrii Nakryiko
  2020-09-04  0:34   ` Alexei Starovoitov
  0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2020-09-03 20:36 UTC (permalink / raw)
  To: Hao Luo
  Cc: Networking, bpf, open list, open list:KERNEL SELFTEST FRAMEWORK,
	Shuah Khan, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh

On Thu, Sep 3, 2020 at 1:06 PM Hao Luo <haoluo@google.com> wrote:
>
> The returned value of bpf_object__open_file() should be checked with
> libbpf_get_error() rather than NULL. This fix prevents test_progs from
> crash when test_global_data.o is not present.
>
> Signed-off-by: Hao Luo <haoluo@google.com>
> ---

thanks!

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  tools/testing/selftests/bpf/prog_tests/global_data_init.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> index 3bdaa5a40744..ee46b11f1f9a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> @@ -12,7 +12,8 @@ void test_global_data_init(void)
>         size_t sz;
>
>         obj = bpf_object__open_file(file, NULL);
> -       if (CHECK_FAIL(!obj))
> +       err = libbpf_get_error(obj);
> +       if (CHECK_FAIL(err))
>                 return;
>
>         map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
> --
> 2.28.0.526.ge36021eeef-goog
>

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

* Re: [PATCH] selftests/bpf: Fix check in global_data_init.
  2020-09-03 20:36 ` Andrii Nakryiko
@ 2020-09-04  0:34   ` Alexei Starovoitov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2020-09-04  0:34 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Hao Luo, Networking, bpf, open list,
	open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
	Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh

On Thu, Sep 3, 2020 at 1:36 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Thu, Sep 3, 2020 at 1:06 PM Hao Luo <haoluo@google.com> wrote:
> >
> > The returned value of bpf_object__open_file() should be checked with
> > libbpf_get_error() rather than NULL. This fix prevents test_progs from
> > crash when test_global_data.o is not present.
> >
> > Signed-off-by: Hao Luo <haoluo@google.com>
> > ---
>
> thanks!
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

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

* Re: [PATCH] selftests/bpf: Fix check in global_data_init.
  2020-09-03 18:50 ` Andrii Nakryiko
@ 2020-09-03 19:31   ` Hao Luo
  0 siblings, 0 replies; 6+ messages in thread
From: Hao Luo @ 2020-09-03 19:31 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Networking, bpf, open list, open list:KERNEL SELFTEST FRAMEWORK,
	Shuah Khan, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh

No problem! Let me update and resend.

On Thu, Sep 3, 2020 at 11:50 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Thu, Sep 3, 2020 at 11:02 AM Hao Luo <haoluo@google.com> wrote:
> >
> > The returned value of bpf_object__open_file() should be checked with
> > IS_ERR() rather than NULL. This fix makes test_progs not crash when
> > test_global_data.o is not present.
> >
> > Signed-off-by: Hao Luo <haoluo@google.com>
> > ---
> >  tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> > index 3bdaa5a40744..1ece86d5c519 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> > @@ -12,7 +12,7 @@ void test_global_data_init(void)
> >         size_t sz;
> >
> >         obj = bpf_object__open_file(file, NULL);
> > -       if (CHECK_FAIL(!obj))
> > +       if (CHECK_FAIL(IS_ERR(obj)))
>
> Can you please use libbpf_get_error(obj) instead to set a good example
> or not relying on kernel internal macros?
>
> >                 return;
> >
> >         map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
> > --
> > 2.28.0.402.g5ffc5be6b7-goog
> >

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

* Re: [PATCH] selftests/bpf: Fix check in global_data_init.
  2020-09-03 18:01 Hao Luo
@ 2020-09-03 18:50 ` Andrii Nakryiko
  2020-09-03 19:31   ` Hao Luo
  0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2020-09-03 18:50 UTC (permalink / raw)
  To: Hao Luo
  Cc: Networking, bpf, open list, open list:KERNEL SELFTEST FRAMEWORK,
	Shuah Khan, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh

On Thu, Sep 3, 2020 at 11:02 AM Hao Luo <haoluo@google.com> wrote:
>
> The returned value of bpf_object__open_file() should be checked with
> IS_ERR() rather than NULL. This fix makes test_progs not crash when
> test_global_data.o is not present.
>
> Signed-off-by: Hao Luo <haoluo@google.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> index 3bdaa5a40744..1ece86d5c519 100644
> --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> @@ -12,7 +12,7 @@ void test_global_data_init(void)
>         size_t sz;
>
>         obj = bpf_object__open_file(file, NULL);
> -       if (CHECK_FAIL(!obj))
> +       if (CHECK_FAIL(IS_ERR(obj)))

Can you please use libbpf_get_error(obj) instead to set a good example
or not relying on kernel internal macros?

>                 return;
>
>         map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
> --
> 2.28.0.402.g5ffc5be6b7-goog
>

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

* [PATCH] selftests/bpf: Fix check in global_data_init.
@ 2020-09-03 18:01 Hao Luo
  2020-09-03 18:50 ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Hao Luo @ 2020-09-03 18:01 UTC (permalink / raw)
  To: netdev, bpf, linux-kernel, linux-kselftest
  Cc: Shuah Khan, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	Toke Høiland-Jørgensen, KP Singh, Hao Luo

The returned value of bpf_object__open_file() should be checked with
IS_ERR() rather than NULL. This fix makes test_progs not crash when
test_global_data.o is not present.

Signed-off-by: Hao Luo <haoluo@google.com>
---
 tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 3bdaa5a40744..1ece86d5c519 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -12,7 +12,7 @@ void test_global_data_init(void)
 	size_t sz;
 
 	obj = bpf_object__open_file(file, NULL);
-	if (CHECK_FAIL(!obj))
+	if (CHECK_FAIL(IS_ERR(obj)))
 		return;
 
 	map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
-- 
2.28.0.402.g5ffc5be6b7-goog


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

end of thread, other threads:[~2020-09-04  0:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 20:05 [PATCH] selftests/bpf: Fix check in global_data_init Hao Luo
2020-09-03 20:36 ` Andrii Nakryiko
2020-09-04  0:34   ` Alexei Starovoitov
  -- strict thread matches above, loose matches on Subject: below --
2020-09-03 18:01 Hao Luo
2020-09-03 18:50 ` Andrii Nakryiko
2020-09-03 19:31   ` Hao Luo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).