Skip to contentSkip to conversation

drm/amd/pm: Avoid overflow when sorting pp_feature list

PATCH In review Asad Kamal 3 participants 5 messages Mar 2

Subsystems (3)
lore
Share & tools
lore

Asad Kamal

author
#0 lore raw

PATCH 1/1 drm/amd/pm: Avoid overflow when sorting pp_feature list

pp_features sorting uses int8_t sort_feature[] to store driver feature enum indices. On newer ASICs the enum index can exceed 127, causing signed overflow and silently dropping entries from the output. Switch the array to int16_t so all enum indices are preserved.

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index c471c0e2cbd1..326c86b920a2 100644
@@ -880,7 +880,7 @@ static const char *smu_get_feature_name(struct smu_context *smu,
 size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
 				   char *buf)
 {
-	int8_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
+	int16_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
 	struct smu_feature_bits feature_mask;
 	uint32_t features[2];
 	int i, feature_index;
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Asad Kamal

pp_features sorting uses int8_t sort_feature[] to store driver feature enum indices. On newer ASICs the enum index can exceed 127, causing signed overflow and silently dropping entries from the output. Switch the array to int16_t so all enum indices are preserved.

Thanks,
Lijo

Quoted 17 lines
---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index c471c0e2cbd1..326c86b920a2 100644
@@ -880,7 +880,7 @@ static const char *smu_get_feature_name(struct smu_context *smu,
  size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
  				   char *buf)
  {
-	int8_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
+	int16_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
  	struct smu_feature_bits feature_mask;
  	uint32_t features[2];
  	int i, feature_index;
Reviewed-by Lijo Lazar
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 1 line
Quoted 1 line

memset(sort_feature, -1, sizeof(sort_feature));

...

Quoted 1 line
Quoted 1 line

if (sort_feature[feature_index] < 0)

      continue;

When the array type is changed from int8_t to int16_t, the code logic of this memset() may not correctly initialize all elements to '-1'. Please modify this code together to ensure that the subsequent code logic meets expectations.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 2, 2026 2:23 PM
To: Kamal, Asad <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

Quoted 6 lines · Asad Kamal

pp_features sorting uses int8_t sort_feature[] to store driver feature enum indices. On newer ASICs the enum index can exceed 127, causing signed overflow and silently dropping entries from the output. Switch the array to int16_t so all enum indices are preserved.

Thanks,
Lijo

Quoted 18 lines
---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index c471c0e2cbd1..326c86b920a2 100644
@@ -880,7 +880,7 @@ static const char *smu_get_feature_name(struct smu_context *smu,
  size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
                                 char *buf)
  {
-     int8_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
+     int16_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
      struct smu_feature_bits feature_mask;
      uint32_t features[2];
      int i, feature_index;
author Reviewed-by Lijo Lazar
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-1 in memset fills all bytes with 0xFF. For int16_t, that becomes 0xFFFF, which is -1 in two’s‑complement. So the < 0 check still works as intended.

Regards
Asad

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Monday, March 2, 2026 11:59 AM
To: Lazar, Lijo <[email protected]>; Kamal, Asad <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 1 line
Quoted 1 line

memset(sort_feature, -1, sizeof(sort_feature));

...

Quoted 1 line
Quoted 1 line

if (sort_feature[feature_index] < 0)

      continue;

When the array type is changed from int8_t to int16_t, the code logic of this memset() may not correctly initialize all elements to '-1'. Please modify this code together to ensure that the subsequent code logic meets expectations.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 2, 2026 2:23 PM
To: Kamal, Asad <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

Quoted 6 lines · Asad Kamal

pp_features sorting uses int8_t sort_feature[] to store driver feature enum indices. On newer ASICs the enum index can exceed 127, causing signed overflow and silently dropping entries from the output. Switch the array to int16_t so all enum indices are preserved.

Thanks,
Lijo

Quoted 18 lines
---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index c471c0e2cbd1..326c86b920a2 100644
@@ -880,7 +880,7 @@ static const char *smu_get_feature_name(struct smu_context *smu,
  size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
                                 char *buf)
  {
-     int8_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
+     int16_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
      struct smu_feature_bits feature_mask;
      uint32_t features[2];
      int i, feature_index;
Reviewed-by Lijo Lazar
#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Based on private discussions, please continue to submit the code.

Best Regards,
Kevin

-----Original Message-----
From: Kamal, Asad <[email protected]>
Sent: Monday, March 2, 2026 2:34 PM
To: Wang, Yang(Kevin) <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

[AMD Official Use Only - AMD Internal Distribution Only]

-1 in memset fills all bytes with 0xFF. For int16_t, that becomes 0xFFFF, which is -1 in two’s‑complement. So the < 0 check still works as intended.

Regards
Asad

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Monday, March 2, 2026 11:59 AM
To: Lazar, Lijo <[email protected]>; Kamal, Asad <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 1 line
Quoted 1 line

memset(sort_feature, -1, sizeof(sort_feature));

...

Quoted 1 line
Quoted 1 line

if (sort_feature[feature_index] < 0)

      continue;

When the array type is changed from int8_t to int16_t, the code logic of this memset() may not correctly initialize all elements to '-1'. Please modify this code together to ensure that the subsequent code logic meets expectations.

Best Regards,
Kevin

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 2, 2026 2:23 PM
To: Kamal, Asad <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Ma, Le <[email protected]>; Zhang, Morris <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: Avoid overflow when sorting pp_feature list

Quoted 6 lines · Asad Kamal

pp_features sorting uses int8_t sort_feature[] to store driver feature enum indices. On newer ASICs the enum index can exceed 127, causing signed overflow and silently dropping entries from the output. Switch the array to int16_t so all enum indices are preserved.

Thanks,
Lijo

Quoted 18 lines
---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -1
index c471c0e2cbd1..326c86b920a2 100644
@@ -880,7 +880,7 @@ static const char *smu_get_feature_name(struct smu_context *smu,
  size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
                                 char *buf)
  {
-     int8_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
+     int16_t sort_feature[MAX(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)];
      struct smu_feature_bits feature_mask;
      uint32_t features[2];
      int i, feature_index;