drm/amd/pm: Replace one-element array with flexible-array in struct _ATOM_Vega10_GFXCLK_Dependency_Table
Subsystems (3)
PATCH 1/1 drm/amd/pm: Replace one-element array with flexible-array in struct _ATOM_Vega10_GFXCLK_Dependency_Table
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Use flexible-array member in struct _ATOM_Vega10_GFXCLK_Dependency_Table, instead of one-element array.
Also, this helps with the ongoing efforts to enable -Warray-bounds and fix the following warning:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/vega10_hwmgr.c: In function ‘vega10_get_pp_table_entry_callback_func’:drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/vega10_hwmgr.c:3113:30: warning: array subscript 4 is above array bounds of ‘ATOM_Vega10_GFXCLK_Dependency_Record[1]’ {aka ‘struct _ATOM_Vega10_GFXCLK_Dependency_Record[1]’} [-Warray-bounds]
3113 | gfxclk_dep_table->entries[4].ulClk;
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +3 -3
@@ -161,9 +161,9 @@ typedef struct _ATOM_Vega10_MCLK_Dependency_Record { } ATOM_Vega10_MCLK_Dependency_Record;typedef struct _ATOM_Vega10_GFXCLK_Dependency_Table { -UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Vega10_GFXCLK_Dependency_Record entries[1 ];/* Dynamically allocate entries. */ +UCHAR ucRevId; +UCHAR ucNumEntries;/* Number of entries. */ +ATOM_Vega10_GFXCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ }ATOM_Vega10_GFXCLK_Dependency_Table ; typedef struct _ATOM_Vega10_MCLK_Dependency_Table {
Signature · 1 line
2.27.0
Alex Deucher
AppliedQuoted 17 lines · Gustavo A. R. Silva
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Use flexible-array member in struct
_ATOM_Vega10_GFXCLK_Dependency_Table, instead of one-element array.Also, this helps with the ongoing efforts to enable -Warray-bounds and fix the following warning:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/vega10_hwmgr.c: In function ‘vega10_get_pp_table_entry_callback_func’:drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/vega10_hwmgr.c:3113:30: warning: array subscript 4 is above array bounds of ‘ATOM_Vega10_GFXCLK_Dependency_Record[1]’ {aka ‘struct _ATOM_Vega10_GFXCLK_Dependency_Record[1]’} [-Warray-bounds]3113 | gfxclk_dep_table->entries[4].ulClk; | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Quoted 8 lines
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays
Applied. Thanks!
Alex
Quoted 24 lines
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +3
-4@@ -161,9 +161,9 @@ typedef struct _ATOM_Vega10_MCLK_Dependency_Record { } ATOM_Vega10_MCLK_Dependency_Record;typedef struct _ATOM_Vega10_GFXCLK_Dependency_Table { -UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Vega10_GFXCLK_Dependency_Record entries[1 ];/* Dynamically allocate entries. */ +UCHAR ucRevId; +UCHAR ucNumEntries;/* Number of entries. */ +ATOM_Vega10_GFXCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ }ATOM_Vega10_GFXCLK_Dependency_Table ; typedef struct _ATOM_Vega10_MCLK_Dependency_Table { --2.27.0
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx