From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: "David Airlie" <airlied@linux.ie>,
dri-devel@lists.freedesktop.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
amd-gfx@lists.freedesktop.org, linux-hardening@vger.kernel.org,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>
Subject: [PATCH 10/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_clock_voltage_dependency_table
Date: Wed, 7 Oct 2020 11:08:53 -0500 [thread overview]
Message-ID: <3954508c123dabe1076af7651f220dc8696e5710.1602020074.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1602020074.git.gustavoars@kernel.org>
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-and-one-element-arrays
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;
--
2.27.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-10-07 16:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 16:01 [PATCH 00/14] drm/amd/pm: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2020-10-07 16:02 ` [PATCH 01/14] drm/amd/pm: Replace one-element array with flexible-array member Gustavo A. R. Silva
2020-10-07 16:03 ` [PATCH 02/14] drm/amd/pm: Replace one-element array with flexible-array member in struct vi_dpm_table Gustavo A. R. Silva
2020-10-07 16:04 ` [PATCH 03/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_clock_array Gustavo A. R. Silva
2020-10-07 16:04 ` [PATCH 04/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_uvd_clock_voltage_dependency_table Gustavo A. R. Silva
2020-10-07 16:05 ` [PATCH 05/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_acp_clock_voltage_dependency_table Gustavo A. R. Silva
2020-10-07 16:06 ` [PATCH 06/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_phase_shedding_limits_table Gustavo A. R. Silva
2020-10-07 16:06 ` [PATCH 07/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_vce_clock_voltage_dependency_table Gustavo A. R. Silva
2020-10-07 16:07 ` [PATCH 08/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_cac_leakage_table Gustavo A. R. Silva
2020-10-07 16:08 ` [PATCH 09/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_samu_clock_voltage_dependency_table Gustavo A. R. Silva
2020-10-07 16:08 ` Gustavo A. R. Silva [this message]
2020-10-07 16:09 ` [PATCH 11/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_mm_clock_voltage_dependency_table Gustavo A. R. Silva
2020-10-07 16:10 ` [PATCH 12/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_voltage_lookup_table Gustavo A. R. Silva
2020-10-07 16:10 ` [PATCH 13/14] drm/amd/pm: Replace one-element array with flexible-array in struct phm_ppt_v1_pcie_table Gustavo A. R. Silva
2020-10-07 16:11 ` [PATCH 14/14] drm/amd/pm: Replace one-element array with flexible-array in struct ATOM_Vega10_GFXCLK_Dependency_Table Gustavo A. R. Silva
2020-10-08 15:46 ` Alex Deucher
2020-10-08 7:19 ` [PATCH 00/14] drm/amd/pm: Replace one-element arrays with flexible-array members Christian König
2020-10-08 13:20 ` Gustavo A. R. Silva
2020-10-08 15:53 ` Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3954508c123dabe1076af7651f220dc8696e5710.1602020074.git.gustavoars@kernel.org \
--to=gustavoars@kernel.org \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).