kernel/bpf/verifier.c:794:5-12: Unneeded variable: "ref_cnt". Return "0" on line 805

From: kernel test robot

Date: Mon Sep 14 2026 - 05:14:49 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 704340f1cd0dcef829eb62f5b48ae95a2ce17bdf
commit: 2eee6fe8ac2cd21e931c009d475e5a8407d42d76 bpf: Fix dynptr ref counting to scan all call frames
date: 3 months ago
config: hexagon-randconfig-r054-20260914 (https://download.01.org/0day-ci/archive/20260914/202609141124.zR9pQCyK-lkp@xxxxxxxxx/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 707c032dae3bee24eae29c6f4c459a6d6dc6556d)

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
| Fixes: 2eee6fe8ac2c ("bpf: Fix dynptr ref counting to scan all call frames")
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202609141124.zR9pQCyK-lkp@xxxxxxxxx/

cocci warnings: (new ones prefixed by >>)
>> kernel/bpf/verifier.c:794:5-12: Unneeded variable: "ref_cnt". Return "0" on line 805

vim +794 kernel/bpf/verifier.c

788
789 static int dynptr_ref_cnt(struct bpf_verifier_env *env, int v_parent_id)
790 {
791 struct bpf_stack_state *stack;
792 struct bpf_func_state *state;
793 struct bpf_reg_state *reg;
> 794 int ref_cnt = 0;
795
796 bpf_for_each_reg_in_vstate_mask(env->cur_state, state, reg, stack, 1 << STACK_DYNPTR, ({
797 if (!stack || stack->slot_type[0] != STACK_DYNPTR)
798 continue;
799 if (!stack->spilled_ptr.dynptr.first_slot)
800 continue;
801 if (stack->spilled_ptr.parent_id == v_parent_id)
802 ref_cnt++;
803 }));
804
> 805 return ref_cnt;
806 }
807

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