Skip to content

Commit 0635559

Browse files
committed
vfio/type1: Use consistent types for page counts
Page count should more consistently be an unsigned long when passed as an argument while functions returning a number of pages should use a signed long to allow for -errno. vaddr_get_pfns() can therefore be upgraded to return long, though in practice it's currently limited by the batch capacity. In fact, the batch indexes are noted to never hold negative values, so while it doesn't make sense to bloat the structure with unsigned longs in this case, it does make sense to specify these as unsigned. No change in behavior expected. Reviewed-by: Peter Xu <[email protected]> Reviewed-by: Mitchell Augustin <[email protected]> Tested-by: Mitchell Augustin <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent eb996ee commit 0635559

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ struct vfio_dma {
103103
struct vfio_batch {
104104
struct page **pages; /* for pin_user_pages_remote */
105105
struct page *fallback_page; /* if pages alloc fails */
106-
int capacity; /* length of pages array */
107-
int size; /* of batch currently */
108-
int offset; /* of next entry in pages */
106+
unsigned int capacity; /* length of pages array */
107+
unsigned int size; /* of batch currently */
108+
unsigned int offset; /* of next entry in pages */
109109
};
110110

111111
struct vfio_iommu_group {
@@ -560,14 +560,14 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
560560
* initial offset. For VM_PFNMAP pfns, only the returned number of pfns and
561561
* returned initial pfn are provided; subsequent pfns are contiguous.
562562
*/
563-
static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
564-
long npages, int prot, unsigned long *pfn,
565-
struct vfio_batch *batch)
563+
static long vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
564+
unsigned long npages, int prot, unsigned long *pfn,
565+
struct vfio_batch *batch)
566566
{
567-
long pin_pages = min_t(long, npages, batch->capacity);
567+
unsigned long pin_pages = min_t(unsigned long, npages, batch->capacity);
568568
struct vm_area_struct *vma;
569569
unsigned int flags = 0;
570-
int ret;
570+
long ret;
571571

572572
if (prot & IOMMU_WRITE)
573573
flags |= FOLL_WRITE;
@@ -612,7 +612,7 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
612612
* first page and all consecutive pages with the same locking.
613613
*/
614614
static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
615-
long npage, unsigned long *pfn_base,
615+
unsigned long npage, unsigned long *pfn_base,
616616
unsigned long limit, struct vfio_batch *batch)
617617
{
618618
unsigned long pfn;
@@ -724,7 +724,7 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
724724
}
725725

726726
static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
727-
unsigned long pfn, long npage,
727+
unsigned long pfn, unsigned long npage,
728728
bool do_accounting)
729729
{
730730
long unlocked = 0, locked = 0;

0 commit comments

Comments
 (0)