[Nouveau] [RFC PATCH 02/29] hwmon: properly check for errors
Pierre Moreau
pierre.morrow at free.fr
Sun Oct 8 10:22:18 UTC 2017
Reviewed-by: Pierre Moreau <pierre.morrow at free.fr>
On 2017-09-15 — 17:11, Karol Herbst wrote:
> Otherwise hwmon interprets error codes as real values.
>
> Signed-off-by: Karol Herbst <karolherbst at gmail.com>
> ---
> drm/nouveau/nouveau_hwmon.c | 33 ++++++++++++++++++++++++++-------
> 1 file changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
> index f1914d9a..0d75c14d 100644
> --- a/drm/nouveau/nouveau_hwmon.c
> +++ b/drm/nouveau/nouveau_hwmon.c
> @@ -470,18 +470,23 @@ nouveau_fan_read(struct device *dev, u32 attr, int channel, long *val)
> struct drm_device *drm_dev = dev_get_drvdata(dev);
> struct nouveau_drm *drm = nouveau_drm(drm_dev);
> struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
> + int ret;
>
> if (!therm)
> return -EOPNOTSUPP;
>
> switch (attr) {
> case hwmon_fan_input:
> - *val = nvkm_therm_fan_sense(therm);
> + ret = nvkm_therm_fan_sense(therm);
> break;
> default:
> return -EOPNOTSUPP;
> }
>
> + if (ret < 0)
> + return ret;
> +
> + *val = ret;
> return 0;
> }
>
> @@ -491,7 +496,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
> struct drm_device *drm_dev = dev_get_drvdata(dev);
> struct nouveau_drm *drm = nouveau_drm(drm_dev);
> struct nvkm_volt *volt = nvxx_volt(&drm->client.device);
> - int ret;
> + int ret = 0;
>
> if (!volt)
> return -EOPNOTSUPP;
> @@ -499,7 +504,8 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
> switch (attr) {
> case hwmon_in_input:
> ret = nvkm_volt_get(volt);
> - *val = ret < 0 ? ret : (ret / 1000);
> + if (ret >= 0)
> + *val = ret / 1000;
> break;
> case hwmon_in_min:
> *val = volt->min_uv > 0 ? (volt->min_uv / 1000) : -ENODEV;
> @@ -511,7 +517,7 @@ nouveau_in_read(struct device *dev, u32 attr, int channel, long *val)
> return -EOPNOTSUPP;
> }
>
> - return 0;
> + return ret;
> }
>
> static int
> @@ -520,21 +526,26 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val)
> struct drm_device *drm_dev = dev_get_drvdata(dev);
> struct nouveau_drm *drm = nouveau_drm(drm_dev);
> struct nvkm_therm *therm = nvxx_therm(&drm->client.device);
> + int ret;
>
> if (!therm || !therm->attr_get || !therm->fan_get)
> return -EOPNOTSUPP;
>
> switch (attr) {
> case hwmon_pwm_enable:
> - *val = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE);
> + ret = therm->attr_get(therm, NVKM_THERM_ATTR_FAN_MODE);
> break;
> case hwmon_pwm_input:
> - *val = therm->fan_get(therm);
> + ret = therm->fan_get(therm);
> break;
> default:
> return -EOPNOTSUPP;
> }
>
> + if (ret < 0)
> + return ret;
> +
> + *val = ret;
> return 0;
> }
>
> @@ -544,18 +555,26 @@ nouveau_power_read(struct device *dev, u32 attr, int channel, long *val)
> struct drm_device *drm_dev = dev_get_drvdata(dev);
> struct nouveau_drm *drm = nouveau_drm(drm_dev);
> struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device);
> + int ret;
>
> if (!iccsense)
> return -EOPNOTSUPP;
>
> switch (attr) {
> case hwmon_power_input:
> - *val = nvkm_iccsense_read_all(iccsense);
> + ret = nvkm_iccsense_read_all(iccsense);
> + if (ret < 0)
> + return ret;
> + *val = ret;
> break;
> case hwmon_power_max:
> + if (iccsense->power_w_max <= 0)
> + return -ENODEV;
> *val = iccsense->power_w_max;
> break;
> case hwmon_power_crit:
> + if (iccsense->power_w_crit <= 0)
> + return -ENODEV;
> *val = iccsense->power_w_crit;
> break;
> default:
> --
> 2.14.1
>
> _______________________________________________
> Nouveau mailing list
> Nouveau at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/nouveau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/nouveau/attachments/20171008/4913c3c7/attachment.sig>
More information about the Nouveau
mailing list