Change the main "for" loop into "while" to get rid of obscure iterator "i" and use more descriptive name to indicate how many pages were already covered. Detect first loop with st->nents.
Signed-off-by: Krzysztof Karas <[email protected]> Reviewed-by: Andi Shyti <[email protected]> --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 59dae47fcfc8..792996b1e075 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -135,7 +135,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, unsigned int max_segment) { unsigned int page_count; /* restricted by sg_alloc_table */ - unsigned long i; + unsigned long pages_done = 0; struct scatterlist *sg; unsigned long next_pfn = 0; /* suppress gcc warning */ struct folio *folio = NULL; @@ -164,15 +164,15 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, sg = st->sgl; st->nents = 0; - for (i = 0; i < page_count; i++) { + while (pages_done < page_count) { unsigned long folio_page_index; unsigned long nr_pages; gfp_t gfp = noreclaim; - if (!i || (next_pfn >= folio_pfn(folio) + folio_nr_pages(folio))) { + if (!pages_done || (next_pfn >= folio_pfn(folio) + folio_nr_pages(folio))) { /* Grab the next folio if we exhausted the current one. */ - folio = shmem_shrink_get_folio(mapping, i, &gfp, - page_count, i915); + folio = shmem_shrink_get_folio(mapping, pages_done, + &gfp, page_count, i915); folio_page_index = 0; if (IS_ERR(folio)) { ret = PTR_ERR(folio); @@ -187,12 +187,12 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, } nr_pages = min3(folio_nr_pages(folio) - folio_page_index, - page_count - i, max_segment / PAGE_SIZE); + page_count - pages_done, max_segment / PAGE_SIZE); - if (!i || + if (!st->nents || sg->length >= max_segment || folio_pfn(folio) != next_pfn) { - if (i) + if (st->nents) sg = sg_next(sg); st->nents++; @@ -209,7 +209,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, * can be merged into the same SG entry. */ next_pfn = folio_pfn(folio) + folio_page_index + nr_pages; - i += nr_pages - 1; + pages_done += nr_pages; /* Check that the i965g/gm workaround works. */ GEM_BUG_ON(gfp & __GFP_DMA32 && next_pfn >= 0x00100000UL); -- 2.34.1
