Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Avoid -Wflex-array-members-not-at-end warnings

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>

authored by

Gustavo A. R. Silva and committed by
Alexei Starovoitov
18474aed 42e33c9a

+9 -12
+1 -1
include/linux/bpf-cgroup.h
··· 184 184 struct bpf_prog_array *array; 185 185 186 186 array = rcu_access_pointer(cgrp->bpf.effective[type]); 187 - return array != &bpf_empty_prog_array.hdr; 187 + return array != &bpf_empty_prog_array; 188 188 } 189 189 190 190 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */
+1 -6
include/linux/bpf.h
··· 2369 2369 struct bpf_prog_array_item items[]; 2370 2370 }; 2371 2371 2372 - struct bpf_empty_prog_array { 2373 - struct bpf_prog_array hdr; 2374 - struct bpf_prog *null_prog; 2375 - }; 2376 - 2377 2372 /* to avoid allocating empty bpf_prog_array for cgroups that 2378 2373 * don't have bpf program attached use one global 'bpf_empty_prog_array' 2379 2374 * It will not be modified the caller of bpf_prog_array_alloc() 2380 2375 * (since caller requested prog_cnt == 0) 2381 2376 * that pointer should be 'freed' by bpf_prog_array_free() 2382 2377 */ 2383 - extern struct bpf_empty_prog_array bpf_empty_prog_array; 2378 + extern struct bpf_prog_array bpf_empty_prog_array; 2384 2379 2385 2380 struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags); 2386 2381 void bpf_prog_array_free(struct bpf_prog_array *progs);
+7 -5
kernel/bpf/core.c
··· 2614 2614 }, 2615 2615 }; 2616 2616 2617 - struct bpf_empty_prog_array bpf_empty_prog_array = { 2618 - .null_prog = NULL, 2617 + struct bpf_prog_array bpf_empty_prog_array = { 2618 + .items = { 2619 + { .prog = NULL }, 2620 + }, 2619 2621 }; 2620 2622 EXPORT_SYMBOL(bpf_empty_prog_array); 2621 2623 ··· 2628 2626 if (prog_cnt) 2629 2627 p = kzalloc_flex(*p, items, prog_cnt + 1, flags); 2630 2628 else 2631 - p = &bpf_empty_prog_array.hdr; 2629 + p = &bpf_empty_prog_array; 2632 2630 2633 2631 return p; 2634 2632 } 2635 2633 2636 2634 void bpf_prog_array_free(struct bpf_prog_array *progs) 2637 2635 { 2638 - if (!progs || progs == &bpf_empty_prog_array.hdr) 2636 + if (!progs || progs == &bpf_empty_prog_array) 2639 2637 return; 2640 2638 kfree_rcu(progs, rcu); 2641 2639 } ··· 2656 2654 2657 2655 void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs) 2658 2656 { 2659 - if (!progs || progs == &bpf_empty_prog_array.hdr) 2657 + if (!progs || progs == &bpf_empty_prog_array) 2660 2658 return; 2661 2659 call_rcu_tasks_trace(&progs->rcu, __bpf_prog_array_free_sleepable_cb); 2662 2660 }