selftests/bpf: fix incorrect users of create_and_get_cgroup
Subsystems (5)
PATCH 1/1 selftests/bpf: fix incorrect users of create_and_get_cgroup
create_and_get_cgroup returns 0 on error, fix the users that assume negative value in case of an error.
--- tools/testing/selftests/bpf/get_cgroup_id_user.c | 2 +- tools/testing/selftests/bpf/test_sockmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/get_cgroup_id_user.c +1 -1
@@ -64,7 +64,7 @@ int main(int argc, char **argv)return 1 ; cgroup_fd =create_and_get_cgroup (TEST_CGROUP ); -if (CHECK (cgroup_fd <0 ,"create_and_get_cgroup" ,"err %d errno %d\n" , +if (CHECK (!cgroup_fd,"create_and_get_cgroup" ,"err %d errno %d\n" , cgroup_fd, errno)) goto cleanup_cgroup_env;
tools/testing/selftests/bpf/test_sockmap.c +1 -1
@@ -1676,7 +1676,7 @@ static int __test_suite(int cg_fd, char *bpf_file) } cg_fd =create_and_get_cgroup (CG_PATH ); -if (cg_fd <0 ) { +if (!cg_fd) {fprintf (stderr,"ERROR: (%i) open cg path failed: %s\n" , cg_fd, optarg);
Signature · 1 line
2.20.1.415.g653613c723-goog
Quoted 5 lines · Stanislav Fomichev
create_and_get_cgroupreturns 0 on error, fix the users that assume negative value in case of an error.Signed-off-by Stanislav Fomichev <[email protected]>
Thanks for the fix!
Quoted 4 lines
--- tools/testing/selftests/bpf/get_cgroup_id_user.c | 2 +- tools/testing/selftests/bpf/test_sockmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines · Stanislav Fomichev
create_and_get_cgroupreturns 0 on error, fix the users that assume negative value in case of an error.Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/get_cgroup_id_user.c | 2 +- tools/testing/selftests/bpf/test_sockmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/get_cgroup_id_user.c +0
-0
tools/testing/selftests/bpf/get_cgroup_id_user.c int main(int argc, char **argv) · line 67
Quoted 5 lines
tools/testing/selftests/bpf/get_cgroup_id_user.c +1
-1@@ -64,7 +64,7 @@ int main(int argc, char **argv)return 1 ; cgroup_fd =create_and_get_cgroup (TEST_CGROUP ); - if (CHECK(cgroup_fd < 0, "create_and_get_cgroup", "err %d errno %d\n", + if (CHECK(!cgroup_fd, "create_and_get_cgroup", "err %d errno %d\n",
fd can be zero.
Hence I prefer to fix it the other way to avoid this corner case. Pls fix create_and_get_cgroup() to return -1 in case of error. The diff will be much bigger, but overall it's imo cleaner. Also pls add Fixes tag.
Thanks
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Stanislav Fomichev
create_and_get_cgroupreturns 0 on error, fix the users that assume negative value in case of an error.Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/get_cgroup_id_user.c | 2 +- tools/testing/selftests/bpf/test_sockmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/get_cgroup_id_user.c +0
-0@@ -64,7 +64,7 @@ int main(int argc, char **argv)return 1 ;
Quoted 5 lines
tools/testing/selftests/bpf/get_cgroup_id_user.c int main(int argc, char **argv) · line 67
Quoted 3 lines
tools/testing/selftests/bpf/get_cgroup_id_user.c +1
-1cgroup_fd =create_and_get_cgroup (TEST_CGROUP ); - if (CHECK(cgroup_fd < 0, "create_and_get_cgroup", "err %d errno %d\n", + if (CHECK(!cgroup_fd, "create_and_get_cgroup", "err %d errno %d\n",fd can be zero.
Assumed it was fine for the test where we never close stdin.
Quoted 3 lines
Hence I prefer to fix it the other way to avoid this corner case. Pls fix
create_and_get_cgroup()to return -1 in case of error. The diff will be much bigger, but overall it's imo cleaner.
Agree, will sent a v2 shortly.
Quoted 4 lines
Also pls add Fixes tag.
Thanks