]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Avoid using ARRAY_SIZE on an uninitialized pointer
authorFlorent Revest <revest@chromium.org>
Mon, 17 May 2021 09:28:30 +0000 (11:28 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 20 May 2021 21:48:38 +0000 (23:48 +0200)
commit0af02eb2a7d76ca85a1ecaf4b3775e2c86408fab
tree258cbac9f9e49aca8f960e3eb45f200189b2ffd2
parent8afcc19fbf083a8459284d9a29b4b5ac1cb2396c
bpf: Avoid using ARRAY_SIZE on an uninitialized pointer

The cppcheck static code analysis reported the following error:

    if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(bufs->tmp_bufs))) {
                                             ^
ARRAY_SIZE is a macro that expands to sizeofs, so bufs is not actually
dereferenced at runtime, and the code is actually safe. But to keep
things tidy, this patch removes the need for a call to ARRAY_SIZE by
extracting the size of the array into a macro. Cppcheck should no longer
be confused and the code ends up being a bit cleaner.

Fixes: e2d5b2bb769f ("bpf: Fix nested bpf_bprintf_prepare with more per-cpu buffers")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Florent Revest <revest@chromium.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/bpf/20210517092830.1026418-2-revest@chromium.org
kernel/bpf/helpers.c