mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: replace min/max nesting with clamp()
@ 2025-08-08  2:52 Xichao Zhao
  2025-08-18  0:09 ` Alex Hung
  0 siblings, 1 reply; 2+ messages in thread
From: Xichao Zhao @ 2025-08-08  2:52 UTC (permalink / raw)
  To: austin.zheng, jun.lei, harry.wentland, sunpeng.li,
	alexander.deucher, christian.koenig, airlied, simona
  Cc: siqueira, amd-gfx, dri-devel, linux-kernel, Xichao Zhao

The clamp() macro explicitly expresses the intent of constraining
a value within bounds.Therefore, replacing min(max(a, b), c) with
clamp(val, lo, hi) can improve code readability.

Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
---
 drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
index 0c0b2d67c9cd..00767b8ccdae 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
@@ -435,12 +435,12 @@ void dcn301_fpu_calculate_wm_and_dlg(struct dc *dc,
 						&context->bw_ctx.dml, pipes, pipe_cnt);
 	/* WM Set C */
 	table_entry = &bw_params->wm_table.entries[WM_C];
-	vlevel = min(max(vlevel_req, 2), vlevel_max);
+	vlevel = clamp(vlevel_req, 2, vlevel_max);
 	calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.c,
 						&context->bw_ctx.dml, pipes, pipe_cnt);
 	/* WM Set B */
 	table_entry = &bw_params->wm_table.entries[WM_B];
-	vlevel = min(max(vlevel_req, 1), vlevel_max);
+	vlevel = clamp(vlevel_req, 1, vlevel_max);
 	calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.b,
 						&context->bw_ctx.dml, pipes, pipe_cnt);
 
-- 
2.34.1


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

* Re: [PATCH] drm/amd/display: replace min/max nesting with clamp()
  2025-08-08  2:52 [PATCH] drm/amd/display: replace min/max nesting with clamp() Xichao Zhao
@ 2025-08-18  0:09 ` Alex Hung
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Hung @ 2025-08-18  0:09 UTC (permalink / raw)
  To: Xichao Zhao, austin.zheng, jun.lei, harry.wentland, sunpeng.li,
	alexander.deucher, christian.koenig, airlied, simona
  Cc: siqueira, amd-gfx, dri-devel, linux-kernel

Reviewed-by: Alex Hung <alex.hung@amd.com>

On 8/7/25 20:52, Xichao Zhao wrote:
> The clamp() macro explicitly expresses the intent of constraining
> a value within bounds.Therefore, replacing min(max(a, b), c) with
> clamp(val, lo, hi) can improve code readability.
> 
> Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
> ---
>   drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
> index 0c0b2d67c9cd..00767b8ccdae 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
> +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn301/dcn301_fpu.c
> @@ -435,12 +435,12 @@ void dcn301_fpu_calculate_wm_and_dlg(struct dc *dc,
>   						&context->bw_ctx.dml, pipes, pipe_cnt);
>   	/* WM Set C */
>   	table_entry = &bw_params->wm_table.entries[WM_C];
> -	vlevel = min(max(vlevel_req, 2), vlevel_max);
> +	vlevel = clamp(vlevel_req, 2, vlevel_max);
>   	calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.c,
>   						&context->bw_ctx.dml, pipes, pipe_cnt);
>   	/* WM Set B */
>   	table_entry = &bw_params->wm_table.entries[WM_B];
> -	vlevel = min(max(vlevel_req, 1), vlevel_max);
> +	vlevel = clamp(vlevel_req, 1, vlevel_max);
>   	calculate_wm_set_for_vlevel(vlevel, table_entry, &context->bw_ctx.bw.dcn.watermarks.b,
>   						&context->bw_ctx.dml, pipes, pipe_cnt);
>   


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

end of thread, other threads:[~2025-08-18  0:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-08  2:52 [PATCH] drm/amd/display: replace min/max nesting with clamp() Xichao Zhao
2025-08-18  0:09 ` Alex Hung

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

all inboxes | Powered by JetHome®