The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v1 1/1] drm/i915/gem: Use simpler versions of min*()
@ 2026-08-25  9:35 Andy Shevchenko
  2026-08-25 13:44 ` Andi Shyti
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2026-08-25  9:35 UTC (permalink / raw)
  To: Andi Shyti, intel-gfx, dri-devel, linux-kernel
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
	David Airlie, Simona Vetter, Andy Shevchenko

Instead of harder to read min_array() and prone to mistakes min_t()
use min3() and min(). No functional changes intended. The types of
the values are unsigned, no side-effects are expected.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index ef9440166295..bf9e7480f0f5 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
@@ -153,11 +153,8 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
 			}
 		} while (1);
 
-		nr_pages = min_array(((unsigned long[]) {
-					folio_nr_pages(folio),
-					page_count - i,
-					max_segment / PAGE_SIZE,
-				      }), 3);
+		nr_pages = min3(folio_nr_pages(folio),
+				page_count - i, max_segment / PAGE_SIZE);
 
 		if (!i ||
 		    sg->length >= max_segment ||
@@ -168,8 +165,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
 			st->nents++;
 			sg_set_folio(sg, folio, nr_pages * PAGE_SIZE, 0);
 		} else {
-			nr_pages = min_t(unsigned long, nr_pages,
-					 (max_segment - sg->length) / PAGE_SIZE);
+			nr_pages = min(nr_pages, (max_segment - sg->length) / PAGE_SIZE);
 
 			sg->length += nr_pages * PAGE_SIZE;
 		}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] drm/i915/gem: Use simpler versions of min*()
  2026-08-25  9:35 [PATCH v1 1/1] drm/i915/gem: Use simpler versions of min*() Andy Shevchenko
@ 2026-08-25 13:44 ` Andi Shyti
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Shyti @ 2026-08-25 13:44 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andi Shyti, intel-gfx, dri-devel, linux-kernel, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter

Hi Andy,

On Tue, Aug 25, 2026 at 11:35:52AM +0200, Andy Shevchenko wrote:
> Instead of harder to read min_array() and prone to mistakes min_t()
> use min3() and min(). No functional changes intended. The types of
> the values are unsigned, no side-effects are expected.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> index ef9440166295..bf9e7480f0f5 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> @@ -153,11 +153,8 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
>  			}
>  		} while (1);
>  
> -		nr_pages = min_array(((unsigned long[]) {
> -					folio_nr_pages(folio),
> -					page_count - i,
> -					max_segment / PAGE_SIZE,
> -				      }), 3);
> +		nr_pages = min3(folio_nr_pages(folio),
> +				page_count - i, max_segment / PAGE_SIZE);

thanks for your patch, but there is another patch involving (and
fixing) this line of code[*]. You are welcome to join the review.

Thanks,
Andi

[*] https://patchwork.freedesktop.org/patch/746877/?series=172332&rev=1

>  
>  		if (!i ||
>  		    sg->length >= max_segment ||
> @@ -168,8 +165,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
>  			st->nents++;
>  			sg_set_folio(sg, folio, nr_pages * PAGE_SIZE, 0);
>  		} else {
> -			nr_pages = min_t(unsigned long, nr_pages,
> -					 (max_segment - sg->length) / PAGE_SIZE);
> +			nr_pages = min(nr_pages, (max_segment - sg->length) / PAGE_SIZE);
>  
>  			sg->length += nr_pages * PAGE_SIZE;
>  		}
> -- 
> 2.50.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-25 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25  9:35 [PATCH v1 1/1] drm/i915/gem: Use simpler versions of min*() Andy Shevchenko
2026-08-25 13:44 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox