drivers/remoteproc/remoteproc_core.c:696:10-20: ERROR: invalid reference to the index variable of the iterator on line 690 (fwd)
PATCH 4105/8734 drivers/remoteproc/remoteproc_core.c:696:10-20: ERROR: invalid reference to the index variable of the iterator on line 690 (fwd)
Hello,
Are you certain that the loop starting on line 690 will always be exited with the break? If the loop exists because it runs out of elements, the uses of tmem may be invalid.
Also, list_for_each_entry_safe is not needed. List_for_each_entry would be sufficient. The loop does not destroy the list elements.
julia
---------- Forwarded message ----------
Date: Thu, 6 Aug 2020 15:22:59 +0800
From: kernel test robot <[email protected]>
To: kbuild(a)lists.01.org
Cc: lkp(a)intel.com, Julia Lawall <[email protected]>
Subject: [ti:ti-linux-5.4.y 4105/8734]
drivers/remoteproc/remoteproc_core.c:696:10-20: ERROR: invalid reference to the index variable of the iterator on line 690
CC: kbuild-all(a)lists.01.org
TO: Suman Anna <[email protected]>
CC: Subramaniam Chanderashekarapuram <[email protected]>
tree: git://git.ti.com/ti-linux-kernel/ti-linux-kernel.git ti-linux-5.4.y head: e5a461dfc65bd00558e0b40e97f678cc7fa480bd commit: 8604575b3314bdd96349eeb3bb453ff30d1788c0 [4105/8734] remoteproc: implement last trace for remoteproc
:::::: branch date: 9 hours ago
:::::: commit date: 6 months ago
config: nios2-randconfig-c003-20200805 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
coccinelle warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
drivers/remoteproc/remoteproc_core.c:696:10-20: ERROR: invalid reference to the index variable of the iterator on line 690
git remote add ti git://git.ti.com/ti-linux-kernel/ti-linux-kernel.git
git remote update ti
git checkout 8604575b3314bdd96349eeb3bb453ff30d1788c0
vim +696 drivers/remoteproc/remoteproc_core.c
aab8d8022304b64 Bjorn Andersson 2016-10-19 644
8604575b3314bdd Suman Anna 2020-02-19 645 /**
8604575b3314bdd Suman Anna 2020-02-19 646 * rproc_process_last_trace() - setup a buffer to capture the trace snapshot
8604575b3314bdd Suman Anna 2020-02-19 647 * before recovery
8604575b3314bdd Suman Anna 2020-02-19 648 * @rproc: the remote processor
8604575b3314bdd Suman Anna 2020-02-19 649 * @trace: the trace resource descriptor
8604575b3314bdd Suman Anna 2020-02-19 650 * @count: the index of the trace under process
8604575b3314bdd Suman Anna 2020-02-19 651 *
8604575b3314bdd Suman Anna 2020-02-19 652 * The last trace is allocated if a previous last trace entry does not exist,
8604575b3314bdd Suman Anna 2020-02-19 653 * and the contents of the trace buffer are copied during a recovery cleanup.
8604575b3314bdd Suman Anna 2020-02-19 654 *
8604575b3314bdd Suman Anna 2020-02-19 655 * NOTE: The memory in the original trace buffer is currently not zeroed out,
8604575b3314bdd Suman Anna 2020-02-19 656 * but can be done if the remote processor is not zero initializing the trace
8604575b3314bdd Suman Anna 2020-02-19 657 * memory region.
8604575b3314bdd Suman Anna 2020-02-19 658 *
8604575b3314bdd Suman Anna 2020-02-19 659 * Returns 0 on success, or an appropriate error code otherwise
8604575b3314bdd Suman Anna 2020-02-19 660 */
8604575b3314bdd Suman Anna 2020-02-19 661 static int rproc_process_last_trace(struct rproc *rproc,
8604575b3314bdd Suman Anna 2020-02-19 662 struct rproc_debug_trace *trace, int count)
8604575b3314bdd Suman Anna 2020-02-19 663 {
8604575b3314bdd Suman Anna 2020-02-19 664 struct rproc_debug_trace *trace_last, *tmp_trace;
8604575b3314bdd Suman Anna 2020-02-19 665 struct rproc_mem_entry *tmem;
8604575b3314bdd Suman Anna 2020-02-19 666 struct device *dev = &rproc->dev;
8604575b3314bdd Suman Anna 2020-02-19 667 char name[16];
8604575b3314bdd Suman Anna 2020-02-19 668 int i = 0;
8604575b3314bdd Suman Anna 2020-02-19 669
8604575b3314bdd Suman Anna 2020-02-19 670 if (!rproc || !trace)
8604575b3314bdd Suman Anna 2020-02-19 671 return -EINVAL;
8604575b3314bdd Suman Anna 2020-02-19 672
8604575b3314bdd Suman Anna 2020-02-19 673 /* lookup trace va if not stored already */
8604575b3314bdd Suman Anna 2020-02-19 674 tmem = &trace->trace_mem;
8604575b3314bdd Suman Anna 2020-02-19 675 if (!tmem->va) {
8604575b3314bdd Suman Anna 2020-02-19 676 tmem->va = rproc_da_to_va(rproc, tmem->da, tmem->len);
8604575b3314bdd Suman Anna 2020-02-19 677 if (!tmem->va)
8604575b3314bdd Suman Anna 2020-02-19 678 return -EINVAL;
8604575b3314bdd Suman Anna 2020-02-19 679 }
8604575b3314bdd Suman Anna 2020-02-19 680
8604575b3314bdd Suman Anna 2020-02-19 681 if (count > rproc->num_last_traces) {
8604575b3314bdd Suman Anna 2020-02-19 682 /* create a new trace_last entry */
8604575b3314bdd Suman Anna 2020-02-19 683 snprintf(name, sizeof(name), "trace%d_last", count - 1);
8604575b3314bdd Suman Anna 2020-02-19 684 trace_last = kzalloc(sizeof(*trace_last), GFP_KERNEL);
8604575b3314bdd Suman Anna 2020-02-19 685 if (!trace_last)
8604575b3314bdd Suman Anna 2020-02-19 686 return -ENOMEM;
8604575b3314bdd Suman Anna 2020-02-19 687 tmem = &trace_last->trace_mem;
8604575b3314bdd Suman Anna 2020-02-19 688 } else {
8604575b3314bdd Suman Anna 2020-02-19 689 /* reuse the already existing trace_last entry */
8604575b3314bdd Suman Anna 2020-02-19 @690 list_for_each_entry_safe(trace_last, tmp_trace,
8604575b3314bdd Suman Anna 2020-02-19 691 &rproc->last_traces, node) {
8604575b3314bdd Suman Anna 2020-02-19 692 if (++i == count)
8604575b3314bdd Suman Anna 2020-02-19 693 break;
8604575b3314bdd Suman Anna 2020-02-19 694 }
8604575b3314bdd Suman Anna 2020-02-19 695
8604575b3314bdd Suman Anna 2020-02-19 @696 tmem = &trace_last->trace_mem;
8604575b3314bdd Suman Anna 2020-02-19 697 if (tmem->len != trace->trace_mem.len) {
8604575b3314bdd Suman Anna 2020-02-19 698 dev_warn(dev, "len does not match between trace and trace_last\n");
8604575b3314bdd Suman Anna 2020-02-19 699 return -EINVAL;
8604575b3314bdd Suman Anna 2020-02-19 700 }
8604575b3314bdd Suman Anna 2020-02-19 701
8604575b3314bdd Suman Anna 2020-02-19 702 goto copy_and_exit;
8604575b3314bdd Suman Anna 2020-02-19 703 }
8604575b3314bdd Suman Anna 2020-02-19 704
8604575b3314bdd Suman Anna 2020-02-19 705 /* allocate memory and create debugfs file for the new last_trace */
8604575b3314bdd Suman Anna 2020-02-19 706 tmem->len = trace->trace_mem.len;
8604575b3314bdd Suman Anna 2020-02-19 707 tmem->va = vmalloc(sizeof(u32) * tmem->len);
8604575b3314bdd Suman Anna 2020-02-19 708 if (!tmem->va) {
8604575b3314bdd Suman Anna 2020-02-19 709 kfree(trace_last);
8604575b3314bdd Suman Anna 2020-02-19 710 return -ENOMEM;
8604575b3314bdd Suman Anna 2020-02-19 711 }
8604575b3314bdd Suman Anna 2020-02-19 712
8604575b3314bdd Suman Anna 2020-02-19 713 trace_last->tfile = rproc_create_trace_file(name, rproc, trace_last);
8604575b3314bdd Suman Anna 2020-02-19 714 if (!trace_last->tfile) {
8604575b3314bdd Suman Anna 2020-02-19 715 dev_err(dev, "trace%d_last create debugfs failed\n", count - 1);
8604575b3314bdd Suman Anna 2020-02-19 716 vfree(tmem->va);
8604575b3314bdd Suman Anna 2020-02-19 717 kfree(trace_last);
8604575b3314bdd Suman Anna 2020-02-19 718 return -EINVAL;
8604575b3314bdd Suman Anna 2020-02-19 719 }
8604575b3314bdd Suman Anna 2020-02-19 720
8604575b3314bdd Suman Anna 2020-02-19 721 list_add_tail(&trace_last->node, &rproc->last_traces);
8604575b3314bdd Suman Anna 2020-02-19 722 rproc->num_last_traces++;
8604575b3314bdd Suman Anna 2020-02-19 723
8604575b3314bdd Suman Anna 2020-02-19 724 copy_and_exit:
8604575b3314bdd Suman Anna 2020-02-19 725 /* copy the trace contents to last trace */
8604575b3314bdd Suman Anna 2020-02-19 726 memcpy(tmem->va, trace->trace_mem.va, trace->trace_mem.len);
8604575b3314bdd Suman Anna 2020-02-19 727
8604575b3314bdd Suman Anna 2020-02-19 728 return 0;
8604575b3314bdd Suman Anna 2020-02-19 729 }
8604575b3314bdd Suman Anna 2020-02-19 730---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org