Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Memory leak of `module_btf` when a module does not have a 
corresponding `.inline` sysfs file.
--

commit ae17979b11eeb1a7bef7bec7a8817be3cb2cd64a
Author: Alan Maguire <[email protected]>

selftests/bpf: Test BTF sysfs inline representations

This commit adds a selftest to validate BTF sysfs inline representations for
the kernel and modules. It parses the base BTF, module BTF, and inline BTF 
files to ensure proper loading and relocation across different scenarios.

> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c 
> b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
> index 3923e64c4c1d0..97eccfd7c1344 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_sysfs.c
[ ... ]
> +static void test_btf_inline_sysfs_all(void)
> +{
[ ... ]
> +     while ((dentry = readdir(dir)) != NULL) {
[ ... ]
> +             if (!base_btf) {
> +                     module_btf = btf__parse_split(btf_path, vmlinux_btf);
> +                     err = libbpf_get_error(module_btf);
> +                     if (err) {
> +                             /* A module can be unloaded while its sysfs 
> entry is iterated. */
> +                             if (err == -ENOENT)
> +                                     continue;
> +                             ASSERT_OK(err, "parse_module_btf");
> +                             continue;
> +                     }
> +                     base_btf = module_btf;
> +             }
> +             if (stat(inline_path, &st)) {
> +                     err = errno;
> +                     if (err == ENOENT)
> +                             continue;

[Severity: Medium]
Does this code leak module_btf?

In test_btf_inline_sysfs_all(), when a module is parsed successfully but
lacks a corresponding .inline sysfs file, stat() fails with ENOENT and this
path calls continue. Since this ends the loop iteration early, the
btf__free(module_btf) at the bottom of the loop is bypassed.

> +                     ASSERT_OK(err, "stat_inline_btf");
> +             }
> +             inline_btf = btf__parse_split(inline_path, base_btf);
> +             err = libbpf_get_error(inline_btf);
> +             if (!err)
> +                     btf__free(inline_btf);
> +             ASSERT_OK(err, "parse_inline_btf");
> +             btf__free(module_btf);
> +     }
> +     closedir(dir);

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=17

Reply via email to