mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Atish Patra <atish.patra@wdc.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	linux-kernel@vger.kernel.org,
	Palmer Dabbelt <palmer@rivosinc.com>
Subject: drivers/perf/riscv_pmu_sbi.c:464 pmu_sbi_get_ctrinfo() warn: potentially one past the end of array 'pmu_ctr_list[i]'
Date: Wed, 20 Apr 2022 12:31:33 +0300	[thread overview]
Message-ID: <202204161940.BrRZvzdD-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   59250f8a7f3a60a2661b84cbafc1e0eb5d05ec9b
commit: e9991434596f5373dfd75857b445eb92a9253c56 RISC-V: Add perf platform driver based on SBI PMU extension
config: riscv-randconfig-m031-20220416 (https://download.01.org/0day-ci/archive/20220416/202204161940.BrRZvzdD-lkp@intel.com/config)
compiler: riscv32-linux-gcc (GCC) 11.2.0

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

smatch warnings:
drivers/perf/riscv_pmu_sbi.c:464 pmu_sbi_get_ctrinfo() warn: potentially one past the end of array 'pmu_ctr_list[i]'
drivers/perf/riscv_pmu_sbi.c:464 pmu_sbi_get_ctrinfo() warn: potentially one past the end of array 'pmu_ctr_list[i]'

vim +464 drivers/perf/riscv_pmu_sbi.c

e9991434596f53 Atish Patra 2022-02-18  444  static int pmu_sbi_get_ctrinfo(int nctr)
e9991434596f53 Atish Patra 2022-02-18  445  {
e9991434596f53 Atish Patra 2022-02-18  446  	struct sbiret ret;
e9991434596f53 Atish Patra 2022-02-18  447  	int i, num_hw_ctr = 0, num_fw_ctr = 0;
e9991434596f53 Atish Patra 2022-02-18  448  	union sbi_pmu_ctr_info cinfo;
e9991434596f53 Atish Patra 2022-02-18  449  
e9991434596f53 Atish Patra 2022-02-18  450  	pmu_ctr_list = kcalloc(nctr, sizeof(*pmu_ctr_list), GFP_KERNEL);
                                                                       ^^^^

e9991434596f53 Atish Patra 2022-02-18  451  	if (!pmu_ctr_list)
e9991434596f53 Atish Patra 2022-02-18  452  		return -ENOMEM;
e9991434596f53 Atish Patra 2022-02-18  453  
e9991434596f53 Atish Patra 2022-02-18  454  	for (i = 0; i <= nctr; i++) {
                                                            ^^^^^^^^^
The <= should be <

e9991434596f53 Atish Patra 2022-02-18  455  		ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, i, 0, 0, 0, 0, 0);
e9991434596f53 Atish Patra 2022-02-18  456  		if (ret.error)
e9991434596f53 Atish Patra 2022-02-18  457  			/* The logical counter ids are not expected to be contiguous */
e9991434596f53 Atish Patra 2022-02-18  458  			continue;
e9991434596f53 Atish Patra 2022-02-18  459  		cinfo.value = ret.value;
e9991434596f53 Atish Patra 2022-02-18  460  		if (cinfo.type == SBI_PMU_CTR_TYPE_FW)
e9991434596f53 Atish Patra 2022-02-18  461  			num_fw_ctr++;
e9991434596f53 Atish Patra 2022-02-18  462  		else
e9991434596f53 Atish Patra 2022-02-18  463  			num_hw_ctr++;
e9991434596f53 Atish Patra 2022-02-18 @464  		pmu_ctr_list[i].value = cinfo.value;
                                                        ^^^^^^^^^^^^^^^
Off by one

e9991434596f53 Atish Patra 2022-02-18  465  	}
e9991434596f53 Atish Patra 2022-02-18  466  
e9991434596f53 Atish Patra 2022-02-18  467  	pr_info("%d firmware and %d hardware counters\n", num_fw_ctr, num_hw_ctr);
e9991434596f53 Atish Patra 2022-02-18  468  
e9991434596f53 Atish Patra 2022-02-18  469  	return 0;
e9991434596f53 Atish Patra 2022-02-18  470  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


             reply	other threads:[~2022-04-20  9:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20  9:31 Dan Carpenter [this message]
2022-04-20 22:38 ` Palmer Dabbelt
2022-04-20 22:48   ` Atish Kumar Patra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202204161940.BrRZvzdD-lkp@intel.com \
    --to=dan.carpenter@oracle.com \
    --cc=atish.patra@wdc.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=palmer@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®