Skip to content

Commit 9a6a1ec

Browse files
iandalltorvalds
authored andcommitted
w1: w1 temp: fix negative termperature calculation
Fix regression caused by commit 507e2fb ("w1: w1 temp calculation overflow fix") whereby negative temperatures for the DS18B20 are not converted properly. When the temperature exceeds 32767 milli-degrees the temperature overflows to -32768 millidegrees. These are both well within the -55 - +125 degree range for the sensor. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=12646 Signed-of-by: Ian Dall <[email protected]> Cc: Evgeniy Polyakov <[email protected]> Tested-by: Karsten Elfenbein <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7716fa6 commit 9a6a1ec

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/w1/slaves/w1_therm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ static struct w1_therm_family_converter w1_therm_families[] = {
115115

116116
static inline int w1_DS18B20_convert_temp(u8 rom[9])
117117
{
118-
int t = ((s16)rom[1] << 8) | rom[0];
119-
t = t*1000/16;
120-
return t;
118+
s16 t = le16_to_cpup((__le16 *)rom);
119+
return t*1000/16;
121120
}
122121

123122
static inline int w1_DS18S20_convert_temp(u8 rom[9])

0 commit comments

Comments
 (0)