Skip to contentSkip to conversation

drm/amdgpu: Fail when setting negative DPM levels v2

PATCH In review Kent Russell 3 participants 3 messages Mar 2, 2018 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Fail when setting negative DPM levels v2

kstrtol can handle negative values, which is unchecked here. While setting a negative value will result in the mask being 1<<0xffffffff , which the SMU will ignore because it's out of long bits, return an error instead of silently failing.

v2 Add similar check for sclk_od and mclk_od

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5 -5
index 9e73cbc..5bdb421 100644
@@ -476,7 +476,7 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
 		}
@@ -522,7 +522,7 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
 		}
@@ -567,7 +567,7 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
 		}
@@ -606,7 +606,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
 
 	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
 		count = -EINVAL;
 		goto fail;
 	}
@@ -650,7 +650,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
 
 	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
 		count = -EINVAL;
 		goto fail;
 	}
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1520013187-24300-1-git-send-email-kent.russell-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#2 lore raw
Quoted 53 lines · Kent Russell

kstrtol can handle negative values, which is unchecked here. While setting a negative value will result in the mask being 1<<0xffffffff , which the SMU will ignore because it's out of long bits, return an error instead of silently failing.

v2 Add similar check for sclk_od and mclk_od

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +4 -4
index 9e73cbc..5bdb421 100644
@@ -476,7 +476,7 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
  		sub_str[1] = '\0';
  		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
  			count = -EINVAL;
  			goto fail;
  		}
@@ -522,7 +522,7 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
  		sub_str[1] = '\0';
  		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
  			count = -EINVAL;
  			goto fail;
  		}
@@ -567,7 +567,7 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
  		sub_str[1] = '\0';
  		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
  			count = -EINVAL;
  			goto fail;
  		}
@@ -606,7 +606,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
 
  	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
  		count = -EINVAL;
  		goto fail;
  	}

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct device *dev, · line 656

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
@@ -650,7 +650,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
 
  	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
  		count = -EINVAL;
  		goto fail;
  	}

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by Alex Deucher
#3 lore raw
In reply to a message not in the archive
Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Kent Russell
Sent: Friday, March 2, 2018 12:53 PM
To: [email protected]
Cc: Russell, Kent <[email protected]>
Subject: [PATCH] drm/amdgpu: Fail when setting negative DPM levels v2

Quoted 7 lines

kstrtol can handle negative values, which is unchecked here. While setting a negative value will result in the mask being 1<<0xffffffff , which the SMU will ignore because it's out of long bits, return an error instead of silently failing.

v2 Add similar check for sclk_od and mclk_od

Quoted 62 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
index 9e73cbc..5bdb421 100644
@@ -476,7 +476,7 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct
 device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
 		}
@@ -522,7 +522,7 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct
 device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
 		}
@@ -567,7 +567,7 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct
 device *dev,
 		sub_str[1] = '\0';
 		ret = kstrtol(sub_str, 0, &level);
 
-		if (ret) {
+		if (ret || level < 0) {
 			count = -EINVAL;
 			goto fail;
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
 		}
@@ -606,7 +606,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device
 *dev,
 
 	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
 		count = -EINVAL;
 		goto fail;
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
 	}
@@ -650,7 +650,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device
 *dev,
 
 	ret = kstrtol(buf, 0, &value);
 
-	if (ret) {
+	if (ret || value < 0) {
 		count = -EINVAL;
 		goto fail;

}
--
2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx