Re: [PATCH 1/2] drm/amd/display: avoid divide-by-zero in __is_lut_linear()
Melissa Wen <[email protected]>
| Newsgroups | org.freedesktop.lists.amd-gfx,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
On 04/08/2026 23:04, Harry Wentland wrote:
> __is_lut_linear() computes the expected value of each entry with
>
> expected = i * MAX_DRM_LUT_VALUE / (size - 1);
>
> If it is ever called with a single-entry LUT, size - 1 is zero and the
> kernel takes a divide error (#DE). A LUT with fewer than two entries
> cannot describe a linear mapping anyway, so return false early instead
> of dividing by zero.
>
> Fixes: 086247a4b2fb ("drm/amd/display: Use 4096 lut entries")
> Cc:[email protected]
> Signed-off-by: Harry Wentland<[email protected]>
> ---
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> index 7b68c6846039..26e5c89375a5 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> @@ -471,6 +471,12 @@ bool __is_lut_linear(const struct drm_color_lut *lut, uint32_t size)
> uint32_t expected;
> int delta;
>
> + /* A LUT with fewer than two entries can't be interpolated and would
> + * divide by zero below (size - 1); it can't be treated as linear.
> + */
> + if (size < 2)
> + return false;
> +
LGTM
Reviewed-by: Melissa Wen <[email protected]>
> for (i = 0; i < size; i++) {
> /* All color values should equal */
> if ((lut[i].red != lut[i].green) || (lut[i].green != lut[i].blue))