Skip to content

Commit 68bf8b5

Browse files
karolherbstBen Skeggs
authored andcommitted
drm/nouveau/hwmon: return EINVAL if the GPU is powered down for sensors reads
fixes bogus values userspace gets from hwmon while the GPU is powered down Signed-off-by: Karol Herbst <[email protected]> Reviewed-by: Rhys Kidd <[email protected]> Signed-off-by: Ben Skeggs <[email protected]>
1 parent b0f84a8 commit 68bf8b5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/gpu/drm/nouveau/nouveau_hwmon.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
428428

429429
switch (attr) {
430430
case hwmon_temp_input:
431+
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
432+
return -EINVAL;
431433
ret = nvkm_therm_temp_get(therm);
432434
*val = ret < 0 ? ret : (ret * 1000);
433435
break;
@@ -474,6 +476,8 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
474476

475477
switch (attr) {
476478
case hwmon_fan_input:
479+
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
480+
return -EINVAL;
477481
*val = nvkm_therm_fan_sense(therm);
478482
break;
479483
default:
@@ -496,6 +500,8 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
496500

497501
switch (attr) {
498502
case hwmon_in_input:
503+
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
504+
return -EINVAL;
499505
ret = nvkm_volt_get(volt);
500506
*val = ret < 0 ? ret : (ret / 1000);
501507
break;
@@ -527,6 +533,8 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
527533
*val = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE);
528534
break;
529535
case hwmon_pwm_input:
536+
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
537+
return -EINVAL;
530538
*val = therm->fan_get(therm);
531539
break;
532540
default:
@@ -548,6 +556,8 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
548556

549557
switch (attr) {
550558
case hwmon_power_input:
559+
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
560+
return -EINVAL;
551561
*val = nvkm_iccsense_read_all(iccsense);
552562
break;
553563
case hwmon_power_max:

0 commit comments

Comments
 (0)