]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Avoid -Wflex-array-members-not-at-end warnings
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 30 Mar 2026 22:38:18 +0000 (16:38 -0600)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 7 Apr 2026 01:37:52 +0000 (18:37 -0700)
Apparently, struct bpf_empty_prog_array exists entirely to populate a
single element of "items" in a global variable. "null_prog" is only
used during the initializer.

None of this is needed; globals will be correctly sized with an array
initializer of a flexible-array member.

So, remove struct bpf_empty_prog_array and adjust the rest of the code,
accordingly.

With these changes, fix the following warnings:

./include/linux/bpf.h:2369:31: warning: structure containing a flexible
array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Link: https://lore.kernel.org/r/acr7Whmn0br3xeBP@kspp
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf-cgroup.h
include/linux/bpf.h
kernel/bpf/core.c

index 2f535331f9264fe0d676b7027edce1863c9b5158..b2e79c2b41d5169bebf0ad256e00c1295e5c1900 100644 (file)
@@ -184,7 +184,7 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
        struct bpf_prog_array *array;
 
        array = rcu_access_pointer(cgrp->bpf.effective[type]);
-       return array != &bpf_empty_prog_array.hdr;
+       return array != &bpf_empty_prog_array;
 }
 
 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */
index 35b1e25bd1043702ef8a2710eece01055cff6bc7..30d35d5fe40b5ae2e3f5bec2c46599f2206bb838 100644 (file)
@@ -2369,18 +2369,13 @@ struct bpf_prog_array {
        struct bpf_prog_array_item items[];
 };
 
-struct bpf_empty_prog_array {
-       struct bpf_prog_array hdr;
-       struct bpf_prog *null_prog;
-};
-
 /* to avoid allocating empty bpf_prog_array for cgroups that
  * don't have bpf program attached use one global 'bpf_empty_prog_array'
  * It will not be modified the caller of bpf_prog_array_alloc()
  * (since caller requested prog_cnt == 0)
  * that pointer should be 'freed' by bpf_prog_array_free()
  */
-extern struct bpf_empty_prog_array bpf_empty_prog_array;
+extern struct bpf_prog_array bpf_empty_prog_array;
 
 struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags);
 void bpf_prog_array_free(struct bpf_prog_array *progs);
index 57811c07aa840c360831c1921ee57abbc60062c8..ee632f41bd83a4886ea8d111040235e8e9833096 100644 (file)
@@ -2614,8 +2614,10 @@ static struct bpf_prog_dummy {
        },
 };
 
-struct bpf_empty_prog_array bpf_empty_prog_array = {
-       .null_prog = NULL,
+struct bpf_prog_array bpf_empty_prog_array = {
+       .items = {
+               { .prog = NULL },
+       },
 };
 EXPORT_SYMBOL(bpf_empty_prog_array);
 
@@ -2626,14 +2628,14 @@ struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags)
        if (prog_cnt)
                p = kzalloc_flex(*p, items, prog_cnt + 1, flags);
        else
-               p = &bpf_empty_prog_array.hdr;
+               p = &bpf_empty_prog_array;
 
        return p;
 }
 
 void bpf_prog_array_free(struct bpf_prog_array *progs)
 {
-       if (!progs || progs == &bpf_empty_prog_array.hdr)
+       if (!progs || progs == &bpf_empty_prog_array)
                return;
        kfree_rcu(progs, rcu);
 }
@@ -2654,7 +2656,7 @@ static void __bpf_prog_array_free_sleepable_cb(struct rcu_head *rcu)
 
 void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs)
 {
-       if (!progs || progs == &bpf_empty_prog_array.hdr)
+       if (!progs || progs == &bpf_empty_prog_array)
                return;
        call_rcu_tasks_trace(&progs->rcu, __bpf_prog_array_free_sleepable_cb);
 }