Skip to content

Commit

Permalink
drm/nouveau/hwmon: return EINVAL if the GPU is powered down for senso…
Browse files Browse the repository at this point in the history
…rs 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]>
  • Loading branch information
karolherbst authored and Ben Skeggs committed Jul 19, 2019
1 parent b0f84a8 commit 68bf8b5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/gpu/drm/nouveau/nouveau_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)

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

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

switch (attr) {
case hwmon_in_input:
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
return -EINVAL;
ret = nvkm_volt_get(volt);
*val = ret < 0 ? ret : (ret / 1000);
break;
Expand Down Expand Up @@ -527,6 +533,8 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
*val = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE);
break;
case hwmon_pwm_input:
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
return -EINVAL;
*val = therm->fan_get(therm);
break;
default:
Expand All @@ -548,6 +556,8 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)

switch (attr) {
case hwmon_power_input:
if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
return -EINVAL;
*val = nvkm_iccsense_read_all(iccsense);
break;
case hwmon_power_max:
Expand Down

0 comments on commit 68bf8b5

Please sign in to comment.