Subject: [bug report] powerpc/iommu: Implement IOMMU pools to improve multiqueue adapter performance

From: Dan Carpenter <[email-masked]>
Date: Wed, 14 Aug 2019 17:19:38 +0300

[ Ancient code.  The warning is correct but the bug seems harmless.
  -- dan ]

Hello Anton Blanchard,

The patch b4c3a8729ae5: "powerpc/iommu: Implement IOMMU pools to
improve multiqueue adapter performance" from Jun 7, 2012, leads to
the following static checker warning:

	arch/powerpc/kernel/iommu.c:377 get_pool()
	warn: array off by one? '*tbl->pools + pool_nr'

arch/powerpc/kernel/iommu.c
   364  static struct iommu_pool *get_pool(struct iommu_table *tbl,
   365                                     unsigned long entry)
   366  {
   367          struct iommu_pool *p;
   368          unsigned long largepool_start = tbl->large_pool.start;
   369  
   370          /* The large pool is the last pool at the top of the table */
   371          if (entry >= largepool_start) {
   372                  p = &tbl->large_pool;
   373          } else {
   374                  unsigned int pool_nr = entry / tbl->poolsize;
   375  
   376                  BUG_ON(pool_nr > tbl->nr_pools);
                                       ^
This should be ">=".  The tbl->nr_pools value is either 1 or
IOMMU_NR_POOLS and the tbl->pools[] array has IOMMU_NR_POOLS elements.

   377                  p = &tbl->pools[pool_nr];
   378          }
   379  
   380          return p;
   381  }

regards,
dan carpenter