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... [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(-)
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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c295c.8iqp1Ifc6oiVDq%2F%2F%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index 3898a95ec28b..a1dbfd5636e6 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index 719597c5d27d..d94a7d8e0587 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c index 35ed47ebaf09..ed9b89980184 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c @@ -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) { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c index 60b5ca974356..b485f8b1d6f2 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c @@ -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");
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 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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c433c.TTk9rnA+F58kyDUy%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index a1dbfd5636e6..d68b547743e6 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c433f.ZyMD+YUIVAwiHGVe%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index d68b547743e6..e84cff09af2d 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c index b760f95e7fa7..52188f6cd150 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c @@ -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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index d94a7d8e0587..d9bed4df6f65 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c index f29af5ca0aa0..e655c04ccdfb 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c433e.pXkC6KsN6HN%2FLdhj%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index e84cff09af2d..2f1886bc5535 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index d9bed4df6f65..305d95c4162d 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c5d3c.TyfOhg%2FA6JycL6ZN%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index 2f1886bc5535..361cb1125351 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index 305d95c4162d..a1b198045978 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c5d36.6PStUZp2HRxAz7IM%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index 361cb1125351..ad614e32079e 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index a1b198045978..b2ef76580c6a 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c5d35.pJToGs3H9khZK6ws%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index ad614e32079e..b8e33325fac6 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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[]; };
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index b2ef76580c6a..7719f52e6d52 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c5d38.iT%2FQTjN+659XUDo5%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- drivers/gpu/drm/amd/pm/inc/hwmgr.h | 2 +- .../drm/amd/pm/powerplay/hwmgr/processpptables.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index b8e33325fac6..7e0c948a7097 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index 7719f52e6d52..e059802d1e25 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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 by sizeof(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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7c5d3a.ryM4GmZr3e0JeZy+%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/inc/hwmgr.h b/drivers/gpu/drm/amd/pm/inc/hwmgr.h index 7e0c948a7097..dad703ba0522 100644 --- a/drivers/gpu/drm/amd/pm/inc/hwmgr.h +++ b/drivers/gpu/drm/amd/pm/inc/hwmgr.h @@ -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 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c index e059802d1e25..48d550d26c6a 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- .../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(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h index c0193e09d58a..c167083b0872 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h @@ -48,7 +48,7 @@ typedef struct phm_ppt_v1_clock_voltage_dependency_record phm_ppt_v1_clock_volta
struct 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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c index 52188f6cd150..0725531fbfff 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c @@ -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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c index e655c04ccdfb..787b23fa25e7 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c @@ -571,18 +571,14 @@ static int get_socclk_voltage_dependency_table( phm_ppt_v1_clock_voltage_dependency_table **pp_vega10_clk_dep_table, const ATOM_Vega10_SOCCLK_Dependency_Table *clk_dep_table) { - uint32_t table_size, i; + uint32_t i; phm_ppt_v1_clock_voltage_dependency_table *clk_table;
PP_ASSERT_WITH_CODE(clk_dep_table->ucNumEntries, "Invalid PowerPlay Table!", return -1);
- table_size = sizeof(uint32_t) + - sizeof(phm_ppt_v1_clock_voltage_dependency_record) * - clk_dep_table->ucNumEntries; - - clk_table = kzalloc(table_size, GFP_KERNEL); - + clk_table = kzalloc(struct_size(clk_table, entries, clk_dep_table->ucNumEntries), + GFP_KERNEL); if (!clk_table) return -ENOMEM;
@@ -605,18 +601,14 @@ static int get_mclk_voltage_dependency_table( phm_ppt_v1_clock_voltage_dependency_table **pp_vega10_mclk_dep_table, const ATOM_Vega10_MCLK_Dependency_Table *mclk_dep_table) { - uint32_t table_size, i; + uint32_t i; phm_ppt_v1_clock_voltage_dependency_table *mclk_table;
PP_ASSERT_WITH_CODE(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); - + mclk_table = kzalloc(struct_size(mclk_table, entries, mclk_dep_table->ucNumEntries), + GFP_KERNEL); if (!mclk_table) return -ENOMEM;
@@ -644,7 +636,7 @@ static int get_gfxclk_voltage_dependency_table( **pp_vega10_clk_dep_table, const ATOM_Vega10_GFXCLK_Dependency_Table *clk_dep_table) { - uint32_t table_size, i; + uint32_t i; struct phm_ppt_v1_clock_voltage_dependency_table *clk_table; ATOM_Vega10_GFXCLK_Dependency_Record_V2 *patom_record_v2; @@ -652,12 +644,8 @@ static int get_gfxclk_voltage_dependency_table( PP_ASSERT_WITH_CODE((clk_dep_table->ucNumEntries != 0), "Invalid PowerPlay Table!", return -1);
- table_size = sizeof(uint32_t) + - sizeof(phm_ppt_v1_clock_voltage_dependency_record) * - clk_dep_table->ucNumEntries; - - clk_table = kzalloc(table_size, GFP_KERNEL); - + clk_table = kzalloc(struct_size(clk_table, entries, clk_dep_table->ucNumEntries), + GFP_KERNEL); if (!clk_table) return -ENOMEM;
@@ -711,19 +699,15 @@ static int get_pix_clk_voltage_dependency_table( **pp_vega10_clk_dep_table, const ATOM_Vega10_PIXCLK_Dependency_Table *clk_dep_table) { - uint32_t table_size, i; + uint32_t i; struct phm_ppt_v1_clock_voltage_dependency_table *clk_table;
PP_ASSERT_WITH_CODE((clk_dep_table->ucNumEntries != 0), "Invalid PowerPlay Table!", return -1);
- table_size = sizeof(uint32_t) + - sizeof(phm_ppt_v1_clock_voltage_dependency_record) * - clk_dep_table->ucNumEntries; - - clk_table = kzalloc(table_size, GFP_KERNEL); - + clk_table = kzalloc(struct_size(clk_table, entries, clk_dep_table->ucNumEntries), + GFP_KERNEL); if (!clk_table) return -ENOMEM;
@@ -747,7 +731,7 @@ static int get_dcefclk_voltage_dependency_table( **pp_vega10_clk_dep_table, const ATOM_Vega10_DCEFCLK_Dependency_Table *clk_dep_table) { - uint32_t table_size, i; + uint32_t i; uint8_t num_entries; struct phm_ppt_v1_clock_voltage_dependency_table *clk_table; @@ -775,12 +759,8 @@ static int get_dcefclk_voltage_dependency_table( num_entries = clk_dep_table->ucNumEntries;
- table_size = sizeof(uint32_t) + - sizeof(phm_ppt_v1_clock_voltage_dependency_record) * - num_entries; - - clk_table = kzalloc(table_size, GFP_KERNEL); - + clk_table = kzalloc(struct_size(clk_table, entries, num_entries), + GFP_KERNEL); if (!clk_table) return -ENOMEM;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7d61e2.qiTVTyG2pVoG8bb0%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h index c167083b0872..923cc04e405a 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h @@ -71,7 +71,7 @@ typedef struct phm_ppt_v1_mm_clock_voltage_dependency_record phm_ppt_v1_mm_clock
struct 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;
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c index 0725531fbfff..5d8016cd1986 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c @@ -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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c index 787b23fa25e7..4f6a73a2cf28 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7d61df.jWrFfnjxGbjSkPOp%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- 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(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h index 923cc04e405a..e11298cdeb30 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h @@ -86,7 +86,7 @@ typedef struct phm_ppt_v1_voltage_lookup_record phm_ppt_v1_voltage_lookup_record
struct 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;
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c index 5d8016cd1986..426655b9c678 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c @@ -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; diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c index 4f6a73a2cf28..3d7f915381c8 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7db0bc.7Xivn4K83f7XW0ug%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- .../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(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h index e11298cdeb30..729615aff126 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/hwmgr_ppt.h @@ -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;
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c index 426655b9c678..4fa58614e26a 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c @@ -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;
/* diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c index 3d7f915381c8..535404de78a2 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_processpptables.c @@ -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;
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7d61dd.O8jxxI5C6P9FOb%2Fd%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org --- drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h index c934e9612c1b..a6968009acc4 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h @@ -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 {
On Wed, Oct 7, 2020 at 12:05 PM Gustavo A. R. Silva gustavoars@kernel.org wrote:
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_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...
Build-tested-by: kernel test robot lkp@intel.com Link: https://lore.kernel.org/lkml/5f7d61dd.O8jxxI5C6P9FOb%2Fd%25lkp@intel.com/ Signed-off-by: Gustavo A. R. Silva gustavoars@kernel.org
This header is shared with firmware, so I'm leaving it as is for consistency.
Alex
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h index c934e9612c1b..a6968009acc4 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_pptable.h @@ -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
amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
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.
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König christian.koenig@amd.com
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.
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.wikiped... [2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel... [3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel... [4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com...
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(-)
On Thu, Oct 08, 2020 at 09:19:47AM +0200, Christian König wrote:
Am 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
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.
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König christian.koenig@amd.com
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.
No problem. Feel free to send all of those my way. :)
Thanks -- Gustavo
Thanks, Christian.
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.wikiped... [2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel... [3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel... [4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com...
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(-)
On Thu, Oct 8, 2020 at 3:20 AM Christian König christian.koenig@amd.com wrote:
Am 07.10.20 um 18:01 schrieb Gustavo A. R. Silva:
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.
Ah! Nice to see that finally be documented and cleaned up.
Feel free to add an Acked-by: Christian König christian.koenig@amd.com
Applied 1-13. patch 14 is changing a file shared with firmware, so I left it for consistency.
Thanks!
Alex
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.
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.wikiped... [2] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel... [3] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel... [4] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com...
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(-)
amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
dri-devel@lists.freedesktop.org