From 3850e082db0fbd60962d56e56043ee955c122871 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 3 Jun 2026 18:14:32 +0300 Subject: [PATCH] drm/i915/color: join loops in xelpd_program_plane_pre_csc_lut() Use single for loops instead of two. Especially switching from a for-loop to a do-while-loop with the same loop index is confusing, and it's hard to figure out the end index. Define the end in terms of lut_size; there's three more entries after the first 128. Reviewed-by: Chaitanya Kumar Borah Link: https://patch.msgid.link/6d4f8bb713a998c199606c079bed924458f04f54.1780499355.git.jani.nikula@intel.com Signed-off-by: Jani Nikula --- drivers/gpu/drm/i915/display/intel_color.c | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_color.c b/drivers/gpu/drm/i915/display/intel_color.c index 5209a4cdd14d..48f09c73e513 100644 --- a/drivers/gpu/drm/i915/display/intel_color.c +++ b/drivers/gpu/drm/i915/display/intel_color.c @@ -3978,35 +3978,26 @@ xelpd_program_plane_pre_csc_lut(struct intel_dsb *dsb, PLANE_PAL_PREC_AUTO_INCREMENT); if (pre_csc_lut) { - for (i = 0; i < lut_size; i++) { - lut_val = drm_color_lut32_extract(pre_csc_lut[i].green, 24); + for (i = 0; i < lut_size + 3; i++) { + if (i < lut_size) + lut_val = drm_color_lut32_extract(pre_csc_lut[i].green, 24); + /* else duplicate last lut_val */ intel_de_write_dsb(display, dsb, PLANE_PRE_CSC_GAMC_DATA_ENH(pipe, plane, 0), lut_val); } - - /* Program the max register to clamp values > 1.0. */ - /* TODO: Restrict to 0x7ffffff */ - do { - intel_de_write_dsb(display, dsb, - PLANE_PRE_CSC_GAMC_DATA_ENH(pipe, plane, 0), - lut_val); - } while (i++ < 130); } else { - for (i = 0; i < lut_size; i++) { - lut_val = (i * ((1 << 24) - 1)) / (lut_size - 1); + for (i = 0; i < lut_size + 3; i++) { + if (i < lut_size) + lut_val = (i * ((1 << 24) - 1)) / (lut_size - 1); + else + lut_val = 1 << 24; intel_de_write_dsb(display, dsb, PLANE_PRE_CSC_GAMC_DATA_ENH(pipe, plane, 0), lut_val); } - - do { - intel_de_write_dsb(display, dsb, - PLANE_PRE_CSC_GAMC_DATA_ENH(pipe, plane, 0), - 1 << 24); - } while (i++ < 130); } intel_de_write_dsb(display, dsb, PLANE_PRE_CSC_GAMC_INDEX_ENH(pipe, plane, 0), 0);