[v4,5/6] hwmon: don't require therm to be valid to get any data

Submitted by Karol Herbst on Feb. 20, 2016, 5:11 p.m.

Details

Message ID 1455988299-2300-6-git-send-email-nouveau@karolherbst.de
State New
Headers show
Series "Suppor for various power sensors on GF100+" ( rev: 3 ) in Nouveau

Not browsing as part of any series.

Commit Message

Karol Herbst Feb. 20, 2016, 5:11 p.m.
Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/nouveau_hwmon.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
index c4f77f5..a630192 100644
--- a/drm/nouveau/nouveau_hwmon.c
+++ b/drm/nouveau/nouveau_hwmon.c
@@ -643,9 +643,6 @@  nouveau_hwmon_init(struct drm_device *dev)
 		return -ENOMEM;
 	hwmon->dev = dev;
 
-	if (!therm || !therm->attr_get || !therm->attr_set)
-		return -ENODEV;
-
 	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
@@ -659,26 +656,28 @@  nouveau_hwmon_init(struct drm_device *dev)
 	if (ret)
 		goto error;
 
-	/* if the card has a working thermal sensor */
-	if (nvkm_therm_temp_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
-		if (ret)
-			goto error;
-	}
-
-	/* if the card has a pwm fan */
-	/*XXX: incorrect, need better detection for this, some boards have
-	 *     the gpio entries for pwm fan control even when there's no
-	 *     actual fan connected to it... therm table? */
-	if (therm->fan_get && therm->fan_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj,
-					 &hwmon_pwm_fan_attrgroup);
-		if (ret)
-			goto error;
+	if (therm && therm->attr_get && therm->attr_set) {
+		/* if the card has a working thermal sensor */
+		if (nvkm_therm_temp_get(therm) >= 0) {
+			ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
+			if (ret)
+				goto error;
+		}
+
+		/* if the card has a pwm fan */
+		/*XXX: incorrect, need better detection for this, some boards have
+		 *     the gpio entries for pwm fan control even when there's no
+		 *     actual fan connected to it... therm table? */
+		if (therm->fan_get && therm->fan_get(therm) >= 0) {
+			ret = sysfs_create_group(&hwmon_dev->kobj,
+						 &hwmon_pwm_fan_attrgroup);
+			if (ret)
+				goto error;
+		}
 	}
 
 	/* if the card can read the fan rpm */
-	if (nvkm_therm_fan_sense(therm) >= 0) {
+	if (therm && nvkm_therm_fan_sense(therm) >= 0) {
 		ret = sysfs_create_group(&hwmon_dev->kobj,
 					 &hwmon_fan_rpm_attrgroup);
 		if (ret)

Comments

On 20/02/16 19:11, Karol Herbst wrote:
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>

Should never be an issue, but I get your point.

Reviewed-by: Martin Peres <martin.peres@free.fr>
> ---
>   drm/nouveau/nouveau_hwmon.c | 39 +++++++++++++++++++--------------------
>   1 file changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
> index c4f77f5..a630192 100644
> --- a/drm/nouveau/nouveau_hwmon.c
> +++ b/drm/nouveau/nouveau_hwmon.c
> @@ -643,9 +643,6 @@ nouveau_hwmon_init(struct drm_device *dev)
>   		return -ENOMEM;
>   	hwmon->dev = dev;
>   
> -	if (!therm || !therm->attr_get || !therm->attr_set)
> -		return -ENODEV;
> -
>   	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
>   	if (IS_ERR(hwmon_dev)) {
>   		ret = PTR_ERR(hwmon_dev);
> @@ -659,26 +656,28 @@ nouveau_hwmon_init(struct drm_device *dev)
>   	if (ret)
>   		goto error;
>   
> -	/* if the card has a working thermal sensor */
> -	if (nvkm_therm_temp_get(therm) >= 0) {
> -		ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
> -		if (ret)
> -			goto error;
> -	}
> -
> -	/* if the card has a pwm fan */
> -	/*XXX: incorrect, need better detection for this, some boards have
> -	 *     the gpio entries for pwm fan control even when there's no
> -	 *     actual fan connected to it... therm table? */
> -	if (therm->fan_get && therm->fan_get(therm) >= 0) {
> -		ret = sysfs_create_group(&hwmon_dev->kobj,
> -					 &hwmon_pwm_fan_attrgroup);
> -		if (ret)
> -			goto error;
> +	if (therm && therm->attr_get && therm->attr_set) {
> +		/* if the card has a working thermal sensor */
> +		if (nvkm_therm_temp_get(therm) >= 0) {
> +			ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
> +			if (ret)
> +				goto error;
> +		}
> +
> +		/* if the card has a pwm fan */
> +		/*XXX: incorrect, need better detection for this, some boards have
> +		 *     the gpio entries for pwm fan control even when there's no
> +		 *     actual fan connected to it... therm table? */
> +		if (therm->fan_get && therm->fan_get(therm) >= 0) {
> +			ret = sysfs_create_group(&hwmon_dev->kobj,
> +						 &hwmon_pwm_fan_attrgroup);
> +			if (ret)
> +				goto error;
> +		}
>   	}
>   
>   	/* if the card can read the fan rpm */
> -	if (nvkm_therm_fan_sense(therm) >= 0) {
> +	if (therm && nvkm_therm_fan_sense(therm) >= 0) {
>   		ret = sysfs_create_group(&hwmon_dev->kobj,
>   					 &hwmon_fan_rpm_attrgroup);
>   		if (ret)