[jolsa-perf:ftrace/direct 5/8] kernel/trace/ftrace.c:5150:4: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
From: kernel test robot
Date: Fri Sep 03 2021 - 06:13:17 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git ftrace/direct
head: 95a037919f1906d8bf164fb0c0066c9f298df139
commit: b45bdf4de5473d5c15090eceeb72a2d5082cde2d [5/8] ftrace: Add ftrace_add_rec_direct function
:::::: branch date: 32 hours ago
:::::: commit date: 32 hours ago
config: i386-randconfig-c001-20210831 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 4b1fde8a2b681dad2ce0c082a5d6422caa06b0bc)
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
# https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/commit/?id=b45bdf4de5473d5c15090eceeb72a2d5082cde2d
git remote add jolsa-perf https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
git fetch --no-tags jolsa-perf ftrace/direct
git checkout b45bdf4de5473d5c15090eceeb72a2d5082cde2d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 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/ftrace.c:5150:4: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
kfree(entry);
^ ~~~~~
kernel/trace/ftrace.c:5114:2: note: 'entry' declared without an initial value
struct ftrace_func_entry *entry;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5122:6: note: Calling 'ftrace_find_rec_direct'
if (ftrace_find_rec_direct(ip))
^~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:2391:6: note: Assuming 'entry' is null, which participates in a condition later
if (!entry)
^~~~~~
kernel/trace/ftrace.c:2391:2: note: Taking true branch
if (!entry)
^
kernel/trace/ftrace.c:2392:3: note: Returning zero, which participates in a condition later
return 0;
^~~~~~~~
kernel/trace/ftrace.c:5122:6: note: Returning from 'ftrace_find_rec_direct'
if (ftrace_find_rec_direct(ip))
^~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5122:2: note: Taking false branch
if (ftrace_find_rec_direct(ip))
^
kernel/trace/ftrace.c:5127:6: note: Assuming 'rec' is non-null
if (!rec)
^~~~
kernel/trace/ftrace.c:5127:2: note: Taking false branch
if (!rec)
^
kernel/trace/ftrace.c:5134:6: note: Assuming the condition is true
if (WARN_ON(rec->flags & FTRACE_FL_DIRECT))
^
include/asm-generic/bug.h:121:23: note: expanded from macro 'WARN_ON'
int __ret_warn_on = !!(condition); \
^~~~~~~~~~~~
kernel/trace/ftrace.c:5134:6: note: Taking false branch
if (WARN_ON(rec->flags & FTRACE_FL_DIRECT))
^
include/asm-generic/bug.h:122:2: note: expanded from macro 'WARN_ON'
if (unlikely(__ret_warn_on)) \
^
kernel/trace/ftrace.c:5134:2: note: Taking false branch
if (WARN_ON(rec->flags & FTRACE_FL_DIRECT))
^
kernel/trace/ftrace.c:5138:6: note: Assuming 'ip' is equal to field 'ip'
if (ip != rec->ip) {
^~~~~~~~~~~~~
kernel/trace/ftrace.c:5138:2: note: Taking false branch
if (ip != rec->ip) {
^
kernel/trace/ftrace.c:5147:6: note: Assuming 'direct' is null
if (!direct) {
^~~~~~~
kernel/trace/ftrace.c:5147:2: note: Taking true branch
if (!direct) {
^
kernel/trace/ftrace.c:5148:12: note: Calling 'ftrace_alloc_direct_func'
direct = ftrace_alloc_direct_func(addr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5084:11: note: Calling 'kmalloc'
direct = kmalloc(sizeof(*direct), GFP_KERNEL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h:579:2: note: Taking false branch
if (__builtin_constant_p(size)) {
^
include/linux/slab.h:596:2: note: Returning pointer, which participates in a condition later
return __kmalloc(size, flags);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5084:11: note: Returning from 'kmalloc'
direct = kmalloc(sizeof(*direct), GFP_KERNEL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5085:6: note: Assuming 'direct' is null, which participates in a condition later
if (!direct)
^~~~~~~
kernel/trace/ftrace.c:5085:2: note: Taking true branch
if (!direct)
^
kernel/trace/ftrace.c:5086:3: note: Returning null pointer, which participates in a condition later
return NULL;
^~~~~~~~~~~
kernel/trace/ftrace.c:5148:12: note: Returning from 'ftrace_alloc_direct_func'
direct = ftrace_alloc_direct_func(addr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/ftrace.c:5149:8: note: 'direct' is null
if (!direct) {
^~~~~~
kernel/trace/ftrace.c:5149:3: note: Taking true branch
if (!direct) {
^
kernel/trace/ftrace.c:5150:4: note: 1st function call argument is an uninitialized value
kfree(entry);
^ ~~~~~
vim +5150 kernel/trace/ftrace.c
8a141dd7f7060d1 Alexei Starovoitov 2021-03-16 5093
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5094) /**
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5095) * register_ftrace_direct - Call a custom trampoline directly
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5096) * @ip: The address of the nop at the beginning of a function
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5097) * @addr: The address of the trampoline to call at @ip
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5098) *
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5099) * This is used to connect a direct call from the nop location (@ip)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5100) * at the start of ftrace traced functions. The location that it calls
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5101) * (@addr) must be able to handle a direct call, and save the parameters
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5102) * of the function being traced, and restore them (or inject new ones
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5103) * if needed), before returning.
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5104) *
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5105) * Returns:
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5106) * 0 on success
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5107) * -EBUSY - Another direct function is already attached (there can be only one)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5108) * -ENODEV - @ip does not point to a ftrace nop location (or not supported)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5109) * -ENOMEM - There was an allocation failure.
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5110) */
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5111) int register_ftrace_direct(unsigned long ip, unsigned long addr)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5112) {
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5113) struct ftrace_direct_func *direct;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5114) struct ftrace_func_entry *entry;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5115) struct ftrace_hash *free_hash = NULL;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5116) struct dyn_ftrace *rec;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5117) int ret = -EBUSY;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5118)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5119) mutex_lock(&direct_mutex);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5120)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5121) /* See if there's a direct function at @ip already */
ff205766dbbee02 Alexei Starovoitov 2019-12-08 5122 if (ftrace_find_rec_direct(ip))
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5123) goto out_unlock;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5124)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5125) ret = -ENODEV;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5126) rec = lookup_rec(ip, ip);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5127) if (!rec)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5128) goto out_unlock;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5129)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5130) /*
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5131) * Check if the rec says it has a direct call but we didn't
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5132) * find one earlier?
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5133) */
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5134) if (WARN_ON(rec->flags & FTRACE_FL_DIRECT))
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5135) goto out_unlock;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5136)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5137) /* Make sure the ip points to the exact record */
406acdd32d3e7d5 Steven Rostedt (VMware 2019-11-15 5138) if (ip != rec->ip) {
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5139) ip = rec->ip;
406acdd32d3e7d5 Steven Rostedt (VMware 2019-11-15 5140) /* Need to check this ip for a direct. */
ff205766dbbee02 Alexei Starovoitov 2019-12-08 5141 if (ftrace_find_rec_direct(ip))
406acdd32d3e7d5 Steven Rostedt (VMware 2019-11-15 5142) goto out_unlock;
406acdd32d3e7d5 Steven Rostedt (VMware 2019-11-15 5143) }
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5144)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5145) ret = -ENOMEM;
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5146) direct = ftrace_find_direct_func(addr);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5147) if (!direct) {
8a141dd7f7060d1 Alexei Starovoitov 2021-03-16 5148 direct = ftrace_alloc_direct_func(addr);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5149) if (!direct) {
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 @5150) kfree(entry);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5151) goto out_unlock;
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5152) }
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5153) }
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5154)
b45bdf4de5473d5 Jiri Olsa 2021-05-18 5155 entry = ftrace_add_rec_direct(ip, addr, &free_hash);
b45bdf4de5473d5 Jiri Olsa 2021-05-18 5156 if (!entry)
b45bdf4de5473d5 Jiri Olsa 2021-05-18 5157 goto out_unlock;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5158)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5159) ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5160) if (ret)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5161) remove_hash_entry(direct_functions, entry);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5162)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5163) if (!ret && !(direct_ops.flags & FTRACE_OPS_FL_ENABLED)) {
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5164) ret = register_ftrace_function(&direct_ops);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5165) if (ret)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5166) ftrace_set_filter_ip(&direct_ops, ip, 1, 0);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5167) }
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5168)
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5169) if (ret) {
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5170) kfree(entry);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5171) if (!direct->count) {
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5172) list_del_rcu(&direct->next);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5173) synchronize_rcu_tasks();
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5174) kfree(direct);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5175) if (free_hash)
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5176) free_ftrace_hash(free_hash);
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5177) free_hash = NULL;
a3ad1a7e3968900 Steven Rostedt (VMware 2019-11-08 5178) ftrace_direct_func_count--;
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5179) }
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5180) } else {
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5181) direct->count++;
013bf0da0474816 Steven Rostedt (VMware 2019-11-08 5182) }
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5183) out_unlock:
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5184) mutex_unlock(&direct_mutex);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5185)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5186) if (free_hash) {
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5187) synchronize_rcu_tasks();
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5188) free_ftrace_hash(free_hash);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5189) }
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5190)
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5191) return ret;
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5192) }
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5193) EXPORT_SYMBOL_GPL(register_ftrace_direct);
763e34e74bb7d5c Steven Rostedt (VMware 2019-11-08 5194)
:::::: The code at line 5150 was first introduced by commit
:::::: 013bf0da0474816f57739daa006c8564ad7396a3 ftrace: Add ftrace_find_direct_func()
:::::: TO: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
:::::: CC: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxxAttachment:
.config.gz
Description: application/gzip
_______________________________________________
kbuild mailing list -- kbuild@xxxxxxxxxxxx
To unsubscribe send an email to kbuild-leave@xxxxxxxxxxxx