All of lore.kernel.org
 help / color / mirror / Atom feed
* kernel/bpf/stackmap.c:697:6: warning: Variable 'err' is reassigned a value before the old one has been used.
@ 2020-09-23 12:53 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2020-09-23 12:53 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 5569 bytes --]

CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Song Liu <songliubraving@fb.com>
CC: Alexei Starovoitov <ast@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   805c6d3c19210c90c109107d189744e960eae025
commit: 7b04d6d60fcfb5b2200ffebb9cfb90927bdfeec7 bpf: Separate bpf_get_[stack|stackid] for perf events BPF
date:   8 weeks ago
:::::: branch date: 15 hours ago
:::::: commit date: 8 weeks ago
compiler: s390-linux-gcc (GCC) 9.3.0

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


cppcheck warnings: (new ones prefixed by >>)

>> kernel/bpf/stackmap.c:697:6: warning: Variable 'err' is reassigned a value before the old one has been used. [redundantAssignment]
    err = -EFAULT;
        ^
   kernel/bpf/stackmap.c:684:0: note: Variable 'err' is reassigned a value before the old one has been used.
    int err = -EINVAL;
   ^
   kernel/bpf/stackmap.c:697:6: note: Variable 'err' is reassigned a value before the old one has been used.
    err = -EFAULT;
        ^
   kernel/bpf/stackmap.c:708:7: warning: Variable 'err' is reassigned a value before the old one has been used. [redundantAssignment]
     err = __bpf_get_stack(ctx->regs, NULL, trace, buf,
         ^
   kernel/bpf/stackmap.c:697:6: note: Variable 'err' is reassigned a value before the old one has been used.
    err = -EFAULT;
        ^
   kernel/bpf/stackmap.c:708:7: note: Variable 'err' is reassigned a value before the old one has been used.
     err = __bpf_get_stack(ctx->regs, NULL, trace, buf,
         ^

# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7b04d6d60fcfb5b2200ffebb9cfb90927bdfeec7
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 7b04d6d60fcfb5b2200ffebb9cfb90927bdfeec7
vim +/err +697 kernel/bpf/stackmap.c

fa28dcb82a38f8e Song Liu 2020-06-29  677  
7b04d6d60fcfb5b Song Liu 2020-07-23  678  BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
7b04d6d60fcfb5b Song Liu 2020-07-23  679  	   void *, buf, u32, size, u64, flags)
7b04d6d60fcfb5b Song Liu 2020-07-23  680  {
7b04d6d60fcfb5b Song Liu 2020-07-23  681  	struct perf_event *event = ctx->event;
7b04d6d60fcfb5b Song Liu 2020-07-23  682  	struct perf_callchain_entry *trace;
7b04d6d60fcfb5b Song Liu 2020-07-23  683  	bool kernel, user;
7b04d6d60fcfb5b Song Liu 2020-07-23  684  	int err = -EINVAL;
7b04d6d60fcfb5b Song Liu 2020-07-23  685  	__u64 nr_kernel;
7b04d6d60fcfb5b Song Liu 2020-07-23  686  
7b04d6d60fcfb5b Song Liu 2020-07-23  687  	if (!(event->attr.sample_type & __PERF_SAMPLE_CALLCHAIN_EARLY))
7b04d6d60fcfb5b Song Liu 2020-07-23  688  		return __bpf_get_stack(ctx->regs, NULL, NULL, buf, size, flags);
7b04d6d60fcfb5b Song Liu 2020-07-23  689  
7b04d6d60fcfb5b Song Liu 2020-07-23  690  	if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
7b04d6d60fcfb5b Song Liu 2020-07-23  691  			       BPF_F_USER_BUILD_ID)))
7b04d6d60fcfb5b Song Liu 2020-07-23  692  		goto clear;
7b04d6d60fcfb5b Song Liu 2020-07-23  693  
7b04d6d60fcfb5b Song Liu 2020-07-23  694  	user = flags & BPF_F_USER_STACK;
7b04d6d60fcfb5b Song Liu 2020-07-23  695  	kernel = !user;
7b04d6d60fcfb5b Song Liu 2020-07-23  696  
7b04d6d60fcfb5b Song Liu 2020-07-23 @697  	err = -EFAULT;
7b04d6d60fcfb5b Song Liu 2020-07-23  698  	trace = ctx->data->callchain;
7b04d6d60fcfb5b Song Liu 2020-07-23  699  	if (unlikely(!trace))
7b04d6d60fcfb5b Song Liu 2020-07-23  700  		goto clear;
7b04d6d60fcfb5b Song Liu 2020-07-23  701  
7b04d6d60fcfb5b Song Liu 2020-07-23  702  	nr_kernel = count_kernel_ip(trace);
7b04d6d60fcfb5b Song Liu 2020-07-23  703  
7b04d6d60fcfb5b Song Liu 2020-07-23  704  	if (kernel) {
7b04d6d60fcfb5b Song Liu 2020-07-23  705  		__u64 nr = trace->nr;
7b04d6d60fcfb5b Song Liu 2020-07-23  706  
7b04d6d60fcfb5b Song Liu 2020-07-23  707  		trace->nr = nr_kernel;
7b04d6d60fcfb5b Song Liu 2020-07-23  708  		err = __bpf_get_stack(ctx->regs, NULL, trace, buf,
7b04d6d60fcfb5b Song Liu 2020-07-23  709  				      size, flags);
7b04d6d60fcfb5b Song Liu 2020-07-23  710  
7b04d6d60fcfb5b Song Liu 2020-07-23  711  		/* restore nr */
7b04d6d60fcfb5b Song Liu 2020-07-23  712  		trace->nr = nr;
7b04d6d60fcfb5b Song Liu 2020-07-23  713  	} else { /* user */
7b04d6d60fcfb5b Song Liu 2020-07-23  714  		u64 skip = flags & BPF_F_SKIP_FIELD_MASK;
7b04d6d60fcfb5b Song Liu 2020-07-23  715  
7b04d6d60fcfb5b Song Liu 2020-07-23  716  		skip += nr_kernel;
7b04d6d60fcfb5b Song Liu 2020-07-23  717  		if (skip > BPF_F_SKIP_FIELD_MASK)
7b04d6d60fcfb5b Song Liu 2020-07-23  718  			goto clear;
7b04d6d60fcfb5b Song Liu 2020-07-23  719  
7b04d6d60fcfb5b Song Liu 2020-07-23  720  		flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
7b04d6d60fcfb5b Song Liu 2020-07-23  721  		err = __bpf_get_stack(ctx->regs, NULL, trace, buf,
7b04d6d60fcfb5b Song Liu 2020-07-23  722  				      size, flags);
7b04d6d60fcfb5b Song Liu 2020-07-23  723  	}
7b04d6d60fcfb5b Song Liu 2020-07-23  724  	return err;
7b04d6d60fcfb5b Song Liu 2020-07-23  725  
7b04d6d60fcfb5b Song Liu 2020-07-23  726  clear:
7b04d6d60fcfb5b Song Liu 2020-07-23  727  	memset(buf, 0, size);
7b04d6d60fcfb5b Song Liu 2020-07-23  728  	return err;
7b04d6d60fcfb5b Song Liu 2020-07-23  729  

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-23 12:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-23 12:53 kernel/bpf/stackmap.c:697:6: warning: Variable 'err' is reassigned a value before the old one has been used kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.