Skip to contentSkip to conversation

drm/amd/pm: Validate custom profile parameters

PATCH In review Lijo Lazar 2 participants 2 messages May 29

Subsystems (3)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amd/pm: Validate custom profile parameters

Add helpers to validate custom profile params against negative/out-of-range values. Use the helpers to validate user passed params.

Assisted-by Claude Sonnet (Cursor AI)
---
 drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c      |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c        |  7 ++++---
 .../gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c    |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h                 | 10 ++++++++++
 7 files changed, 34 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +4 -3
index d73c3c191e9c..051a0008aa10 100644
@@ -1467,9 +1467,10 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != ARCTURUS_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       ARCTURUS_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * ARCTURUS_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -3
index f2ce8de58cb9..2f2a5953dbbc 100644
@@ -1845,9 +1845,10 @@ static int navi10_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != NAVI10_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       NAVI10_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * NAVI10_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +4 -3
index 68255cfcb04d..70897c70db32 100644
@@ -1756,9 +1756,10 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != SIENNA_CICHLID_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       SIENNA_CICHLID_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * SIENNA_CICHLID_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -3
index fa91837f7024..d7792616e4b9 100644
@@ -2734,9 +2734,10 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != SMU_13_0_0_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       SMU_13_0_0_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * SMU_13_0_0_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -3
index 25f977a42a1c..ce83e299a66a 100644
@@ -2690,9 +2690,10 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != SMU_13_0_7_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       SMU_13_0_7_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * SMU_13_0_7_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +4 -3
index 6b5aa4e514fd..933873de7850 100644
@@ -1829,9 +1829,10 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
 				return -ENOMEM;
 		}
 		if (custom_params && custom_params_max_idx) {
-			if (custom_params_max_idx != SMU_14_0_2_CUSTOM_PARAMS_COUNT)
-				return -EINVAL;
-			if (custom_params[0] >= SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT)
+			if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+							       SMU_14_0_2_CUSTOM_PARAMS_COUNT) ||
+			    !smu_cmn_custom_params_clock_valid(custom_params[0],
+							       SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT))
 				return -EINVAL;
 			idx = custom_params[0] * SMU_14_0_2_CUSTOM_PARAMS_COUNT;
 			smu->custom_profile_params[idx] = 1;
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h +10 -0
index 0e119965ce13..5b7f64b94179 100644
@@ -113,6 +113,16 @@ static inline int pcie_gen_to_speed(uint32_t gen)
 	return ((gen == 0) ? link_speed[0] : link_speed[gen - 1]);
 }
 
+static inline bool smu_cmn_custom_params_count_valid(u32 max_idx, u32 params_count)
+{
+	return max_idx == params_count;
+}
+
+static inline bool smu_cmn_custom_params_clock_valid(long clock_idx, long clock_count)
+{
+	return clock_idx >= 0 && clock_idx < clock_count;
+}
+
 int smu_cmn_send_smc_msg_with_param(struct smu_context *smu,
 				    enum smu_message_type msg,
 				    uint32_t param,
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw

AMD General

Regards,
Hawking
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, May 29, 2026 5:44 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Kamal, Asad <[email protected]>; Wang, Yang(Kevin) <[email protected]>
Subject: [PATCH] drm/amd/pm: Validate custom profile parameters

Add helpers to validate custom profile params against negative/out-of-range values. Use the helpers to validate user passed params.

Assisted-by Claude Sonnet (Cursor AI)
---
 drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c      |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c        |  7 ++++---
 .../gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c    |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c   |  7 ++++---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h                 | 10 ++++++++++
 7 files changed, 34 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +4 -3
index d73c3c191e9c..051a0008aa10 100644
@@ -1467,9 +1467,10 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != ARCTURUS_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              ARCTURUS_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * ARCTURUS_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c

index f2ce8de58cb9..2f2a5953dbbc 100644

drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -3
@@ -1845,9 +1845,10 @@ static int navi10_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != NAVI10_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              NAVI10_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * NAVI10_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

index 68255cfcb04d..70897c70db32 100644

drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +4 -3
@@ -1756,9 +1756,10 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != SIENNA_CICHLID_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              SIENNA_CICHLID_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * SIENNA_CICHLID_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

index fa91837f7024..d7792616e4b9 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -3
@@ -2734,9 +2734,10 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != SMU_13_0_0_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              SMU_13_0_0_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * SMU_13_0_0_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

index 25f977a42a1c..ce83e299a66a 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -3
@@ -2690,9 +2690,10 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != SMU_13_0_7_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              SMU_13_0_7_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * SMU_13_0_7_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c

index 6b5aa4e514fd..933873de7850 100644

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +4 -3
@@ -1829,9 +1829,10 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
                                return -ENOMEM;
                }
                if (custom_params && custom_params_max_idx) {
-                       if (custom_params_max_idx != SMU_14_0_2_CUSTOM_PARAMS_COUNT)
-                               return -EINVAL;
-                       if (custom_params[0] >= SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT)
+                       if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
+                                                              SMU_14_0_2_CUSTOM_PARAMS_COUNT) ||
+                           !smu_cmn_custom_params_clock_valid(custom_params[0],
+                                                              SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT))
                                return -EINVAL;
                        idx = custom_params[0] * SMU_14_0_2_CUSTOM_PARAMS_COUNT;
                        smu->custom_profile_params[idx] = 1; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h

index 0e119965ce13..5b7f64b94179 100644

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h +9 -1
@@ -113,6 +113,16 @@ static inline int pcie_gen_to_speed(uint32_t gen)
        return ((gen == 0) ? link_speed[0] : link_speed[gen - 1]);  }
 
+static inline bool smu_cmn_custom_params_count_valid(u32 max_idx, u32
+params_count) {
+       return max_idx == params_count;
+}
+
+static inline bool smu_cmn_custom_params_clock_valid(long clock_idx,
+long clock_count) {
+       return clock_idx >= 0 && clock_idx < clock_count; }
+
 int smu_cmn_send_smc_msg_with_param(struct smu_context *smu,
                                    enum smu_message_type msg,
                                    uint32_t param,
--

2.49.0