[rostedt-trace:ftrace/core 2/2] kernel/trace/pid_list.c:439:6: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]

From: kernel test robot
Date: Sun Oct 10 2021 - 05:46:37 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git ftrace/core
head: c8d01c02b46e599b057d7d24d1342ae9fcf828c2
commit: c8d01c02b46e599b057d7d24d1342ae9fcf828c2 [2/2] tracing: Create a sparse bitmask for pid filtering
config: riscv-randconfig-c006-20210927 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dc6e8dfdfe7efecfda318d43a06fae18b40eb498)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git/commit/?id=c8d01c02b46e599b057d7d24d1342ae9fcf828c2
git remote add rostedt-trace https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
git fetch --no-tags rostedt-trace ftrace/core
git checkout c8d01c02b46e599b057d7d24d1342ae9fcf828c2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv clang-analyzer

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>


clang-analyzer warnings: (new ones prefixed by >>)

>> kernel/trace/pid_list.c:439:6: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
if (upper) {
^~~~~
kernel/trace/pid_list.c:398:2: note: 'upper' declared without an initial value
union upper_chunk *upper;
^~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/pid_list.c:413:6: note: Assuming 'upper_count' is > 0
if (upper_count <= 0 && lower_count <= 0)
^~~~~~~~~~~~~~~~
kernel/trace/pid_list.c:413:23: note: Left side of '&&' is false
if (upper_count <= 0 && lower_count <= 0)
^
kernel/trace/pid_list.c:416:2: note: Loop condition is true. Entering loop body
while (upper_count-- > 0) {
^
kernel/trace/pid_list.c:420:7: note: Assuming 'chunk' is null
if (!chunk)
^~~~~~
kernel/trace/pid_list.c:420:3: note: Taking true branch
if (!chunk)
^
kernel/trace/pid_list.c:421:4: note: Execution continues on line 427
break;
^
kernel/trace/pid_list.c:427:9: note: Assuming the condition is false
while (lower_count-- > 0) {
^~~~~~~~~~~~~~~~~
kernel/trace/pid_list.c:427:2: note: Loop condition is false. Execution continues on line 438
while (lower_count-- > 0) {
^
kernel/trace/pid_list.c:439:6: note: Branch condition evaluates to a garbage value
if (upper) {
^~~~~
kernel/trace/pid_list.c:444:6: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
if (lower) {
^~~~~

vim +439 kernel/trace/pid_list.c

c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 393)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 394) static void pid_list_refill_irq(struct irq_work *iwork)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 395) {
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 396) struct trace_pid_list *pid_list = container_of(iwork, struct trace_pid_list,
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 397) refill_irqwork);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 398) union upper_chunk *upper;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 399) union lower_chunk *lower;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 400) union upper_chunk **upper_next = &upper;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 401) union lower_chunk **lower_next = &lower;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 402) int upper_count;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 403) int lower_count;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 404) int ucnt = 0;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 405) int lcnt = 0;
eff05923d317af7 Steven Rostedt (VMware 2021-09-23 406)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 407) again:
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 408) raw_spin_lock(&pid_list->lock);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 409) upper_count = CHUNK_ALLOC - pid_list->free_upper_chunks;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 410) lower_count = CHUNK_ALLOC - pid_list->free_lower_chunks;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 411) raw_spin_unlock(&pid_list->lock);
eff05923d317af7 Steven Rostedt (VMware 2021-09-23 412)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 413) if (upper_count <= 0 && lower_count <= 0)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 414) return;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 415)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 416) while (upper_count-- > 0) {
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 417) union upper_chunk *chunk;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 418)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 419) chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 420) if (!chunk)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 421) break;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 422) *upper_next = chunk;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 423) upper_next = &chunk->next;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 424) ucnt++;
eff05923d317af7 Steven Rostedt (VMware 2021-09-23 425) }
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 426)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 427) while (lower_count-- > 0) {
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 428) union lower_chunk *chunk;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 429)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 430) chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 431) if (!chunk)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 432) break;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 433) *lower_next = chunk;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 434) lower_next = &chunk->next;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 435) lcnt++;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 436) }
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 437)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 438) raw_spin_lock(&pid_list->lock);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 @439) if (upper) {
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 440) *upper_next = pid_list->upper_list;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 441) pid_list->upper_list = upper;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 442) pid_list->free_upper_chunks += ucnt;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 443) }
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 444) if (lower) {
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 445) *lower_next = pid_list->lower_list;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 446) pid_list->lower_list = lower;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 447) pid_list->free_lower_chunks += lcnt;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 448) }
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 449) raw_spin_unlock(&pid_list->lock);
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 450)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 451) /*
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 452) * On success of allocating all the chunks, both counters
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 453) * will be less than zero. If they are not, then an allocation
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 454) * failed, and we should not try again.
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 455) */
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 456) if (upper_count >= 0 || lower_count >= 0)
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 457) return;
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 458) /*
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 459) * When the locks were released, free chunks could have
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 460) * been used and allocation needs to be done again. Might as
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 461) * well allocate it now.
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 462) */
c8d01c02b46e599 Steven Rostedt (VMware 2021-09-23 463) goto again;
eff05923d317af7 Steven Rostedt (VMware 2021-09-23 464) }
eff05923d317af7 Steven Rostedt (VMware 2021-09-23 465)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip