hwmon: Fix applesmc temperature handling
Subsystems (2)
PATCH 2/3 hwmon: Fix applesmc temperature handling
The temperature registers in the applesmc hardware are signed. It's likely that a negative value is invalid, so trigger on that and return an error rather than an erroneous value.
--- drivers/hwmon/applesmc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/hwmon/applesmc.c +4 -0
@@ -781,6 +781,10 @@ static ssize_t applesmc_show_temperature(struct device *dev,return ret;if (entry->len =2 ) { +if (buffer[0 ] >=0x80 ) { +/* The two byte format is signed - ignore negative */ +return -EINVAL ; + } temp = buffer[0 ] *1000 ; temp += (buffer[1 ] >>6 ) *250 ; }else {
Signature · 7 lines
1.7.6 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
Quoted 14 lines · Matthew Garrett
The temperature registers in the applesmc hardware are signed. It's likely that a negative value is invalid, so trigger on that and return an error rather than an erroneous value.
Signed-off-by Matthew Garrett <[email protected]>--- drivers/hwmon/applesmc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)drivers/hwmon/applesmc.c +0
-0
drivers/hwmon/applesmc.c static ssize_t applesmc_show_temperature(struct device *dev, · line 787
Quoted 7 lines
drivers/hwmon/applesmc.c +4
-0@@ -781,6 +781,10 @@ static ssize_t applesmc_show_temperature(struct device *dev,return ret;if (entry->len =2 ) { +if (buffer[0 ] >=0x80 ) { +/* The two byte format is signed - ignore negative */ +return -EINVAL ; + }
Kind of unusual. Do you have evidence that such an error is in fact seen ? If there is no such evidence, I'd rather keep the original code. We don't usually return errors for negative temperature readings just because we assume that the readings might be erroneous.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
In reply to Matthew GarrettQuoted 10 lines · Guenter Roeck
drivers/hwmon/applesmc.c static ssize_t applesmc_show_temperature(struct device *dev, · line 787
Quoted 5 lines
drivers/hwmon/applesmc.c +4
-0if (entry->len =2 ) { +if (buffer[0 ] >=0x80 ) { +/* The two byte format is signed - ignore negative */ +return -EINVAL ; + }Kind of unusual. Do you have evidence that such an error is in fact seen ? If there is no such evidence, I'd rather keep the original code. We don't usually return errors for negative temperature readings just because we assume that the readings might be erroneous.
Yeah, my MBA returns these from TCZ3 and TH0F. Typical read value is 0xf978. There may be some other underlying issue that's triggering this, but returning data that's known to be bogus seems unhelpful.
Signature · 6 lines
Matthew Garrett | [email protected] _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
In reply to Matthew GarrettQuoted 12 lines · Matthew Garrett
Quoted 10 lines · Guenter Roeck
drivers/hwmon/applesmc.c static ssize_t applesmc_show_temperature(struct device *dev, · line 787
Quoted 5 lines
drivers/hwmon/applesmc.c +4
-0if (entry->len =2 ) { +if (buffer[0 ] >=0x80 ) { +/* The two byte format is signed - ignore negative */ +return -EINVAL ; + }Kind of unusual. Do you have evidence that such an error is in fact seen ? If there is no such evidence, I'd rather keep the original code. We don't usually return errors for negative temperature readings just because we assume that the readings might be erroneous.
Quoted 4 lines
Yeah, my MBA returns these from TCZ3 and TH0F. Typical read value is
0xf978. There may be some other underlying issue that's triggering this, but returning data that's known to be bogus seems unhelpful.
Sounds like that is a persistent condition, though, not a temporary one. Negative values returned from temperature sensors often indicate either a non-existing thermistor or a sensor fault.
Personally, I think it would be better to just ignore the returned value. Ultimately, you'll have to add an entry into sensors.conf anyway, and returning an error just because the returned value _might_ be wrong does not seem to be a good idea to me.
Either case, -EINVAL seems wrong. Maybe -EIO.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
In reply to Matthew GarrettQuoted 5 lines · Guenter Roeck
Quoted 4 lines · Matthew Garrett
Yeah, my MBA returns these from TCZ3 and TH0F. Typical read value is
0xf978. There may be some other underlying issue that's triggering this, but returning data that's known to be bogus seems unhelpful.
Quoted 8 lines
Sounds like that is a persistent condition, though, not a temporary one. Negative values returned from temperature sensors often indicate either a non-existing thermistor or a sensor fault.
Personally, I think it would be better to just ignore the returned value. Ultimately, you'll have to add an entry into sensors.conf anyway, and returning an error just because the returned value _might_ be wrong does not seem to be a good idea to me.
We can pretty much guarantee that this hardware won't be running below freezing in this case. Smarter userspace can see an error and then ignore the sensor in the UI.
Quoted 1 line
Either case,
-EINVALseems wrong. Maybe-EIO.
Seems reasonable.
Signature · 6 lines
Matthew Garrett | [email protected] _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
In reply to Matthew GarrettQuoted 10 lines · Matthew Garrett
Quoted 9 lines · Guenter Roeck
Quoted 4 lines · Matthew Garrett
Yeah, my MBA returns these from TCZ3 and TH0F. Typical read value is
0xf978. There may be some other underlying issue that's triggering this, but returning data that's known to be bogus seems unhelpful.Sounds like that is a persistent condition, though, not a temporary one. Negative values returned from temperature sensors often indicate either a non-existing thermistor or a sensor fault.
Quoted 8 lines
Quoted 4 lines
Personally, I think it would be better to just ignore the returned value. Ultimately, you'll have to add an entry into sensors.conf anyway, and returning an error just because the returned value _might_ be wrong does not seem to be a good idea to me.
We can pretty much guarantee that this hardware won't be running below freezing in this case. Smarter userspace can see an error and then ignore the sensor in the UI.
To that end, userspace can equally well read the negative value.
Bogus sensor values is an integral part of some of the machines. For instance, on some models, remove the battery and some temperature sensors will start to oscillate between zero and max. Some time ago, I tried to come up with a patch which would detect this behavior, so far without positive reports. If anything, it would make sense to filter the list of available sensors, either dynamically (removing it from the sysfs tree) or by clamping the value to zero or something. Reporting an error does not seem very useful.
Thanks,
Henrik
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 2/3] hwmon: Fix applesmc temperature
In reply to Matthew GarrettQuoted 7 lines · Henrik Rydberg
instance, on some models, remove the battery and some temperature sensors will start to oscillate between zero and max. Some time ago, I tried to come up with a patch which would detect this behavior, so far without positive reports. If anything, it would make sense to filter the list of available sensors, either dynamically (removing it from the sysfs tree) or by clamping the value to zero or something. Reporting an error does not seem very useful.
We *know* that the value is incorrect. How is giving it to userspace without that information in any way helpful? Once userspace has opened the file and performed read(), we need to give it something.
Signature · 6 lines
Matthew Garrett | [email protected] _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors