Hi Pingfan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bpf-next/net]
[also build test WARNING on bpf-next/master bpf/master arm64/for-next/core 
linus/master v6.15 next-20250529]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    
https://github.com/intel-lab-lkp/linux/commits/Pingfan-Liu/kexec_file-Make-kexec_image_load_default-global-visible/20250529-122124
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git net
patch link:    
https://lore.kernel.org/r/20250529041744.16458-4-piliu%40redhat.com
patch subject: [PATCHv3 3/9] bpf: Introduce bpf_copy_to_kernel() to buffer the 
content from bpf-prog
config: riscv-randconfig-001-20250529 
(https://download.01.org/0day-ci/archive/20250529/202505291926.ipusqcej-...@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 
f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20250529/202505291926.ipusqcej-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <l...@intel.com>
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202505291926.ipusqcej-...@intel.com/

All warnings (new ones prefixed by >>):

>> kernel/bpf/helpers_carrier.c:74:17: warning: no previous prototype for 
>> function 'bpf_mem_range_result_put' [-Wmissing-prototypes]
      74 | __bpf_kfunc int bpf_mem_range_result_put(struct mem_range_result 
*result)
         |                 ^
   kernel/bpf/helpers_carrier.c:74:13: note: declare 'static' if the function 
is not intended to be used outside of this translation unit
      74 | __bpf_kfunc int bpf_mem_range_result_put(struct mem_range_result 
*result)
         |             ^
         |             static 
   kernel/bpf/helpers_carrier.c:88:7: warning: variable 'kmalloc' set but not 
used [-Wunused-but-set-variable]
      88 |         bool kmalloc;
         |              ^
>> kernel/bpf/helpers_carrier.c:82:17: warning: no previous prototype for 
>> function 'bpf_copy_to_kernel' [-Wmissing-prototypes]
      82 | __bpf_kfunc int bpf_copy_to_kernel(const char *name, char *buf, int 
size)
         |                 ^
   kernel/bpf/helpers_carrier.c:82:13: note: declare 'static' if the function 
is not intended to be used outside of this translation unit
      82 | __bpf_kfunc int bpf_copy_to_kernel(const char *name, char *buf, int 
size)
         |             ^
         |             static 
>> kernel/bpf/helpers_carrier.c:165:6: warning: variable 'ret' is used 
>> uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     165 |         if (!find_listener(item->str)) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/helpers_carrier.c:174:9: note: uninitialized use occurs here
     174 |         return ret;
         |                ^~~
   kernel/bpf/helpers_carrier.c:165:2: note: remove the 'if' if its condition 
is always false
     165 |         if (!find_listener(item->str)) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     166 |                 hash_add(str_listeners, &item->node, hash);
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     167 |         } else {
         |         ~~~~~~
   kernel/bpf/helpers_carrier.c:149:9: note: initialize the variable 'ret' to 
silence this warning
     149 |         int ret;
         |                ^
         |                 = 0
   4 warnings generated.


vim +/bpf_mem_range_result_put +74 kernel/bpf/helpers_carrier.c

    73  
  > 74  __bpf_kfunc int bpf_mem_range_result_put(struct mem_range_result 
*result)
    75  {
    76          return mem_range_result_put(result);
    77  }
    78  
    79  /*
    80   * Cache the content in @buf into kernel
    81   */
  > 82  __bpf_kfunc int bpf_copy_to_kernel(const char *name, char *buf, int 
size)
    83  {
    84          struct mem_range_result *range;
    85          struct mem_cgroup *memcg, *old_memcg;
    86          struct str_listener *item;
    87          resource_handler handler;
    88          bool kmalloc;
    89          char *kbuf;
    90          int id, ret = 0;
    91  
    92          id = srcu_read_lock(&srcu);
    93          item = find_listener(name);
    94          if (!item) {
    95                  srcu_read_unlock(&srcu, id);
    96                  return -EINVAL;
    97          }
    98          kmalloc = item->kmalloc;
    99          handler = item->handler;
   100          srcu_read_unlock(&srcu, id);
   101          memcg = get_mem_cgroup_from_current();
   102          old_memcg = set_active_memcg(memcg);
   103          range = kmalloc(sizeof(struct mem_range_result), GFP_KERNEL);
   104          if (!range) {
   105                  pr_err("fail to allocate mem_range_result\n");
   106                  ret = -ENOMEM;
   107                  goto err;
   108          }
   109  
   110          kref_init(&range->ref);
   111          if (item->kmalloc)
   112                  kbuf = kmalloc(size, GFP_KERNEL | __GFP_ACCOUNT);
   113          else
   114                  kbuf = __vmalloc(size, GFP_KERNEL | __GFP_ACCOUNT);
   115          if (!kbuf) {
   116                  kfree(range);
   117                  ret = -ENOMEM;
   118                  goto err;
   119          }
   120          ret = copy_from_kernel_nofault(kbuf, buf, size);
   121          if (unlikely(ret < 0)) {
   122                  kfree(range);
   123                  if (item->kmalloc)
   124                          kfree(kbuf);
   125                  else
   126                          vfree(kbuf);
   127                  ret = -EINVAL;
   128                  goto err;
   129          }
   130          range->kmalloc = item->kmalloc;
   131          range->buf = kbuf;
   132          range->buf_sz = size;
   133          range->data_sz = size;
   134          range->memcg = memcg;
   135          mem_cgroup_tryget(memcg);
   136          range->status = 0;
   137          ret = handler(name, range);
   138          mem_range_result_put(range);
   139  err:
   140          set_active_memcg(old_memcg);
   141          mem_cgroup_put(memcg);
   142          return ret;
   143  }
   144  
   145  int register_carrier_listener(struct carrier_listener *listener)
   146  {
   147          struct str_listener *item;
   148          unsigned int hash;
   149          int ret;
   150  
   151          if (!listener->name)
   152                  return -EINVAL;
   153          item = kmalloc(sizeof(*item), GFP_KERNEL);
   154          if (!item)
   155                  return -ENOMEM;
   156          item->str = kstrdup(listener->name, GFP_KERNEL);
   157          if (!item->str) {
   158                  kfree(item);
   159                  return -ENOMEM;
   160          }
   161          item->handler = listener->handler;
   162          item->kmalloc = listener->kmalloc;
   163          hash = jhash(item->str, strlen(item->str), 0);
   164          mutex_lock(&str_listeners_mutex);
 > 165          if (!find_listener(item->str)) {
   166                  hash_add(str_listeners, &item->node, hash);
   167          } else {
   168                  kfree(item->str);
   169                  kfree(item);
   170                  ret = -EBUSY;
   171          }
   172          mutex_unlock(&str_listeners_mutex);
   173  
   174          return ret;
   175  }
   176  EXPORT_SYMBOL(register_carrier_listener);
   177  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

Reply via email to