On Wed, Sep 24, 2025 at 12:54 PM Mario Limonciello
<[email protected]> wrote:
>
> [Why]
> Adding or removing a mode from common_modes[] can be fragile if a user
> forgot to update the for loop boundaries.
>
> [How]
> Use ARRAY_SIZE() to detect size of the array and use that instead.
>
> Cc: Timur Kristóf <[email protected]>
> Signed-off-by: Mario Limonciello <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> index 84a8af961531..ba24a0eba2a4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> @@ -398,10 +398,11 @@ static void amdgpu_connector_add_common_modes(struct 
> drm_encoder *encoder,
>         struct drm_display_mode *mode = NULL;
>         struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
>         int i;
> +       int n;
>         static const struct mode_size {
>                 int w;
>                 int h;
> -       } common_modes[17] = {
> +       } common_modes[] = {
>                 { 640,  480},
>                 { 720,  480},
>                 { 800,  600},
> @@ -421,7 +422,9 @@ static void amdgpu_connector_add_common_modes(struct 
> drm_encoder *encoder,
>                 {1920, 1200}
>         };
>
> -       for (i = 0; i < 17; i++) {
> +       n = ARRAY_SIZE(common_modes);
> +
> +       for (i = 0; i < n; i++) {

Could drop n and just use ARRAY_SIZE() directly here.  Either way:
Reviewed-by: Alex Deucher <[email protected]>

>                 if (amdgpu_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
>                         if (common_modes[i].w > 1024 ||
>                             common_modes[i].h > 768)
> --
> 2.51.0
>

Reply via email to