]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
libbpf: Add bpf_object_cleanup_btf function
authorJiri Olsa <jolsa@kernel.org>
Sat, 6 Jun 2026 12:39:42 +0000 (14:39 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 7 Jun 2026 17:03:02 +0000 (10:03 -0700)
Adding bpf_object_cleanup_btf function to cleanup btf objects.
It will be used in following changes.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260606123955.345967-18-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c

index 62f088359c5ed61566a80a53fe935d91322b20ad..5bdaa5eb1f50f0f31a445094c4629bc611304710 100644 (file)
@@ -8941,13 +8941,10 @@ static void bpf_object_unpin(struct bpf_object *obj)
                        bpf_map__unpin(&obj->maps[i], NULL);
 }
 
-static void bpf_object_post_load_cleanup(struct bpf_object *obj)
+static void bpf_object_cleanup_btf(struct bpf_object *obj)
 {
        int i;
 
-       /* clean up fd_array */
-       zfree(&obj->fd_array);
-
        /* clean up module BTFs */
        for (i = 0; i < obj->btf_module_cnt; i++) {
                close(obj->btf_modules[i].fd);
@@ -8955,6 +8952,8 @@ static void bpf_object_post_load_cleanup(struct bpf_object *obj)
                free(obj->btf_modules[i].name);
        }
        obj->btf_module_cnt = 0;
+       obj->btf_module_cap = 0;
+       obj->btf_modules_loaded = false;
        zfree(&obj->btf_modules);
 
        /* clean up vmlinux BTF */
@@ -8962,6 +8961,15 @@ static void bpf_object_post_load_cleanup(struct bpf_object *obj)
        obj->btf_vmlinux = NULL;
 }
 
+static void bpf_object_post_load_cleanup(struct bpf_object *obj)
+{
+       /* clean up fd_array */
+       zfree(&obj->fd_array);
+
+       /* clean up BTF */
+       bpf_object_cleanup_btf(obj);
+}
+
 static int bpf_object_prepare(struct bpf_object *obj, const char *target_btf_path)
 {
        int err;