Skip to contentSkip to conversation

LM75 bug fix for negative temperatures

PATCH New Larry Johnson 2 participants 2 messages Feb 21, 2008 – Feb 22, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
The patch was tested on the AMCC Sequoia board, which uses the AD7414 temperature sensor. It appears that other drivers, such as "ds1621.c", may have the same bug, but I have no way of testing these.

 drivers/hwmon/lm75.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/hwmon/lm75.c +7 -1
index 63f3b75..e29b294 100644
@@ -179,7 +179,13 @@ int dtt_init (void)
 
 int dtt_get_temp(int sensor)
 {
-    return (dtt_read(sensor, DTT_READ_TEMP) / 256);
+    int const ret = dtt_read(sensor, DTT_READ_TEMP);
+
+    if (ret < 0) {
+	printf("DTT temperature read failed.\n");
+	return 0;
+    }
+    return (int)((int16_t) ret / 256);
 } /* dtt_get_temp() */
 
 #endif /* CONFIG_DTT_LM75 */
#1 lore raw

PATCH 1/1 LM75 bug fix for negative temperatures

Quoted 5 lines · In message <[email protected]> you wrote:

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.

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
EMACS belongs in <sys/errno.h>: Editor too big!