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

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.

Fixes: bae77c5eb5b2 ("bpf: enable stackmap with build_id in nmi context")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Arnd Bergmann and committed by
Daniel Borkmann
dc3b8ae9 53c8036c

+3 -4
+3 -4
kernel/bpf/stackmap.c
··· 285 285 { 286 286 int i; 287 287 struct vm_area_struct *vma; 288 - bool in_nmi_ctx = in_nmi(); 289 288 bool irq_work_busy = false; 290 - struct stack_map_irq_work *work; 289 + struct stack_map_irq_work *work = NULL; 291 290 292 - if (in_nmi_ctx) { 291 + if (in_nmi()) { 293 292 work = this_cpu_ptr(&up_read_work); 294 293 if (work->irq_work.flags & IRQ_WORK_BUSY) 295 294 /* cannot queue more up_read, fallback */ ··· 327 328 id_offs[i].status = BPF_STACK_BUILD_ID_VALID; 328 329 } 329 330 330 - if (!in_nmi_ctx) { 331 + if (!work) { 331 332 up_read(&current->mm->mmap_sem); 332 333 } else { 333 334 work->sem = &current->mm->mmap_sem;