Skip to content

Commit

Permalink
W1: w1_therm.c ds18b20 decode freezing temperatures correctly
Browse files Browse the repository at this point in the history
Correct the decoding of negative C temperatures.  The code did a binary OR
of two bytes to make a 16 bit value, but assignd it to an integer.  This
caused the value to not be sign extended and to loose that it was a
negative number in the assignment.

Before the patch (in my freezer),
	w1_slave
	ed fe 4b 46 7f ff 03 10 e4 : crc=e4 YES
	ed fe 4b 46 7f ff 03 10 e4 t=4078
With the patch,
	e3 fe 4b 46 7f ff 0d 10 81 : crc=81 YES
	e3 fe 4b 46 7f ff 0d 10 81 t=-17

Signed-off-by: David Fries <david@fries.net>
Acked-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
David Fries authored and Linus Torvalds committed Jan 22, 2008
1 parent d384e35 commit 941ed3b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/w1/slaves/w1_therm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {

static inline int w1_DS18B20_convert_temp(u8 rom[9])
{
int t = (rom[1] << 8) | rom[0];
s16 t = (rom[1] << 8) | rom[0];
t /= 16;
return t;
}
Expand Down

0 comments on commit 941ed3b

Please sign in to comment.