dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu/pm/powerplay: factor voltage index bounds check into a macro
@ 2026-09-23  5:41 yaolu
  2026-09-23  5:46 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: yaolu @ 2026-09-23  5:41 UTC (permalink / raw)
  To: kenneth.feng, alexander.deucher, christian.koenig
  Cc: asad.kamal, amd-gfx, dri-devel, linux-kernel, Lu Yao

From: Lu Yao <yaolu@kylinos.cn>

commit 3a8a05477cda ("drm/amdgpu/pm/powerplay: bounds-check voltage index in SMU7 lookup") and
commit 6fa33f594e46 ("drm/amdgpu/pm/powerplay: bounds-check voltage index in Vega10 lookup")
added the same block.

Move the pattern into PP_CHECK_VOLTAGE_INDEX().

Signed-off-by: Lu Yao <yaolu@kylinos.cn>
---
 .../drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c   | 28 +++++----------
 .../drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 35 ++++++-------------
 .../gpu/drm/amd/pm/powerplay/inc/pp_debug.h   | 12 +++++++
 3 files changed, 30 insertions(+), 45 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
index bdf1e489369e..aafb52bf94ff 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
@@ -2216,24 +2216,18 @@ static int smu7_patch_voltage_dependency_tables_with_lookup_table(
 	if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
 		for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
 			voltage_id = sclk_table->entries[entry_id].vddInd;
-			if (voltage_id >= table_info->vddgfx_lookup_table->count) {
-				pr_err("amdgpu: sclk[%u] vddgfx index %u out of bounds (%u)\n",
-				       entry_id, voltage_id,
-				       table_info->vddgfx_lookup_table->count);
+			if (PP_VOLTAGE_INDEX_OOB(table_info->vddgfx_lookup_table, voltage_id,
+						 "sclk[%u] vddgfx", entry_id))
 				return -EINVAL;
-			}
 			sclk_table->entries[entry_id].vddgfx =
 				table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
 		}
 	} else {
 		for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
 			voltage_id = sclk_table->entries[entry_id].vddInd;
-			if (voltage_id >= table_info->vddc_lookup_table->count) {
-				pr_err("amdgpu: sclk[%u] vddc index %u out of bounds (%u)\n",
-				       entry_id, voltage_id,
-				       table_info->vddc_lookup_table->count);
+			if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+						 "sclk[%u] vddc", entry_id))
 				return -EINVAL;
-			}
 			sclk_table->entries[entry_id].vddc =
 				table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 		}
@@ -2241,24 +2235,18 @@ static int smu7_patch_voltage_dependency_tables_with_lookup_table(
 
 	for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
 		voltage_id = mclk_table->entries[entry_id].vddInd;
-		if (voltage_id >= table_info->vddc_lookup_table->count) {
-			pr_err("amdgpu: mclk[%u] vddc index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddc_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+					 "mclk[%u] vddc", entry_id))
 			return -EINVAL;
-		}
 		mclk_table->entries[entry_id].vddc =
 			table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 	}
 
 	for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
 		voltage_id = mm_table->entries[entry_id].vddcInd;
-		if (voltage_id >= table_info->vddc_lookup_table->count) {
-			pr_err("amdgpu: mm[%u] vddc index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddc_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+					 "mm[%u] vddc", entry_id))
 			return -EINVAL;
-		}
 		mm_table->entries[entry_id].vddc =
 			table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 	}
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
index 05b1e69116fd..96783710afe3 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
@@ -691,12 +691,9 @@ static int vega10_patch_voltage_dependency_tables_with_lookup_table(
 
 		for (entry_id = 0; entry_id < vdt->count; entry_id++) {
 			voltage_id = vdt->entries[entry_id].vddInd;
-			if (voltage_id >= table_info->vddc_lookup_table->count) {
-				pr_err("amdgpu: clk_dep[%u][%u] vddc index %u out of bounds (%u)\n",
-				       i, entry_id, voltage_id,
-				       table_info->vddc_lookup_table->count);
+			if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+						 "clk_dep[%u][%u] vddc", i, entry_id))
 				return -EINVAL;
-			}
 			vdt->entries[entry_id].vddc =
 					table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 		}
@@ -704,44 +701,32 @@ static int vega10_patch_voltage_dependency_tables_with_lookup_table(
 
 	for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
 		voltage_id = mm_table->entries[entry_id].vddcInd;
-		if (voltage_id >= table_info->vddc_lookup_table->count) {
-			pr_err("amdgpu: mm[%u] vddc index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddc_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+					 "mm[%u] vddc", entry_id))
 			return -EINVAL;
-		}
 		mm_table->entries[entry_id].vddc =
 			table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 	}
 
 	for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
 		voltage_id = mclk_table->entries[entry_id].vddInd;
-		if (voltage_id >= table_info->vddc_lookup_table->count) {
-			pr_err("amdgpu: mclk[%u] vddc index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddc_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddc_lookup_table, voltage_id,
+					 "mclk[%u] vddc", entry_id))
 			return -EINVAL;
-		}
 		mclk_table->entries[entry_id].vddc =
 				table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
 
 		voltage_id = mclk_table->entries[entry_id].vddciInd;
-		if (voltage_id >= table_info->vddci_lookup_table->count) {
-			pr_err("amdgpu: mclk[%u] vddci index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddci_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddci_lookup_table, voltage_id,
+					 "mclk[%u] vddci", entry_id))
 			return -EINVAL;
-		}
 		mclk_table->entries[entry_id].vddci =
 				table_info->vddci_lookup_table->entries[voltage_id].us_vdd;
 
 		voltage_id = mclk_table->entries[entry_id].mvddInd;
-		if (voltage_id >= table_info->vddmem_lookup_table->count) {
-			pr_err("amdgpu: mclk[%u] vddmem index %u out of bounds (%u)\n",
-			       entry_id, voltage_id,
-			       table_info->vddmem_lookup_table->count);
+		if (PP_VOLTAGE_INDEX_OOB(table_info->vddmem_lookup_table, voltage_id,
+					 "mclk[%u] vddmem", entry_id))
 			return -EINVAL;
-		}
 		mclk_table->entries[entry_id].mvdd =
 				table_info->vddmem_lookup_table->entries[voltage_id].us_vdd;
 	}
diff --git a/drivers/gpu/drm/amd/pm/powerplay/inc/pp_debug.h b/drivers/gpu/drm/amd/pm/powerplay/inc/pp_debug.h
index cea65093b6ad..efe5f6df8c9b 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/inc/pp_debug.h
+++ b/drivers/gpu/drm/amd/pm/powerplay/inc/pp_debug.h
@@ -54,6 +54,18 @@
 		pr_debug(fmt, ##__VA_ARGS__); \
 	} while (0)
 
+/* Reports and returns true when index does not fit into the lookup table. */
+#define PP_VOLTAGE_INDEX_OOB(lookup_table, index, fmt, ...)		\
+({									\
+	typeof(lookup_table) __lookup = (lookup_table);			\
+	typeof(index) __idx = (index);					\
+	bool __oob = __idx >= __lookup->count;				\
+									\
+	if (__oob)							\
+		pr_err(fmt " index %u out of bounds (%u)\n",		\
+		       ##__VA_ARGS__, __idx, __lookup->count);		\
+	__oob;								\
+})
 
 #define GET_FLEXIBLE_ARRAY_MEMBER_ADDR(type, member, ptr, n)	\
 	(type *)((char *)&(ptr)->member + (sizeof(type) * (n)))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu/pm/powerplay: factor voltage index bounds check into a macro
  2026-09-23  5:41 [PATCH] drm/amdgpu/pm/powerplay: factor voltage index bounds check into a macro yaolu
@ 2026-09-23  5:46 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-23  5:46 UTC (permalink / raw)
  To: yaolu; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] commit message: macro name mismatch PP_CHECK_VOLTAGE_INDEX vs PP_VOLTAGE_INDEX_OOB
--

commit 3d5448c38d3504f9987ca03ae0f6fc0dcde24233
Author: Lu Yao <yaolu@kylinos.cn>

drm/amdgpu/pm/powerplay: factor voltage index bounds check into a macro

This commit refactors duplicate voltage index bounds checking from SMU7 and
Vega10 implementations into a common macro.

>     Move the pattern into PP_CHECK_VOLTAGE_INDEX().

[Severity: Low]
This isn't a bug, but the commit message mentions moving the pattern into
PP_CHECK_VOLTAGE_INDEX(), while the code actually defines the macro as
PP_VOLTAGE_INDEX_OOB in drivers/gpu/drm/amd/pm/powerplay/inc/pp_debug.h at
line 58. Could the commit message be updated to reflect the actual macro
name?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923054111.209370-1-yaolu@kylinos.cn?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-23  5:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23  5:41 [PATCH] drm/amdgpu/pm/powerplay: factor voltage index bounds check into a macro yaolu
2026-09-23  5:46 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox