drm/amd/pm: Replace one-element arrays with flexible-array members
Subsystems (3)
cover drm/amd/pm: Replace one-element arrays with flexible-array members
Hi all,
This series aims to replace one-element arrays with flexible-array members.
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].
Refactor the code according to the use of flexible-array members, instead of one-element arrays, and use the struct_size() helper to calculate the size for the dynamic memory allocation.
Also, save some heap space in the process. More on this on each individual patch.
This series also addresses multiple of the following sorts of warnings:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/smu8_hwmgr.c:1515:37:
warning: array subscript 1 is above array bounds of ‘const struct phm_clock_voltage_dependency_record[1]’ [-Warray-bounds]
which, in this case, they are false positives, but nervertheless should be fixed in order to enable -Warray-bounds[3][4].
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
[3] https://git.kernel.org/linus/44720996e2d79e47d508b0abe99b931a726a3197
[4] https://github.com/KSPP/linux/issues/109
Gustavo A. R. Silva (14):
drm/amd/pm: Replace one-element array with flexible-array member drm/amd/pm: Replace one-element array with flexible-array member in
struct vi_dpm_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_clock_array
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_uvd_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_acp_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_phase_shedding_limits_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_vce_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_cac_leakage_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_samu_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_mm_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_voltage_lookup_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_pcie_table
drm/amd/pm: Replace one-element array with flexible-array in struct
ATOM_Vega10_GFXCLK_Dependency_Table
drivers/gpu/drm/amd/pm/inc/hwmgr.h | 20 ++--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 8 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 85 +++++++----------- .../amd/pm/powerplay/hwmgr/processpptables.c | 85 +++++++----------- .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c | 2 +- .../drm/amd/pm/powerplay/hwmgr/smu_helper.c | 5 +- .../amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- .../powerplay/hwmgr/vega10_processpptables.c | 88 ++++++------------- 8 files changed, 107 insertions(+), 188 deletions(-)
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 1/14 drm/amd/pm: Replace one-element array with flexible-array member
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].
Refactor the code according to the use of a flexible-array member in struct phm_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 4 ++-- drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 9 +++------ drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c | 2 +- drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +2 -2
@@ -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[1 ];/* Dynamically allocate count entries. */ +uint32_t count;/* Number of entries. */ +struct phm_clock_voltage_dependency_record entries[];/* Dynamically allocate count entries. */ };struct phm_phase_shedding_limits_record {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +3 -6
@@ -377,14 +377,11 @@ static int get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr, const ATOM_PPLIB_Clock_Voltage_Dependency_Table *table) { -unsigned long table_size, i; +unsigned long i;struct phm_clock_voltage_dependency_table *dep_table; - table_size =sizeof (unsigned long ) + -sizeof (struct phm_clock_voltage_dependency_table ) - * table->ucNumEntries; - - dep_table =kzalloc (table_size,GFP_KERNEL ); + dep_table =kzalloc (struct_size (dep_table, entries, table->ucNumEntries), +GFP_KERNEL );if (NULL == dep_table)return -ENOMEM ;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c +1 -1
@@ -276,7 +276,7 @@ static int smu8_init_dynamic_state_adjustment_rule_settings( {struct phm_clock_voltage_dependency_table *table_clk_vlt; - table_clk_vlt =kzalloc (struct_size (table_clk_vlt, entries,7 ), + table_clk_vlt =kzalloc (struct_size (table_clk_vlt, entries,8 ),GFP_KERNEL );if (NULL == table_clk_vlt) {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c +2 -3
@@ -492,13 +492,12 @@ int phm_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,*/ int phm_initializa_dynamic_state_adjustment_rule_settings (struct pp_hwmgr *hwmgr) { -uint32_t table_size;struct phm_clock_voltage_dependency_table *table_clk_vlt;struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);/* initialize vddc_dep_on_dal_pwrl table */ - table_size =sizeof (uint32_t ) +4 *sizeof (struct phm_clock_voltage_dependency_record ); - table_clk_vlt =kzalloc (table_size,GFP_KERNEL ); + table_clk_vlt =kzalloc (struct_size (table_clk_vlt, entries,4 ), +GFP_KERNEL );if (NULL == table_clk_vlt) {pr_err ("Can not allocate space for vddc_dep_on_dal_pwrl! \n" );
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/14 drm/amd/pm: Replace one-element array with flexible-array member in struct vi_dpm_table
In reply to Gustavo A. R. SilvaThere 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 a flexible-array member in struct vi_dpm_table instead of a one-element array.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -60,7 +60,7 @@ struct vi_dpm_level {struct vi_dpm_table {uint32_t count; -struct vi_dpm_level dpm_level[1 ]; +struct vi_dpm_level dpm_level[]; };#define PCIE_PERF_REQ_REMOVE_REGISTRY 0
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_clock_array
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_clock_array, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 11 ++++------- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 7 +++---- .../amd/pm/powerplay/hwmgr/vega10_processpptables.c | 9 +++------ 4 files changed, 11 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -91,7 +91,7 @@ struct phm_set_power_state_input {struct phm_clock_array {uint32_t count; -uint32_t values[1 ]; +uint32_t values[]; };struct phm_clock_voltage_dependency_record {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +4 -7
@@ -318,19 +318,16 @@ static int get_valid_clk(phm_ppt_v1_clock_voltage_dependency_table const *clk_volt_pp_table ) { -uint32_t table_size, i; +uint32_t i;struct phm_clock_array *table;phm_ppt_v1_clock_voltage_dependency_record *dep_record;PP_ASSERT_WITH_CODE ((0 != clk_volt_pp_table->count),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (uint32_t ) * clk_volt_pp_table->count; - - table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == table) + table =kzalloc (struct_size (table, values, clk_volt_pp_table->count), +GFP_KERNEL ); +if (!table)return -ENOMEM ; table->count = (uint32_t )clk_volt_pp_table->count;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +3 -4
@@ -404,12 +404,11 @@ static int get_valid_clk(struct pp_hwmgr *hwmgr,struct phm_clock_array **ptable, const struct phm_clock_voltage_dependency_table *table) { - unsigned long table_size, i; + unsigned long i;struct phm_clock_array *clock_table; - table_size =sizeof (unsigned long ) +sizeof (unsigned long ) * table->count; - clock_table =kzalloc (table_size,GFP_KERNEL ); -if (NULL == clock_table) + clock_table =kzalloc (struct_size (clock_table, values, table->count),GFP_KERNEL ); +if (!clock_table)return -ENOMEM ; clock_table->count = (unsigned long )table->count;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +3 -6
@@ -875,17 +875,14 @@ static int get_valid_clk(struct phm_clock_array **clk_table, const phm_ppt_v1_clock_voltage_dependency_table *clk_volt_pp_table) { - uint32_t table_size, i; + uint32_t i;struct phm_clock_array *table;PP_ASSERT_WITH_CODE (clk_volt_pp_table->count,"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (uint32_t ) * clk_volt_pp_table->count; - - table =kzalloc (table_size,GFP_KERNEL ); - + table =kzalloc (struct_size (table, values, clk_volt_pp_table->count), +GFP_KERNEL );if (!table)return -ENOMEM ;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_uvd_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_uvd_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying table->numEntries by sizeof(struct phm_uvd_clock_voltage_dependency_table) when it should have multiplied it by sizeof(phm_uvd_clock_voltage_dependency_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -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[1 ]; +struct phm_uvd_clock_voltage_dependency_record entries[]; };struct phm_acp_clock_voltage_dependency_record {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +4 -7
@@ -1105,15 +1105,12 @@ static int get_uvd_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,const ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *table, const UVDClockInfoArray *array) { - unsigned long table_size, i; + unsigned long i;struct phm_uvd_clock_voltage_dependency_table *uvd_table; - table_size =sizeof (unsigned long ) + -sizeof (struct phm_uvd_clock_voltage_dependency_table ) * - table->numEntries; - - uvd_table =kzalloc (table_size,GFP_KERNEL ); -if (NULL == uvd_table) + uvd_table =kzalloc (struct_size (uvd_table, entries, table->numEntries), +GFP_KERNEL ); +if (!uvd_table)return -ENOMEM ; uvd_table->count = table->numEntries;
Signature · 1 line
2.27.0
PATCH 5/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_acp_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_acp_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying table->numEntries by sizeof(struct phm_acp_clock_voltage_dependency_table) when it should have multiplied it by sizeof(phm_acp_clock_voltage_dependency_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -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[1 ]; +struct phm_acp_clock_voltage_dependency_record entries[]; };struct phm_vce_clock_voltage_dependency_record {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +4 -7
@@ -1194,15 +1194,12 @@ static int get_acp_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,struct phm_acp_clock_voltage_dependency_table **ptable, const ATOM_PPLIB_ACPClk_Voltage_Limit_Table *table) { - unsigned table_size, i; + unsigned long i;struct phm_acp_clock_voltage_dependency_table *acp_table; - table_size =sizeof (unsigned long ) + -sizeof (struct phm_acp_clock_voltage_dependency_table ) * - table->numEntries; - - acp_table =kzalloc (table_size,GFP_KERNEL ); -if (NULL == acp_table) + acp_table =kzalloc (struct_size (acp_table, entries, table->numEntries), +GFP_KERNEL ); +if (!acp_table)return -ENOMEM ; acp_table->count = (unsigned long )table->numEntries;
Signature · 6 lines
2.27.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_phase_shedding_limits_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_phase_shedding_limits_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying ptable->ucNumEntries by sizeof(struct phm_phase_shedding_limits_table) when it should have multiplied it by sizeof(struct phm_phase_shedding_limits_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -161,7 +161,7 @@ struct phm_vce_clock_voltage_dependency_record {struct phm_phase_shedding_limits_table {uint32_t count; -struct phm_phase_shedding_limits_record entries[1 ]; +struct phm_phase_shedding_limits_record entries[]; };struct phm_vceclock_voltage_dependency_table {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +4 -8
@@ -1530,16 +1530,12 @@ static int init_phase_shedding_table(struct pp_hwmgr *hwmgr, (((unsigned long )powerplay_table4) +le16_to_cpu (powerplay_table4->usVddcPhaseShedLimitsTableOffset));struct phm_phase_shedding_limits_table *table; -unsigned long size, i; +unsigned long i; - size =sizeof (unsigned long ) + - (sizeof (struct phm_phase_shedding_limits_table ) * - ptable->ucNumEntries); - - table =kzalloc (size,GFP_KERNEL ); - -if (table ==NULL ) + table =kzalloc (struct_size (table, entries, ptable->ucNumEntries), +GFP_KERNEL ); +if (!table)return -ENOMEM ; table->count = (unsigned long )ptable->ucNumEntries;
Signature · 1 line
2.27.0
PATCH 7/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_vce_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_vce_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying table->numEntries by sizeof(struct phm_vce_clock_voltage_dependency_table) when it should have multiplied it by sizeof(struct phm_vce_clock_voltage_dependency_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -186,7 +186,7 @@ struct phm_acpclock_voltage_dependency_table {struct phm_vce_clock_voltage_dependency_table {uint8_t count; -struct phm_vce_clock_voltage_dependency_record entries[1 ]; +struct phm_vce_clock_voltage_dependency_record entries[]; };
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +4 -7
@@ -1135,15 +1135,12 @@ static int get_vce_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *table, const VCEClockInfoArray *array) { - unsigned long table_size, i; + unsigned long i;struct phm_vce_clock_voltage_dependency_table *vce_table =NULL ; - table_size =sizeof (unsigned long ) + -sizeof (struct phm_vce_clock_voltage_dependency_table ) - * table->numEntries; - - vce_table =kzalloc (table_size,GFP_KERNEL ); -if (NULL == vce_table) + vce_table =kzalloc (struct_size (vce_table, entries, table->numEntries), +GFP_KERNEL ); +if (!vce_table)return -ENOMEM ; vce_table->count = table->numEntries;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 8/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_cac_leakage_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_cac_leakage_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying table->ucNumEntries by sizeof(struct phm_cac_leakage_table) when it should have been multiplied it by sizeof(struct phm_cac_leakage_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../drm/amd/pm/powerplay/hwmgr/processpptables.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -393,7 +393,7 @@ union phm_cac_leakage_record {struct phm_cac_leakage_table {uint32_t count; -union phm_cac_leakage_record entries[1 ]; +union phm_cac_leakage_record entries[]; };struct phm_samu_clock_voltage_dependency_record {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +5 -8
@@ -1384,17 +1384,14 @@ static int get_cac_leakage_table(struct pp_hwmgr *hwmgr, const ATOM_PPLIB_CAC_Leakage_Table *table) {struct phm_cac_leakage_table *cac_leakage_table; -unsigned long table_size, i; +unsigned long i; -if (hwmgr ==NULL || table ==NULL || ptable ==NULL ) +if (!hwmgr || !table || !ptable)return -EINVAL ; - table_size =sizeof (ULONG ) + - (sizeof (struct phm_cac_leakage_table ) * table->ucNumEntries); - - cac_leakage_table =kzalloc (table_size,GFP_KERNEL ); - -if (cac_leakage_table ==NULL ) + cac_leakage_table =kzalloc (struct_size (cac_leakage_table, entries, table->ucNumEntries), +GFP_KERNEL ); +if (!cac_leakage_table)return -ENOMEM ; cac_leakage_table->count = (ULONG )table->ucNumEntries;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 9/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_samu_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_samu_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
Also, save some heap space as the original code is multiplying table->numEntries by sizeof(struct phm_samu_clock_voltage_dependency_table) when it should have been multiplied it bysizeof(struct phm_samu_clock_voltage_dependency_record) instead.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/inc/hwmgr.h +1 -1
@@ -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[1 ]; +struct phm_samu_clock_voltage_dependency_record entries[]; };struct phm_cac_tdp_table {
drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +4 -7
@@ -1163,15 +1163,12 @@ static int get_samu_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,struct phm_samu_clock_voltage_dependency_table **ptable, const ATOM_PPLIB_SAMClk_Voltage_Limit_Table *table) { - unsigned long table_size, i; + unsigned long i;struct phm_samu_clock_voltage_dependency_table *samu_table; - table_size =sizeof (unsigned long ) + -sizeof (struct phm_samu_clock_voltage_dependency_table ) * - table->numEntries; - - samu_table =kzalloc (table_size,GFP_KERNEL ); -if (NULL == samu_table) + samu_table =kzalloc (struct_size (samu_table, entries, table->numEntries), +GFP_KERNEL ); +if (!samu_table)return -ENOMEM ; samu_table->count = table->numEntries;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 10/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_ppt_v1_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
Link:
--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 2 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 31 ++++-------- .../powerplay/hwmgr/vega10_processpptables.c | 50 ++++++------------- 3 files changed, 27 insertions(+), 56 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +1 -1
@@ -48,7 +48,7 @@ typedef struct phm_ppt_v1_clock_voltage_dependency_record phm_ppt_v1_clock_voltastruct phm_ppt_v1_clock_voltage_dependency_table {uint32_t count;/* Number of entries. */ -phm_ppt_v1_clock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +phm_ppt_v1_clock_voltage_dependency_record entries[];/* Dynamically allocate count entries. */ };typedef struct phm_ppt_v1_clock_voltage_dependency_table phm_ppt_v1_clock_voltage_dependency_table ;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +11 -20
@@ -367,7 +367,7 @@ static int get_mclk_voltage_dependency_table(ATOM_Tonga_MCLK_Dependency_Table const *mclk_dep_table ) { -uint32_t table_size, i; +uint32_t i;phm_ppt_v1_clock_voltage_dependency_table *mclk_table;phm_ppt_v1_clock_voltage_dependency_record *mclk_table_record;ATOM_Tonga_MCLK_Dependency_Record *mclk_dep_record;
@@ -375,12 +375,9 @@ static int get_mclk_voltage_dependency_table(PP_ASSERT_WITH_CODE ((0 != mclk_dep_table->ucNumEntries),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) +sizeof (phm_ppt_v1_clock_voltage_dependency_record) - * mclk_dep_table->ucNumEntries; - - mclk_table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == mclk_table) + mclk_table =kzalloc (struct_size (mclk_table, entries, mclk_dep_table->ucNumEntries), +GFP_KERNEL ); +if (!mclk_table)return -ENOMEM ; mclk_table->count = (uint32_t )mclk_dep_table->ucNumEntries;
@@ -410,7 +407,7 @@ static int get_sclk_voltage_dependency_table(PPTable_Generic_SubTable_Header const *sclk_dep_table ) { -uint32_t table_size, i; +uint32_t i;phm_ppt_v1_clock_voltage_dependency_table *sclk_table;phm_ppt_v1_clock_voltage_dependency_record *sclk_table_record;
@@ -422,12 +419,9 @@ static int get_sclk_voltage_dependency_table(PP_ASSERT_WITH_CODE ((0 != tonga_table->ucNumEntries),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) +sizeof (phm_ppt_v1_clock_voltage_dependency_record) - * tonga_table->ucNumEntries; - - sclk_table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == sclk_table) + sclk_table =kzalloc (struct_size (sclk_table, entries, tonga_table->ucNumEntries), +GFP_KERNEL ); +if (!sclk_table)return -ENOMEM ; sclk_table->count = (uint32_t )tonga_table->ucNumEntries;
@@ -454,12 +448,9 @@ static int get_sclk_voltage_dependency_table(PP_ASSERT_WITH_CODE ((0 != polaris_table->ucNumEntries),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) +sizeof (phm_ppt_v1_clock_voltage_dependency_record) - * polaris_table->ucNumEntries; - - sclk_table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == sclk_table) + sclk_table =kzalloc (struct_size (sclk_table, entries, polaris_table->ucNumEntries), +GFP_KERNEL ); +if (!sclk_table)return -ENOMEM ; sclk_table->count = (uint32_t )polaris_table->ucNumEntries;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +15 -35
108 lines not on this page · raw message
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_mm_clock_voltage_dependency_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_ppt_v1_mm_clock_voltage_dependency_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 2 +- .../amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 11 ++++------- .../amd/pm/powerplay/hwmgr/vega10_processpptables.c | 9 +++------ 3 files changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +1 -1
@@ -71,7 +71,7 @@ typedef struct phm_ppt_v1_mm_clock_voltage_dependency_record phm_ppt_v1_mm_clockstruct phm_ppt_v1_mm_clock_voltage_dependency_table {uint32_t count;/* Number of entries. */ -phm_ppt_v1_mm_clock_voltage_dependency_record entries[1 ];/* Dynamically allocate count entries. */ +phm_ppt_v1_mm_clock_voltage_dependency_record entries[];/* Dynamically allocate count entries. */ };typedef struct phm_ppt_v1_mm_clock_voltage_dependency_table phm_ppt_v1_mm_clock_voltage_dependency_table ;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +4 -7
@@ -678,19 +678,16 @@ static int get_mm_clock_voltage_table(const ATOM_Tonga_MM_Dependency_Table * mm_dependency_table ) { -uint32_t table_size, i; +uint32_t i;const ATOM_Tonga_MM_Dependency_Record *mm_dependency_record;phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table;phm_ppt_v1_mm_clock_voltage_dependency_record *mm_table_record;PP_ASSERT_WITH_CODE ((0 != mm_dependency_table->ucNumEntries),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_mm_clock_voltage_dependency_record) - * mm_dependency_table->ucNumEntries; - mm_table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == mm_table) + mm_table =kzalloc (struct_size (mm_table, entries, mm_dependency_table->ucNumEntries), +GFP_KERNEL ); +if (!mm_table)return -ENOMEM ; mm_table->count = mm_dependency_table->ucNumEntries;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +3 -6
@@ -344,18 +344,15 @@ static int get_mm_clock_voltage_table(phm_ppt_v1_mm_clock_voltage_dependency_table **vega10_mm_table, const ATOM_Vega10_MM_Dependency_Table *mm_dependency_table) { - uint32_t table_size, i; + uint32_t i;const ATOM_Vega10_MM_Dependency_Record *mm_dependency_record;phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table;PP_ASSERT_WITH_CODE ((mm_dependency_table->ucNumEntries !=0 ),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_mm_clock_voltage_dependency_record) * - mm_dependency_table->ucNumEntries; - mm_table =kzalloc (table_size,GFP_KERNEL ); - + mm_table =kzalloc (struct_size (mm_table, entries, mm_dependency_table->ucNumEntries), +GFP_KERNEL );if (!mm_table)return -ENOMEM ;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 12/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_voltage_lookup_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_ppt_v1_voltage_lookup_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 2 +- .../drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 10 +++------- .../amd/pm/powerplay/hwmgr/vega10_processpptables.c | 10 +++------- 3 files changed, 7 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +1 -1
@@ -86,7 +86,7 @@ typedef struct phm_ppt_v1_voltage_lookup_record phm_ppt_v1_voltage_lookup_recordstruct phm_ppt_v1_voltage_lookup_table {uint32_t count; -phm_ppt_v1_voltage_lookup_record entries[1 ];/* Dynamically allocate count entries. */ +phm_ppt_v1_voltage_lookup_record entries[];/* Dynamically allocate count entries. */ };typedef struct phm_ppt_v1_voltage_lookup_table phm_ppt_v1_voltage_lookup_table ;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +3 -7
@@ -157,7 +157,7 @@ static int get_vddc_lookup_table(uint32_t max_levels ) { -uint32_t table_size, i; +uint32_t i;phm_ppt_v1_voltage_lookup_table *table;phm_ppt_v1_voltage_lookup_record *record;ATOM_Tonga_Voltage_Lookup_Record *atom_record;
@@ -165,12 +165,8 @@ static int get_vddc_lookup_table(PP_ASSERT_WITH_CODE ((0 != vddc_lookup_pp_tables->ucNumEntries), "Invalid CAC Leakage PowerPlay Table!", return 1); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_voltage_lookup_record) * max_levels; - - table =kzalloc (table_size,GFP_KERNEL ); - -if (NULL == table) + table =kzalloc (struct_size (table, entries, max_levels),GFP_KERNEL ); +if (!table)return -ENOMEM ; table->count = vddc_lookup_pp_tables->ucNumEntries;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +3 -7
@@ -1040,18 +1040,14 @@ static int get_vddc_lookup_table(const ATOM_Vega10_Voltage_Lookup_Table *vddc_lookup_pp_tables, uint32_t max_levels) { - uint32_t table_size, i; + uint32_t i;phm_ppt_v1_voltage_lookup_table *table;PP_ASSERT_WITH_CODE ((vddc_lookup_pp_tables->ucNumEntries !=0 ), "Invalid SOC_VDDD Lookup Table!", return 1); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_voltage_lookup_record) * max_levels; - - table =kzalloc (table_size,GFP_KERNEL ); - -if (table ==NULL ) + table =kzalloc (struct_size (table, entries, max_levels),GFP_KERNEL ); +if (!table)return -ENOMEM ; table->count = vddc_lookup_pp_tables->ucNumEntries;
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 13/14 drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_pcie_table
In reply to Gustavo A. R. SilvaThere 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].
Refactor the code according to the use of a flexible-array member in struct phm_ppt_v1_pcie_table, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 2 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 22 ++++++++----------- .../powerplay/hwmgr/vega10_processpptables.c | 10 +++------ 3 files changed, 13 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +1 -1
@@ -103,7 +103,7 @@ typedef struct phm_ppt_v1_pcie_record phm_ppt_v1_pcie_record;struct phm_ppt_v1_pcie_table {uint32_t count;/* Number of entries. */ -phm_ppt_v1_pcie_record entries[1 ];/* Dynamically allocate count entries. */ +phm_ppt_v1_pcie_record entries[];/* Dynamically allocate count entries. */ };typedef struct phm_ppt_v1_pcie_table phm_ppt_v1_pcie_table ;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +9 -13
@@ -478,7 +478,7 @@ static int get_pcie_table(PPTable_Generic_SubTable_Header const *ptable ) { -uint32_t table_size, i, pcie_count; +uint32_t i, pcie_count;phm_ppt_v1_pcie_table *pcie_table;struct phm_ppt_v1_information *pp_table_information = (struct phm_ppt_v1_information *)(hwmgr->pptable);
@@ -491,12 +491,10 @@ static int get_pcie_table(PP_ASSERT_WITH_CODE ((atom_pcie_table->ucNumEntries !=0 ),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_pcie_record) * atom_pcie_table->ucNumEntries; - - pcie_table =kzalloc (table_size,GFP_KERNEL ); - -if (pcie_table ==NULL ) + pcie_table =kzalloc (struct_size (pcie_table, entries, + atom_pcie_table->ucNumEntries), +GFP_KERNEL ); +if (!pcie_table)return -ENOMEM ;/*
@@ -530,12 +528,10 @@ static int get_pcie_table(PP_ASSERT_WITH_CODE ((atom_pcie_table->ucNumEntries !=0 ),"Invalid PowerPlay Table!" , return -1 ); - table_size =sizeof (uint32_t ) + -sizeof (phm_ppt_v1_pcie_record) * atom_pcie_table->ucNumEntries; - - pcie_table =kzalloc (table_size,GFP_KERNEL ); - -if (pcie_table ==NULL ) + pcie_table =kzalloc (struct_size (pcie_table, entries, + atom_pcie_table->ucNumEntries), +GFP_KERNEL ); +if (!pcie_table)return -ENOMEM ;/*
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +3 -7
@@ -784,7 +784,7 @@ static int get_pcie_table(struct pp_hwmgr *hwmgr,struct phm_ppt_v1_pcie_table **vega10_pcie_table, const Vega10_PPTable_Generic_SubTable_Header *table) { - uint32_t table_size, i, pcie_count; + uint32_t i, pcie_count;struct phm_ppt_v1_pcie_table *pcie_table;struct phm_ppt_v2_information *table_info = (struct phm_ppt_v2_information *)(hwmgr->pptable);
@@ -795,12 +795,8 @@ static int get_pcie_table(struct pp_hwmgr *hwmgr,"Invalid PowerPlay Table!" , return 0); - table_size =sizeof (uint32_t ) + -sizeof (struct phm_ppt_v1_pcie_record ) * - atom_pcie_table->ucNumEntries; - - pcie_table =kzalloc (table_size,GFP_KERNEL ); - + pcie_table =kzalloc (struct_size (pcie_table, entries, atom_pcie_table->ucNumEntries), +GFP_KERNEL );if (!pcie_table)return -ENOMEM ;
Signature · 1 line
2.27.0
PATCH 14/14 drm/amd/pm: Replace one-element array with flexible-array in struct ATOM_Vega10_GFXCLK_Dependency_Table
In reply to Gustavo A. R. SilvaThere 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 a flexible-array member in struct ATOM_Vega10_GFXCLK_Dependency_Table instead of a one-element array.
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +1 -1
@@ -163,7 +163,7 @@ typedef struct _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. */ +ATOM_Vega10_GFXCLK_Dependency_Record entries[];/* Dynamically allocate entries. */ }ATOM_Vega10_GFXCLK_Dependency_Table ; typedef struct _ATOM_Vega10_MCLK_Dependency_Table {
Signature · 6 lines
2.27.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 14/14] drm/amd/pm: Replace one-element array with flexible-array in struct ATOM_Vega10_GFXCLK_Dependency_Table
Quoted 9 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 a flexible-array member in struct
ATOM_Vega10_GFXCLK_Dependency_Tableinstead of a one-element array.
Quoted 6 lines
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
This header is shared with firmware, so I'm leaving it as is for consistency.
Alex
Quoted 20 lines
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +1
-2@@ -163,7 +163,7 @@ typedef struct _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. */ +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
Christian König
maintainerAm 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
Quoted 10 lines
Hi all,
This series aims to replace one-element arrays with flexible-array members.
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].
Quoted 6 lines
Refactor the code according to the use of flexible-array members, instead of one-element arrays, and use the
struct_size()helper to calculate the size for the dynamic memory allocation.Also, save some heap space in the process. More on this on each individual patch.
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König <[email protected]>
I also know about a case where we don't use struct_size in the DMA-buf code.
I'm the maintainer of that stuff as well, so be prepared to get patches thrown at you to clean that up as well.
Thanks,
Christian.
Quoted 54 lines
This series also addresses multiple of the following sorts of warnings:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/smu8_hwmgr.c:1515:37:
warning: array subscript 1 is above array bounds of ‘const struct phm_clock_voltage_dependency_record[1]’ [-Warray-bounds]which, in this case, they are false positives, but nervertheless should be fixed in order to enable -Warray-bounds[3][4].
[1] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFlexible_array_member&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=5LEWyR8pYSxmHsqhHiYiOS%2BPPk%2Fm5suOc6H7f5cIBL4%3D&reserved=0
[2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Fv5.9-rc1%2Fprocess%2Fdeprecated.html%23zero-length-and-one-element-arrays&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=wOqxnNkA9FnOI%2BfB3dHn9RU7cqPJ62qqGCK9gsd2i%2Bo%3D&reserved=0
[3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Flinus%2F44720996e2d79e47d508b0abe99b931a726a3197&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=x%2BSJeOrQA11HXoTaZEdyLyNWL9rC4GngDyoDMRBUn4M%3D&reserved=0
[4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FKSPP%2Flinux%2Fissues%2F109&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=48155uVo7AboCdSZfsTP10i2rHfBJctG%2F432lD%2BpfHo%3D&reserved=0Gustavo A. R. Silva (14):
drm/amd/pm: Replace one-element array with flexible-array member drm/amd/pm: Replace one-element array with flexible-array member in
structvi_dpm_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_clock_array
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_uvd_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_acp_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_phase_shedding_limits_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_vce_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_cac_leakage_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_samu_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_mm_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_voltage_lookup_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_pcie_table
drm/amd/pm: Replace one-element array with flexible-array in struct
ATOM_Vega10_GFXCLK_Dependency_Tabledrivers/gpu/drm/amd/pm/inc/hwmgr.h | 20 ++--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 8 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 85 +++++++----------- .../amd/pm/powerplay/hwmgr/processpptables.c | 85 +++++++----------- .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c | 2 +- .../drm/amd/pm/powerplay/hwmgr/smu_helper.c | 5 +- .../amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- .../powerplay/hwmgr/vega10_processpptables.c | 88 ++++++------------- 8 files changed, 107 insertions(+), 188 deletions(-)
Quoted 18 lines · Christian König
Am 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
Quoted 10 lines
Hi all,
This series aims to replace one-element arrays with flexible-array members.
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].
Quoted 6 lines
Refactor the code according to the use of flexible-array members, instead of one-element arrays, and use the
struct_size()helper to calculate the size for the dynamic memory allocation.Also, save some heap space in the process. More on this on each individual patch.
Quoted 8 lines
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König <[email protected]>
I also know about a case where we don't use
struct_sizein the DMA-buf code.I'm the maintainer of that stuff as well, so be prepared to get patches thrown at you to clean that up as well.
No problem. Feel free to send all of those my way. :)
Thanks
--
Gustavo
Quoted 59 lines
Thanks,
Christian.Quoted 54 lines
This series also addresses multiple of the following sorts of warnings:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/smu8_hwmgr.c:1515:37:
warning: array subscript 1 is above array bounds of ‘const struct phm_clock_voltage_dependency_record[1]’ [-Warray-bounds]which, in this case, they are false positives, but nervertheless should be fixed in order to enable -Warray-bounds[3][4].
[1] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFlexible_array_member&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=5LEWyR8pYSxmHsqhHiYiOS%2BPPk%2Fm5suOc6H7f5cIBL4%3D&reserved=0
[2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Fv5.9-rc1%2Fprocess%2Fdeprecated.html%23zero-length-and-one-element-arrays&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=wOqxnNkA9FnOI%2BfB3dHn9RU7cqPJ62qqGCK9gsd2i%2Bo%3D&reserved=0
[3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Flinus%2F44720996e2d79e47d508b0abe99b931a726a3197&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=x%2BSJeOrQA11HXoTaZEdyLyNWL9rC4GngDyoDMRBUn4M%3D&reserved=0
[4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FKSPP%2Flinux%2Fissues%2F109&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=48155uVo7AboCdSZfsTP10i2rHfBJctG%2F432lD%2BpfHo%3D&reserved=0Gustavo A. R. Silva (14):
drm/amd/pm: Replace one-element array with flexible-array member drm/amd/pm: Replace one-element array with flexible-array member in
structvi_dpm_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_clock_array
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_uvd_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_acp_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_phase_shedding_limits_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_vce_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_cac_leakage_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_samu_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_mm_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_voltage_lookup_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_pcie_table
drm/amd/pm: Replace one-element array with flexible-array in struct
ATOM_Vega10_GFXCLK_Dependency_Tabledrivers/gpu/drm/amd/pm/inc/hwmgr.h | 20 ++--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 8 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 85 +++++++----------- .../amd/pm/powerplay/hwmgr/processpptables.c | 85 +++++++----------- .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c | 2 +- .../drm/amd/pm/powerplay/hwmgr/smu_helper.c | 5 +- .../amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- .../powerplay/hwmgr/vega10_processpptables.c | 88 ++++++------------- 8 files changed, 107 insertions(+), 188 deletions(-)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 16 lines · Christian König
Am 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
Quoted 14 lines
Hi all,
This series aims to replace one-element arrays with flexible-array members.
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].
Refactor the code according to the use of flexible-array members, instead of one-element arrays, and use the
struct_size()helper to calculate the size for the dynamic memory allocation.
Quoted 6 lines
Quoted 2 lines
Also, save some heap space in the process. More on this on each individual patch.
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König <[email protected]>
Applied 1-13. patch 14 is changing a file shared with firmware, so I left it for consistency.
Thanks!
Alex
Quoted 64 lines
I also know about a case where we don't use
struct_sizein the DMA-buf code.I'm the maintainer of that stuff as well, so be prepared to get patches thrown at you to clean that up as well.
Thanks,
Christian.Quoted 44 lines
This series also addresses multiple of the following sorts of warnings:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/smu8_hwmgr.c:1515:37:
warning: array subscript 1 is above array bounds of ‘const struct phm_clock_voltage_dependency_record[1]’ [-Warray-bounds]which, in this case, they are false positives, but nervertheless should be fixed in order to enable -Warray-bounds[3][4].
[1] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFlexible_array_member&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=5LEWyR8pYSxmHsqhHiYiOS%2BPPk%2Fm5suOc6H7f5cIBL4%3D&reserved=0
[2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Fv5.9-rc1%2Fprocess%2Fdeprecated.html%23zero-length-and-one-element-arrays&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=wOqxnNkA9FnOI%2BfB3dHn9RU7cqPJ62qqGCK9gsd2i%2Bo%3D&reserved=0
[3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Flinus%2F44720996e2d79e47d508b0abe99b931a726a3197&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=x%2BSJeOrQA11HXoTaZEdyLyNWL9rC4GngDyoDMRBUn4M%3D&reserved=0
[4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FKSPP%2Flinux%2Fissues%2F109&data=02%7C01%7Cchristian.koenig%40amd.com%7C5312862a3b8c41838ef508d86ad969c1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637376829947099179&sdata=48155uVo7AboCdSZfsTP10i2rHfBJctG%2F432lD%2BpfHo%3D&reserved=0Gustavo A. R. Silva (14):
drm/amd/pm: Replace one-element array with flexible-array member drm/amd/pm: Replace one-element array with flexible-array member in
structvi_dpm_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_clock_array
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_uvd_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_acp_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_phase_shedding_limits_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_vce_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_cac_leakage_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_samu_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_mm_clock_voltage_dependency_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_voltage_lookup_table
drm/amd/pm: Replace one-element array with flexible-array in struct
phm_ppt_v1_pcie_table
drm/amd/pm: Replace one-element array with flexible-array in struct
ATOM_Vega10_GFXCLK_Dependency_TableQuoted 10 lines
drivers/gpu/drm/amd/pm/inc/hwmgr.h | 20 ++--- .../drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h | 8 +- .../powerplay/hwmgr/process_pptables_v1_0.c | 85 +++++++----------- .../amd/pm/powerplay/hwmgr/processpptables.c | 85 +++++++----------- .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c | 2 +- .../drm/amd/pm/powerplay/hwmgr/smu_helper.c | 5 +- .../amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- .../powerplay/hwmgr/vega10_processpptables.c | 88 ++++++------------- 8 files changed, 107 insertions(+), 188 deletions(-)
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