Re: [PATCH v2 5/5] drm/edid: Make sure the CEA mode arrays have the correct amount of modes

2019-07-11 Thread Ville Syrjälä
On Thu, Jul 11, 2019 at 01:32:34PM +0300, Ville Syrjala wrote:
> From: Ville Syrjälä 
> 
> We depend on a specific relationship between the VIC number and the
> index in the CEA mode arrays. Assert that the arrays have the excpected
> size to make sure we've not accidentally left holes in them.
> 
> Cc: Hans Verkuil 
> Cc: Shashank Sharma 
> Signed-off-by: Ville Syrjälä 
> ---
>  drivers/gpu/drm/drm_edid.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index e6b1e785d158..f0b449225727 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3209,6 +3209,9 @@ static u8 *drm_find_cea_extension(const struct edid 
> *edid)
>  
>  static const struct drm_display_mode *cea_mode_for_vic(u8 vic)
>  {
> + BUILD_BUG_ON(ARRAY_SIZE(edid_cea_modes_1) != 127);
> + BUILD_BUG_ON(ARRAY_SIZE(edid_cea_modes_193) != 27);

Maybe better to write these as something like

BUILD_BUG_ON(1 + ARRAY_SIZE(edid_cea_modes_1) - 1 != 127);
BUILD_BUG_ON(193 + ARRAY_SIZE(edid_cea_modes_193) - 1 != 219);

to make it super trivial to cross check against the VICs of the
first and last entry in the arrays.

> +
>   if (vic >= 1 && vic < 1 + ARRAY_SIZE(edid_cea_modes_1))
>   return _cea_modes_1[vic - 1];
>   if (vic >= 193 && vic < 193 + ARRAY_SIZE(edid_cea_modes_193))
> -- 
> 2.21.0

-- 
Ville Syrjälä
Intel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 5/5] drm/edid: Make sure the CEA mode arrays have the correct amount of modes

2019-07-11 Thread Ville Syrjala
From: Ville Syrjälä 

We depend on a specific relationship between the VIC number and the
index in the CEA mode arrays. Assert that the arrays have the excpected
size to make sure we've not accidentally left holes in them.

Cc: Hans Verkuil 
Cc: Shashank Sharma 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index e6b1e785d158..f0b449225727 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3209,6 +3209,9 @@ static u8 *drm_find_cea_extension(const struct edid *edid)
 
 static const struct drm_display_mode *cea_mode_for_vic(u8 vic)
 {
+   BUILD_BUG_ON(ARRAY_SIZE(edid_cea_modes_1) != 127);
+   BUILD_BUG_ON(ARRAY_SIZE(edid_cea_modes_193) != 27);
+
if (vic >= 1 && vic < 1 + ARRAY_SIZE(edid_cea_modes_1))
return _cea_modes_1[vic - 1];
if (vic >= 193 && vic < 193 + ARRAY_SIZE(edid_cea_modes_193))
-- 
2.21.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel