]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/radeon: replace min/max nesting with clamp()
authorXichao Zhao <zhao.xichao@vivo.com>
Tue, 12 Aug 2025 03:16:03 +0000 (11:16 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 15 Aug 2025 17:03:21 +0000 (13:03 -0400)
The clamp() macro explicitly expresses the intent of constraining
a value within bounds.Therefore, replacing min(max(a, b), c) and
max(min(a,b),c) with clamp(val, lo, hi) can improve code readability.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/radeon_display.c

index b4bf5dfeea2dcd81f864c1c6d84077468be56125..d66c1a30df951ff9b3289562755a54db22e1b562 100644 (file)
@@ -926,10 +926,10 @@ static void avivo_get_fb_ref_div(unsigned nom, unsigned den, unsigned post_div,
                                 unsigned *fb_div, unsigned *ref_div)
 {
        /* limit reference * post divider to a maximum */
-       ref_div_max = max(min(100 / post_div, ref_div_max), 1u);
+       ref_div_max = clamp(100 / post_div, 1u, ref_div_max);
 
        /* get matching reference and feedback divider */
-       *ref_div = min(max(den/post_div, 1u), ref_div_max);
+       *ref_div = clamp(den / post_div, 1u, ref_div_max);
        *fb_div = DIV_ROUND_CLOSEST(nom * *ref_div * post_div, den);
 
        /* limit fb divider to its maximum */