> diff --git a/tools/testing/selftests/bpf/prog_tests/memcg_ops.c 
> b/tools/testing/selftests/bpf/prog_tests/memcg_ops.c
> index 9a8d16296f2d..bab9f3094f59 100644
> --- a/tools/testing/selftests/bpf/prog_tests/memcg_ops.c
> +++ b/tools/testing/selftests/bpf/prog_tests/memcg_ops.c

[ ... ]

> +void test_memcg_ops_hierarchies(void)
> +{
> +     int ret, first = -1, second = -1, third = -1;
> +     struct memcg_ops *skel;
> +     struct bpf_map *map;
> +     struct bpf_link *link1 = NULL, *link2 = NULL, *link3 = NULL;

[ ... ]

> +     opts.relative_fd = second;
> +     opts.flags = 0;
> +     link2 = bpf_map__attach_struct_ops_opts(map, &opts);
> +     if (!ASSERT_OK_PTR(link2, "bpf_map__attach_struct_ops_opts"))
> +             goto cleanup;
> +
> +     opts.relative_fd = third;
> +     opts.flags = 0;
> +     link2 = bpf_map__attach_struct_ops_opts(map, &opts);
> +     if (!ASSERT_ERR_PTR(link3, "bpf_map__attach_struct_ops_opts"))
                          ^^^^^

The result of the third bpf_map__attach_struct_ops_opts() call is stored in
link2, but the assertion checks link3. Since link3 is initialized to NULL
and never modified, the ASSERT_ERR_PTR check does not validate the actual
return value of the third attachment.

Should this be assigning to link3 instead of link2?

> +             goto cleanup;
> +
> +cleanup:
> +     bpf_link__destroy(link1);
> +     bpf_link__destroy(link2);

If the fix is to use link3 for the third attachment result, should
bpf_link__destroy(link3) be added here as well?

> +     memcg_ops__detach(skel);
> +     close(first);
> +     close(second);
> +     close(third);
> +     cleanup_cgroup_environment();
> +}


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21280790825

Reply via email to