Skip to content

Commit 123a175

Browse files
superm1alexdeucher
authored andcommitted
drm/amd: Use dynamic array size declaration for amdgpu_connector_add_common_modes()
[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]> Reviewed-by: Alex Deucher <[email protected]> Reviewed-by: Timur Kristóf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 1f721eb commit 123a175

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,11 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
398398
struct drm_display_mode *mode = NULL;
399399
struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
400400
int i;
401+
int n;
401402
static const struct mode_size {
402403
int w;
403404
int h;
404-
} common_modes[17] = {
405+
} common_modes[] = {
405406
{ 640, 480},
406407
{ 720, 480},
407408
{ 800, 600},
@@ -421,7 +422,9 @@ static void amdgpu_connector_add_common_modes(struct drm_encoder *encoder,
421422
{1920, 1200}
422423
};
423424

424-
for (i = 0; i < 17; i++) {
425+
n = ARRAY_SIZE(common_modes);
426+
427+
for (i = 0; i < n; i++) {
425428
if (amdgpu_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
426429
if (common_modes[i].w > 1024 ||
427430
common_modes[i].h > 768)

0 commit comments

Comments
 (0)