diff options
author | Joao Martins <joao.m.martins@oracle.com> | 2024-06-27 13:01:03 +0200 |
---|---|---|
committer | Jason Gunthorpe <jgg@nvidia.com> | 2024-06-28 18:12:23 +0200 |
commit | 00fa1a89917fbc319909231e648439b26e8857af (patch) | |
tree | 17eec65c52afcabd92e3f8503df2b363c4efec18 /drivers/iommu | |
parent | iommufd/iova_bitmap: Move initial pinning to iova_bitmap_for_each() (diff) | |
download | linux-00fa1a89917fbc319909231e648439b26e8857af.tar.xz linux-00fa1a89917fbc319909231e648439b26e8857af.zip |
iommufd/iova_bitmap: Consolidate iova_bitmap_set exit conditionals
There's no need to have two conditionals when they are closely tied
together. Move the setting of bitmap::set_ahead_length after it checks for
::pages array out of bounds access.
Link: https://lore.kernel.org/r/20240627110105.62325-10-joao.m.martins@oracle.com
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Matt Ochs <mochs@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/iommu')
-rw-r--r-- | drivers/iommu/iommufd/iova_bitmap.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/iommu/iommufd/iova_bitmap.c b/drivers/iommu/iommufd/iova_bitmap.c index b94636b7977e..be97bb464f6b 100644 --- a/drivers/iommu/iommufd/iova_bitmap.c +++ b/drivers/iommu/iommufd/iova_bitmap.c @@ -465,18 +465,18 @@ void iova_bitmap_set(struct iova_bitmap *bitmap, last_bit - cur_bit + 1); void *kaddr; - if (unlikely(page_idx > last_page_idx)) + if (unlikely(page_idx > last_page_idx)) { + unsigned long left = + ((last_bit - cur_bit + 1) << mapped->pgshift); + + bitmap->set_ahead_length = left; break; + } kaddr = kmap_local_page(mapped->pages[page_idx]); bitmap_set(kaddr, offset, nbits); kunmap_local(kaddr); cur_bit += nbits; } while (cur_bit <= last_bit); - - if (unlikely(cur_bit <= last_bit)) { - bitmap->set_ahead_length = - ((last_bit - cur_bit + 1) << bitmap->mapped.pgshift); - } } EXPORT_SYMBOL_NS_GPL(iova_bitmap_set, IOMMUFD); |