drm/amdgpu/pptable: Fix __counted_by attribute
Subsystems (3)
PATCH 1/2 drm/amdgpu/pptable: Fix __counted_by attribute
The attribute is not helpful if commented out.
--- drivers/gpu/drm/amd/include/pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/include/pptable.h +1 -1
@@ -480,7 +480,7 @@ typedef struct _StateArray{//how many states we have UCHAR ucNumEntries; -ATOM_PPLIB_STATE_V2 states[]/* __counted_by(ucNumEntries) */ ; + ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); }StateArray;
Signature · 1 line
2.43.0
PATCH 2/2 drm/amd/pm: powerplay: Add `__counted_by` attribute for flexible arrays
This attribute is used to hint the length of flexible arrays to compiler and sanitizers.
--- .../drm/amd/pm/powerplay/hwmgr/pptable_v1_0.h | 36 +++++++++--------- drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h | 38 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pptable_v1_0.h +18 -18
@@ -163,8 +163,8 @@ typedef struct _ATOM_Tonga_State {typedef struct _ATOM_Tonga_State_Array {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_State entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_State entries[] __counted_by(ucNumEntries); }ATOM_Tonga_State_Array ; typedef struct _ATOM_Tonga_MCLK_Dependency_Record {
@@ -178,8 +178,8 @@ typedef struct _ATOM_Tonga_MCLK_Dependency_Record {typedef struct _ATOM_Tonga_MCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_MCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_MCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_MCLK_Dependency_Table ; typedef struct _ATOM_Tonga_SCLK_Dependency_Record {
@@ -193,8 +193,8 @@ typedef struct _ATOM_Tonga_SCLK_Dependency_Record {typedef struct _ATOM_Tonga_SCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_SCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_SCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_SCLK_Dependency_Table ; typedef struct _ATOM_Polaris_SCLK_Dependency_Record {
@@ -209,8 +209,8 @@ typedef struct _ATOM_Polaris_SCLK_Dependency_Record {typedef struct _ATOM_Polaris_SCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Polaris_SCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Polaris_SCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Polaris_SCLK_Dependency_Table ; typedef struct _ATOM_Tonga_PCIE_Record {
@@ -221,8 +221,8 @@ typedef struct _ATOM_Tonga_PCIE_Record {typedef struct _ATOM_Tonga_PCIE_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_PCIE_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_PCIE_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_PCIE_Table ; typedef struct _ATOM_Polaris10_PCIE_Record {
@@ -234,8 +234,8 @@ typedef struct _ATOM_Polaris10_PCIE_Record {typedef struct _ATOM_Polaris10_PCIE_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Polaris10_PCIE_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Polaris10_PCIE_Record entries[] __counted_by(ucNumEntries); }ATOM_Polaris10_PCIE_Table ;
@@ -251,8 +251,8 @@ typedef struct _ATOM_Tonga_MM_Dependency_Record {typedef struct _ATOM_Tonga_MM_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_MM_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_MM_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_MM_Dependency_Table ; typedef struct _ATOM_Tonga_Voltage_Lookup_Record {
@@ -264,8 +264,8 @@ typedef struct _ATOM_Tonga_Voltage_Lookup_Record {typedef struct _ATOM_Tonga_Voltage_Lookup_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_Voltage_Lookup_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_Voltage_Lookup_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_Voltage_Lookup_Table ; typedef struct _ATOM_Tonga_Fan_Table {
@@ -367,7 +367,7 @@ typedef struct _ATOM_Tonga_VCE_State_Record {typedef struct _ATOM_Tonga_VCE_State_Table {UCHAR ucRevId;UCHAR ucNumEntries; -ATOM_Tonga_VCE_State_Record entries[]; + ATOM_Tonga_VCE_State_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_VCE_State_Table ; typedef struct _ATOM_Tonga_PowerTune_Table {
@@ -481,7 +481,7 @@ typedef struct _ATOM_Tonga_Hard_Limit_Record {typedef struct _ATOM_Tonga_Hard_Limit_Table {UCHAR ucRevId;UCHAR ucNumEntries; -ATOM_Tonga_Hard_Limit_Record entries[]; + ATOM_Tonga_Hard_Limit_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_Hard_Limit_Table ; typedef struct _ATOM_Tonga_GPIO_Table {
drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h +19 -19
@@ -60,7 +60,7 @@ struct vi_dpm_level {struct vi_dpm_table {uint32_t count; -struct vi_dpm_level dpm_level[]; + struct vi_dpm_level dpm_level[] __counted_by(count); };#define PCIE_PERF_REQ_REMOVE_REGISTRY 0
@@ -91,7 +91,7 @@ struct phm_set_power_state_input {struct phm_clock_array {uint32_t count; -uint32_t values[]; + uint32_t values[] __counted_by(count); };struct phm_clock_voltage_dependency_record {
@@ -122,8 +122,8 @@ struct phm_acpclock_voltage_dependency_record { };struct phm_clock_voltage_dependency_table { -uint32_t count;/* Number of entries. */ -struct phm_clock_voltage_dependency_record entries[];/* Dynamically allocate count entries. */ +uint32_t count; + struct phm_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_phase_shedding_limits_record {
@@ -140,7 +140,7 @@ struct phm_uvd_clock_voltage_dependency_record {struct phm_uvd_clock_voltage_dependency_table {uint8_t count; -struct phm_uvd_clock_voltage_dependency_record entries[]; + struct phm_uvd_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_acp_clock_voltage_dependency_record {
@@ -150,7 +150,7 @@ struct phm_acp_clock_voltage_dependency_record {struct phm_acp_clock_voltage_dependency_table {uint32_t count; -struct phm_acp_clock_voltage_dependency_record entries[]; + struct phm_acp_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_vce_clock_voltage_dependency_record {
@@ -160,33 +160,33 @@ struct phm_vce_clock_voltage_dependency_record { };struct phm_phase_shedding_limits_table { -uint32_t count; -struct phm_phase_shedding_limits_record entries[]; +uint32_t count; + struct phm_phase_shedding_limits_record entries[] __counted_by(count); };struct phm_vceclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_vceclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_vceclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_uvdclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_uvdclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_uvdclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_samuclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_samuclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_samuclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_acpclock_voltage_dependency_table { -uint32_t count;/* Number of entries. */ -struct phm_acpclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint32_t count; + struct phm_acpclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_vce_clock_voltage_dependency_table {uint8_t count; -struct phm_vce_clock_voltage_dependency_record entries[]; + struct phm_vce_clock_voltage_dependency_record entries[] __counted_by(count); };
@@ -393,7 +393,7 @@ union phm_cac_leakage_record {struct phm_cac_leakage_table {uint32_t count; -union phm_cac_leakage_record entries[]; + union phm_cac_leakage_record entries[] __counted_by(count); };struct phm_samu_clock_voltage_dependency_record {
@@ -404,7 +404,7 @@ struct phm_samu_clock_voltage_dependency_record {struct phm_samu_clock_voltage_dependency_table {uint8_t count; -struct phm_samu_clock_voltage_dependency_record entries[]; + struct phm_samu_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_cac_tdp_table {
Signature · 1 line
2.43.0
Re: [PATCH 2/2] drm/amd/pm: powerplay: Add `__counted_by` attribute for flexible arrays
Quoted 5 lines · Mario Limonciello
This attribute is used to hint the length of flexible arrays to compiler and sanitizers.
Signed-off-by Mario Limonciello <[email protected]>
Quoted 232 lines
--- .../drm/amd/pm/powerplay/hwmgr/pptable_v1_0.h | 36 +++++++++--------- drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h | 38 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-)drivers/gpu/drm/amd/pm/powerplay/hwmgr/pptable_v1_0.h +18
-18@@ -163,8 +163,8 @@ typedef struct _ATOM_Tonga_State {typedef struct _ATOM_Tonga_State_Array {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_State entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_State entries[] __counted_by(ucNumEntries); }ATOM_Tonga_State_Array ; typedef struct _ATOM_Tonga_MCLK_Dependency_Record {@@ -178,8 +178,8 @@ typedef struct _ATOM_Tonga_MCLK_Dependency_Record {typedef struct _ATOM_Tonga_MCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_MCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_MCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_MCLK_Dependency_Table ; typedef struct _ATOM_Tonga_SCLK_Dependency_Record {@@ -193,8 +193,8 @@ typedef struct _ATOM_Tonga_SCLK_Dependency_Record {typedef struct _ATOM_Tonga_SCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_SCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_SCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_SCLK_Dependency_Table ; typedef struct _ATOM_Polaris_SCLK_Dependency_Record {@@ -209,8 +209,8 @@ typedef struct _ATOM_Polaris_SCLK_Dependency_Record {typedef struct _ATOM_Polaris_SCLK_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Polaris_SCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Polaris_SCLK_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Polaris_SCLK_Dependency_Table ; typedef struct _ATOM_Tonga_PCIE_Record {@@ -221,8 +221,8 @@ typedef struct _ATOM_Tonga_PCIE_Record {typedef struct _ATOM_Tonga_PCIE_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_PCIE_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_PCIE_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_PCIE_Table ; typedef struct _ATOM_Polaris10_PCIE_Record {@@ -234,8 +234,8 @@ typedef struct _ATOM_Polaris10_PCIE_Record {typedef struct _ATOM_Polaris10_PCIE_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Polaris10_PCIE_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Polaris10_PCIE_Record entries[] __counted_by(ucNumEntries); }ATOM_Polaris10_PCIE_Table ;@@ -251,8 +251,8 @@ typedef struct _ATOM_Tonga_MM_Dependency_Record {typedef struct _ATOM_Tonga_MM_Dependency_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_MM_Dependency_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_MM_Dependency_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_MM_Dependency_Table ; typedef struct _ATOM_Tonga_Voltage_Lookup_Record {@@ -264,8 +264,8 @@ typedef struct _ATOM_Tonga_Voltage_Lookup_Record {typedef struct _ATOM_Tonga_Voltage_Lookup_Table {UCHAR ucRevId; -UCHAR ucNumEntries;/* Number of entries. */ -ATOM_Tonga_Voltage_Lookup_Record entries[];/* Dynamically allocate entries. */ +UCHAR ucNumEntries; + ATOM_Tonga_Voltage_Lookup_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_Voltage_Lookup_Table ; typedef struct _ATOM_Tonga_Fan_Table {@@ -367,7 +367,7 @@ typedef struct _ATOM_Tonga_VCE_State_Record {typedef struct _ATOM_Tonga_VCE_State_Table {UCHAR ucRevId;UCHAR ucNumEntries; -ATOM_Tonga_VCE_State_Record entries[]; + ATOM_Tonga_VCE_State_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_VCE_State_Table ; typedef struct _ATOM_Tonga_PowerTune_Table {@@ -481,7 +481,7 @@ typedef struct _ATOM_Tonga_Hard_Limit_Record {typedef struct _ATOM_Tonga_Hard_Limit_Table {UCHAR ucRevId;UCHAR ucNumEntries; -ATOM_Tonga_Hard_Limit_Record entries[]; + ATOM_Tonga_Hard_Limit_Record entries[] __counted_by(ucNumEntries); }ATOM_Tonga_Hard_Limit_Table ; typedef struct _ATOM_Tonga_GPIO_Table {drivers/gpu/drm/amd/pm/powerplay/inc/hwmgr.h +19
-20@@ -60,7 +60,7 @@ struct vi_dpm_level {struct vi_dpm_table {uint32_t count; -struct vi_dpm_level dpm_level[]; + struct vi_dpm_level dpm_level[] __counted_by(count); };#define PCIE_PERF_REQ_REMOVE_REGISTRY 0@@ -91,7 +91,7 @@ struct phm_set_power_state_input {struct phm_clock_array {uint32_t count; -uint32_t values[]; + uint32_t values[] __counted_by(count); };struct phm_clock_voltage_dependency_record {@@ -122,8 +122,8 @@ struct phm_acpclock_voltage_dependency_record { };struct phm_clock_voltage_dependency_table { -uint32_t count;/* Number of entries. */ -struct phm_clock_voltage_dependency_record entries[];/* Dynamically allocate count entries. */ +uint32_t count; + struct phm_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_phase_shedding_limits_record {@@ -140,7 +140,7 @@ struct phm_uvd_clock_voltage_dependency_record {struct phm_uvd_clock_voltage_dependency_table {uint8_t count; -struct phm_uvd_clock_voltage_dependency_record entries[]; + struct phm_uvd_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_acp_clock_voltage_dependency_record {@@ -150,7 +150,7 @@ struct phm_acp_clock_voltage_dependency_record {struct phm_acp_clock_voltage_dependency_table {uint32_t count; -struct phm_acp_clock_voltage_dependency_record entries[]; + struct phm_acp_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_vce_clock_voltage_dependency_record {@@ -160,33 +160,33 @@ struct phm_vce_clock_voltage_dependency_record { };struct phm_phase_shedding_limits_table { -uint32_t count; -struct phm_phase_shedding_limits_record entries[]; +uint32_t count; + struct phm_phase_shedding_limits_record entries[] __counted_by(count); };struct phm_vceclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_vceclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_vceclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_uvdclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_uvdclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_uvdclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_samuclock_voltage_dependency_table { -uint8_t count;/* Number of entries. */ -struct phm_samuclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint8_t count; + struct phm_samuclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_acpclock_voltage_dependency_table { -uint32_t count;/* Number of entries. */ -struct phm_acpclock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +uint32_t count; + struct phm_acpclock_voltage_dependency_record entries[] __counted_by(count); };struct phm_vce_clock_voltage_dependency_table {uint8_t count; -struct phm_vce_clock_voltage_dependency_record entries[]; + struct phm_vce_clock_voltage_dependency_record entries[] __counted_by(count); };@@ -393,7 +393,7 @@ union phm_cac_leakage_record {struct phm_cac_leakage_table {uint32_t count; -union phm_cac_leakage_record entries[]; + union phm_cac_leakage_record entries[] __counted_by(count); };struct phm_samu_clock_voltage_dependency_record {@@ -404,7 +404,7 @@ struct phm_samu_clock_voltage_dependency_record {struct phm_samu_clock_voltage_dependency_table {uint8_t count; -struct phm_samu_clock_voltage_dependency_record entries[]; + struct phm_samu_clock_voltage_dependency_record entries[] __counted_by(count); };struct phm_cac_tdp_table { --2.43.0
Deucher, Alexander
maintainer[Public]
Quoted 10 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Friday, June 14, 2024 1:06 PM
To: [email protected]
Cc: Limonciello, Mario <[email protected]>; Tasos Sahanidis <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/pptable: Fix__counted_byattributeThe attribute is not helpful if commented out.
It's commented out on purpose because it breaks clang 19. See:
https://lists.freedesktop.org/archives/amd-gfx/2024-May/109223.html
Alex
Quoted 25 lines
Cc Tasos Sahanidis <[email protected]>Fixes c6c4dd540125 ("drm/amdgpu/pptable: Fix UBSAN array-index-out-of-bounds")
Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/include/pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/include/pptable.h +1
-2@@ -480,7 +480,7 @@ typedef struct _StateArray{//how many states we have UCHAR ucNumEntries; -ATOM_PPLIB_STATE_V2 states[]/* __counted_by(ucNumEntries) */ ; + ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); }StateArray; --2.43.0