Skip to contentSkip to conversation

w1: w1 temp calculation overflow fix.

PATCH In review Evgeniy Polyakov 4 participants 9 messages Feb 9, 2009 – Feb 11, 2009 W1 dallas's 1-wire bus

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 w1: w1 temp calculation overflow fix.

drivers/w1/slaves/w1_therm.c +1 -1
index 2c8dff9..1ed3d55 100644
@@ -115,7 +115,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
-	s16 t = (rom[1] << 8) | rom[0];
+	int t = ((s16)rom[1] << 8) | rom[0];
 	t = t*1000/16;
 	return t;
 }
Signature · 1 line
	Evgeniy Polyakov
#1 lore raw

drivers/w1/slaves/w1_therm.c static struct w1_therm_family_converter w1_therm_families[] = { · line 118

Quoted 13 lines · Evgeniy Polyakov
drivers/w1/slaves/w1_therm.c +1 -1
index 2c8dff9..1ed3d55 100644
@@ -115,7 +115,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
-	s16 t = (rom[1] << 8) | rom[0];
+	int t = ((s16)rom[1] << 8) | rom[0];

Alternatively,

	int t = (s16)le16_to_cpup((__le16 *)rom);

Cheers,

Harvey

#3 lore raw
In reply to Evgeniy Polyakov
Quoted 2 lines · On Tue, 10 Feb 2009 00:42:17 +0300 Evgeniy Polyakov <[email protected]> wrote:

I assumed from the above that Ian authored this patch. Please let me know if that was incorrect.

The way to track authorship is to put the originator's From: line at the top of the changelog.

drivers/w1/slaves/w1_therm.c static struct w1_therm_family_converter w1_therm_families[] = { · line 121

Quoted 13 lines
drivers/w1/slaves/w1_therm.c +1 -1
index 2c8dff9..1ed3d55 100644
@@ -115,7 +115,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
-	s16 t = (rom[1] << 8) | rom[0];
+	int t = ((s16)rom[1] << 8) | rom[0];
 	t = t*1000/16;
 	return t;
 }

It seems strange to use s16 here, but it will fix the bug.

Perhaps this function should be using plain old `unsigned' everywhere.

Please provide changelogs. This bugfix is applicable to 2.6.28.x and probably earlier. But due to the lack of any supporting information I am not in a position to determine whether it should be backported.

#4 lore raw
Quoted 8 lines · Andrew Morton
Quoted 2 lines

I assumed from the above that Ian authored this patch. Please let me know if that was incorrect.

The way to track authorship is to put the originator's From: line at the top of the changelog.

Yes, Ian is the author.
I will put appropriate From: field next time, I did not know it :)

Quoted 14 lines

drivers/w1/slaves/w1_therm.c static struct w1_therm_family_converter w1_therm_families[] = { · line 121

Quoted 11 lines
drivers/w1/slaves/w1_therm.c +1 -1
@@ -115,7 +115,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
-	s16 t = (rom[1] << 8) | rom[0];
+	int t = ((s16)rom[1] << 8) | rom[0];
 	t = t*1000/16;
 	return t;
 }

It seems strange to use s16 here, but it will fix the bug.

Quoted 5 lines

Perhaps this function should be using plain old `unsigned' everywhere.

Please provide changelogs. This bugfix is applicable to 2.6.28.x and probably earlier. But due to the lack of any supporting information I am not in a position to determine whether it should be backported.

That's what was placed into the documentation iirc, code for the more advanced chip works ok. This code exists for way too long, but apparently did not grow higher than 32 degrees, so it is applicable for the earlier trees either.

Signature · 1 line
	Evgeniy Polyakov
#2 lore raw
In reply to Harvey Harrison
Quoted 7 lines · Harvey Harrison

drivers/w1/slaves/w1_therm.c static struct w1_therm_family_converter w1_therm_families[] = { · line 118

Quoted 3 lines

{

drivers/w1/slaves/w1_therm.c +1 -1
-	s16 t = (rom[1] << 8) | rom[0];
+	int t = ((s16)rom[1] << 8) | rom[0];

Alternatively,

	int t = (s16)le16_to_cpup((__le16 *)rom);

Well, yes, but for the consistency with the other conversation functions I think above is more appropriate.

Signature · 1 line
	Evgeniy Polyakov
#5 lore raw
In reply to Evgeniy Polyakov
Quoted 8 lines · On Tue, 10 Feb 2009 01:08:30 +0300 Evgeniy Polyakov <[email protected]> wrote:
Quoted 3 lines

Please provide changelogs. This bugfix is applicable to 2.6.28.x and probably earlier. But due to the lack of any supporting information I am not in a position to determine whether it should be backported.

That's what was placed into the documentation iirc, code for the more advanced chip works ok. This code exists for way too long, but apparently did not grow higher than 32 degrees, so it is applicable for the earlier trees either.

I think the above means that the patch is appropriate for earlier trees.

But we still don't have a _reason_. Presumably the bug causes the driver to malfunction in some manner.

There are two reasons for properly describing the patch:

a) the stable maintainers will want to understand why they should backport the patch - does the bug affect anyone and if so, how?

b) people who are using earlier kernel versions and who experience a bug will want to know whether this patch will fix their bug. To do that, they will need a description of what the patch fixes!

So please, do describe the user-visible impact of the bug if that is at all relevant or possible.

#7 lore raw
Quoted 9 lines · Andrew Morton
Quoted 2 lines · On Mon, 9 Feb 2009 14:48:03 -0800 Andrew Morton <[email protected]>…

But we still don't have a _reason_. Presumably the bug causes the driver to malfunction in some manner.

ah-hah. I discovered http://bugzilla.kernel.org/show_bug.cgi?id=12646

Now all is revealed!

Argh, I did not get that you need this description :)
Yes, reading sysfs temperature file may return wrong (overflown) value.

Signature · 1 line
	Evgeniy Polyakov
#8 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 2 lines · On Mon, 9 Feb 2009 14:48:03 -0800 Andrew Morton <[email protected]>…

But we still don't have a _reason_. Presumably the bug causes the driver to malfunction in some manner.

ah-hah. I discovered http://bugzilla.kernel.org/show_bug.cgi?id=12646

Now all is revealed!

I've been out of the loop a couple of days. Is there anything else needed from me?

Regards,
Ian

Signature · 1 line
Ian Dall <[email protected]>