drivers/gpu/drm/radeon/radeon_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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.
Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
---
drivers/gpu/drm/radeon/radeon_display.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index b4bf5dfeea2d..d66c1a30df95 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -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 */
--
2.34.1
On 12.08.25 05:16, Xichao Zhao wrote:
> 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.
>
> Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/radeon/radeon_display.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
> index b4bf5dfeea2d..d66c1a30df95 100644
> --- a/drivers/gpu/drm/radeon/radeon_display.c
> +++ b/drivers/gpu/drm/radeon/radeon_display.c
> @@ -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 */
Applied. Thanks!
Alex
On Tue, Aug 12, 2025 at 2:49 AM Christian König
<christian.koenig@amd.com> wrote:
>
> On 12.08.25 05:16, Xichao Zhao wrote:
> > 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.
> >
> > Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> > ---
> > drivers/gpu/drm/radeon/radeon_display.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
> > index b4bf5dfeea2d..d66c1a30df95 100644
> > --- a/drivers/gpu/drm/radeon/radeon_display.c
> > +++ b/drivers/gpu/drm/radeon/radeon_display.c
> > @@ -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 */
>
© 2016 - 2026 Red Hat, Inc.