bpf: btf: avoid -Wreturn-type warning
Subsystems (4)
PATCH 1/2 bpf: btf: avoid -Wreturn-type warning
gcc warns about a noreturn function possibly returning in some configurations:
kernel/bpf/btf.c: In function 'env_type_is_resolve_sink':kernel/bpf/btf.c:729:1: error: control reaches end of non-void function [-Werror=return-type]
Using BUG() instead of BUG_ON() avoids that warning and otherwise does the exact same thing.
--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -749,7 +749,7 @@ static bool env_type_is_resolve_sink(const struct btf_verifier_env *env, !btf_type_is_array (next_type) && !btf_type_is_struct (next_type);default : -BUG_ON (1 ); +BUG (); } }
Signature · 1 line
2.9.0
PATCH 2/2 bpf: avoid -Wmaybe-uninitialized warning
The stack_map_get_build_id_offset() function is too long for gcc to track whether 'work' may or may not be initialized at the end of it, leading to a false-positive warning:
kernel/bpf/stackmap.c: In function 'stack_map_get_build_id_offset':kernel/bpf/stackmap.c:334:13: error: 'work' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This removes the 'in_nmi_ctx' flag and uses the state of that variable itself to see if it got initialized.
--- kernel/bpf/stackmap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/bpf/stackmap.c +3 -4
@@ -285,11 +285,10 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, {int i;struct vm_area_struct *vma; -bool in_nmi_ctx =in_nmi ();bool irq_work_busy = false; -struct stack_map_irq_work *work; +struct stack_map_irq_work *work =NULL ; -if (in_nmi_ctx) { +if (in_nmi ()) { work =this_cpu_ptr (&up_read_work);if (work->irq_work.flags &IRQ_WORK_BUSY )/* cannot queue more up_read, fallback */
@@ -328,7 +327,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, id_offs[i].status =BPF_STACK_BUILD_ID_VALID ; } -if (!in_nmi_ctx) { +if (!work) {up_read (¤t->mm->mmap_sem); }else { work->sem = ¤t->mm->mmap_sem;
Signature · 1 line
2.9.0
Re: [PATCH, net-next 2/2] bpf: avoid -Wmaybe-uninitialized warning
Quoted 49 lines · Arnd Bergmann
The
stack_map_get_build_id_offset()function is too long for gcc to track whether 'work' may or may not be initialized at the end of it, leading to a false-positive warning:
kernel/bpf/stackmap.c: In function 'stack_map_get_build_id_offset':kernel/bpf/stackmap.c:334:13: error: 'work' may be used uninitialized in this function [-Werror=maybe-uninitialized]This removes the '
in_nmi_ctx' flag and uses the state of that variable itself to see if it got initialized.Fixes bae77c5eb5b2 ("bpf: enable stackmap with build_id in nmi context")Signed-off-by Arnd Bergmann <[email protected]>---
kernel/bpf/stackmap.c| 7 +++----1 file changed, 3 insertions(+), 4 deletions(-)kernel/bpf/stackmap.c +3
-4@@ -285,11 +285,10 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, {int i;struct vm_area_struct *vma; -bool in_nmi_ctx =in_nmi ();bool irq_work_busy = false; -struct stack_map_irq_work *work; +struct stack_map_irq_work *work =NULL ; -if (in_nmi_ctx) { +if (in_nmi ()) { work =this_cpu_ptr (&up_read_work);if (work->irq_work.flags &IRQ_WORK_BUSY )/* cannot queue more up_read, fallback */ @@ -328,7 +327,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, id_offs[i].status =BPF_STACK_BUILD_ID_VALID ; } -if (!in_nmi_ctx) { +if (!work) {up_read (¤t->mm->mmap_sem); }else { work->sem = ¤t->mm->mmap_sem;Signature · 1 line
2.9.0
Re: [PATCH, net-next 2/2] bpf: avoid -Wmaybe-uninitialized warning
In reply to Arnd BergmannQuoted 4 lines · Arnd Bergmann
The
stack_map_get_build_id_offset()function is too long for gcc to track whether 'work' may or may not be initialized at the end of it, leading to a false-positive warning:
Quoted 8 lines
kernel/bpf/stackmap.c: In function 'stack_map_get_build_id_offset':kernel/bpf/stackmap.c:334:13: error: 'work' may be used uninitialized in this function [-Werror=maybe-uninitialized]This removes the '
in_nmi_ctx' flag and uses the state of that variable itself to see if it got initialized.Fixes bae77c5eb5b2 ("bpf: enable stackmap with build_id in nmi context")Signed-off-by Arnd Bergmann <[email protected]>
Applied to bpf-next, thanks Arnd!
Quoted 35 lines · Arnd Bergmann
gcc warns about a noreturn function possibly returning in some configurations:
kernel/bpf/btf.c: In function 'env_type_is_resolve_sink':kernel/bpf/btf.c:729:1: error: control reaches end of non-void function [-Werror=return-type]Using
BUG()instead ofBUG_ON()avoids that warning and otherwise does the exact same thing.Fixes eb3f595dab40 ("bpf: btf: Validate type reference")Signed-off-by Arnd Bergmann <[email protected]>---
kernel/bpf/btf.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/btf.c +1
-1@@ -749,7 +749,7 @@ static bool env_type_is_resolve_sink(const struct btf_verifier_env *env, !btf_type_is_array (next_type) && !btf_type_is_struct (next_type);default : -BUG_ON (1 ); +BUG (); } }Signature · 1 line
2.9.0
Quoted 11 lines · Arnd Bergmann
gcc warns about a noreturn function possibly returning in some configurations:
kernel/bpf/btf.c: In function 'env_type_is_resolve_sink':kernel/bpf/btf.c:729:1: error: control reaches end of non-void function [-Werror=return-type]Using
BUG()instead ofBUG_ON()avoids that warning and otherwise does the exact same thing.Fixes eb3f595dab40 ("bpf: btf: Validate type reference")Signed-off-by Arnd Bergmann <[email protected]>
Applied to bpf-next, thanks Arnd!