Commit d01b847c5cd070895c4ba178c85cd068a95cf7cd
Committed by
Wolfgang Denk
1 parent
5a910c224b
Exists in
master
and in
54 other branches
LM75 bug fix for negative temperatures
When the LM75 temperature sensor measures a temperature below 0 C, the current driver does not perform sign extension, so the result returned is 256 C too high. This patch fixes the problem. Signed-off-by: Larry Johnson <lrj@acm.org>
Showing 1 changed file with 7 additions and 1 deletions Side-by-side Diff
drivers/hwmon/lm75.c
... | ... | @@ -179,7 +179,13 @@ |
179 | 179 | |
180 | 180 | int dtt_get_temp(int sensor) |
181 | 181 | { |
182 | - return (dtt_read(sensor, DTT_READ_TEMP) / 256); | |
182 | + int const ret = dtt_read(sensor, DTT_READ_TEMP); | |
183 | + | |
184 | + if (ret < 0) { | |
185 | + printf("DTT temperature read failed.\n"); | |
186 | + return 0; | |
187 | + } | |
188 | + return (int)((int16_t) ret / 256); | |
183 | 189 | } /* dtt_get_temp() */ |
184 | 190 | |
185 | 191 | #endif /* CONFIG_DTT_LM75 */ |