On 05/26/2017 07:48 AM, Patrick Venture wrote:
When the controller fails to provide an RPM reading within the allotted
time; the driver returns -EAGAIN instead of 0.
Signed-off-by: Patrick Venture <[email protected] <mailto:[email protected]>>
---
drivers/hwmon/aspeed-pwm-tacho.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c
index 48403a2115be..ec57be4a4a55 100644
--- a/drivers/hwmon/aspeed-pwm-tacho.c
+++ b/drivers/hwmon/aspeed-pwm-tacho.c
@@ -7,6 +7,7 @@
*/
#include <linux/clk.h>
+#include <linux/errno.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
#include <linux/hwmon.h>
@@ -516,7 +517,7 @@ static u32 aspeed_get_fan_tach_ch_rpm(struct
aspeed_pwm_tacho_data *priv,
clk_source = priv->clk_freq;
if (raw_data == 0)
-return 0;
+return -EAGAIN;
We don't know why the value reported is 0. Maybe it is because no fan is
connected.
We can not just return -EAGAIN; this might result in a tight loop if the
problem is
permanent. A retry loop which returns -ETIMEOUT after some reasonable timeout
might be more appropriate if the controller just needs more time, and if reading
"0"
is an indication that the controller is not ready.
Note that you can not just return an error without changing the function type
to int.
return (clk_source * 60) / (2 * raw_data * tach_div);
}
@@ -566,7 +567,7 @@ static ssize_t show_rpm(struct device *dev, struct
device_attribute *attr,
rpm = aspeed_get_fan_tach_ch_rpm(priv, index);
-return sprintf(buf, "%u\n", rpm);
+return sprintf(buf, "%d\n", rpm);
rpm is u32. This is incorrect. This would also return a negative speed to the
user,
not an error. To return an error, the variable would have to be an int, and the
code would have to be something like
int rpm;
...
rpm = aspeed_get_fan_tach_ch_rpm(priv, index);
if (rpm < 0)
return rpm;
return sprintf(...);
Guenter
}
static umode_t pwm_is_visible(struct kobject *kobj,
--
2.13.0.219.gdb65acc882-goog
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html