All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: drivers/s390/cio/vfio_ccw_cp.c:69 page_array_alloc() warn: double check that we're allocating correct size: 8 vs 16
Date: Sun, 07 Aug 2022 12:41:02 +0800	[thread overview]
Message-ID: <202208071226.m6YIXeZR-lkp@intel.com> (raw)

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

BCC: lkp(a)intel.com
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Nicolin Chen <nicolinc@nvidia.com>
CC: Alex Williamson <alex.williamson@redhat.com>
CC: Jason Gunthorpe <jgg@nvidia.com>
CC: Eric Farman <farman@linux.ibm.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   1612c382ffbdf1f673caec76502b1c00e6d35363
commit: 1331460514ff7d378373223109eefae4cd55ec77 vfio/ccw: Change pa_pfn list to pa_iova list
date:   12 days ago
:::::: branch date: 4 hours ago
:::::: commit date: 12 days ago
config: s390-randconfig-m041-20220807 (https://download.01.org/0day-ci/archive/20220807/202208071226.m6YIXeZR-lkp(a)intel.com/config)
compiler: s390-linux-gcc (GCC) 12.1.0

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

smatch warnings:
drivers/s390/cio/vfio_ccw_cp.c:69 page_array_alloc() warn: double check that we're allocating correct size: 8 vs 16
drivers/s390/cio/vfio_ccw_cp.c:76 page_array_alloc() warn: potentially one past the end of array 'pa->pa_iova[pa->pa_nr]'

vim +69 drivers/s390/cio/vfio_ccw_cp.c

0a19e61e6d4c61 Dong Jia Shi 2017-03-17  40  
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  41  /*
1331460514ff7d Nicolin Chen 2022-07-22  42   * page_array_alloc() - alloc memory for page array
1331460514ff7d Nicolin Chen 2022-07-22  43   * @pa: page_array on which to perform the operation
5c1cfb1c3948fe Dong Jia Shi 2018-05-23  44   * @iova: target guest physical address
5c1cfb1c3948fe Dong Jia Shi 2018-05-23  45   * @len: number of bytes that should be pinned from @iova
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  46   *
1331460514ff7d Nicolin Chen 2022-07-22  47   * Attempt to allocate memory for page array.
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  48   *
1331460514ff7d Nicolin Chen 2022-07-22  49   * Usage of page_array:
1331460514ff7d Nicolin Chen 2022-07-22  50   * We expect (pa_nr == 0) and (pa_iova == NULL), any field in
5c1cfb1c3948fe Dong Jia Shi 2018-05-23  51   * this structure will be filled in by this function.
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  52   *
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  53   * Returns:
1331460514ff7d Nicolin Chen 2022-07-22  54   *         0 if page array is allocated
1331460514ff7d Nicolin Chen 2022-07-22  55   *   -EINVAL if pa->pa_nr is not initially zero, or pa->pa_iova is not NULL
e4f3f18b12324e Eric Farman  2019-05-15  56   *   -ENOMEM if alloc failed
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  57   */
1331460514ff7d Nicolin Chen 2022-07-22  58  static int page_array_alloc(struct page_array *pa, u64 iova, unsigned int len)
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  59  {
e4f3f18b12324e Eric Farman  2019-05-15  60  	int i;
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  61  
1331460514ff7d Nicolin Chen 2022-07-22  62  	if (pa->pa_nr || pa->pa_iova)
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  63  		return -EINVAL;
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  64  
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  65  	pa->pa_nr = ((iova & ~PAGE_MASK) + len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  66  	if (!pa->pa_nr)
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  67  		return -EINVAL;
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  68  
1331460514ff7d Nicolin Chen 2022-07-22 @69  	pa->pa_iova = kcalloc(pa->pa_nr,
1331460514ff7d Nicolin Chen 2022-07-22  70  			      sizeof(*pa->pa_iova) + sizeof(*pa->pa_pfn),
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  71  			      GFP_KERNEL);
1331460514ff7d Nicolin Chen 2022-07-22  72  	if (unlikely(!pa->pa_iova)) {
c1ab69268d124e Farhan Ali   2019-07-11  73  		pa->pa_nr = 0;
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  74  		return -ENOMEM;
c1ab69268d124e Farhan Ali   2019-07-11  75  	}
1331460514ff7d Nicolin Chen 2022-07-22 @76  	pa->pa_pfn = (unsigned long *)&pa->pa_iova[pa->pa_nr];
0a19e61e6d4c61 Dong Jia Shi 2017-03-17  77  
1331460514ff7d Nicolin Chen 2022-07-22  78  	pa->pa_iova[0] = iova;
c34a12e6a3df3a Eric Farman  2019-05-15  79  	pa->pa_pfn[0] = -1ULL;
c34a12e6a3df3a Eric Farman  2019-05-15  80  	for (i = 1; i < pa->pa_nr; i++) {
1331460514ff7d Nicolin Chen 2022-07-22  81  		pa->pa_iova[i] = pa->pa_iova[i - 1] + PAGE_SIZE;
c34a12e6a3df3a Eric Farman  2019-05-15  82  		pa->pa_pfn[i] = -1ULL;
c34a12e6a3df3a Eric Farman  2019-05-15  83  	}
5c1cfb1c3948fe Dong Jia Shi 2018-05-23  84  
e4f3f18b12324e Eric Farman  2019-05-15  85  	return 0;
e4f3f18b12324e Eric Farman  2019-05-15  86  }
e4f3f18b12324e Eric Farman  2019-05-15  87  

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

             reply	other threads:[~2022-08-07  4:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-07  4:41 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-12-24 11:33 drivers/s390/cio/vfio_ccw_cp.c:69 page_array_alloc() warn: double check that we're allocating correct size: 8 vs 16 kernel test robot
2023-01-07 16:49 kernel test robot

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=202208071226.m6YIXeZR-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild@lists.01.org \
    /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 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.