Skip to contentSkip to conversation

hwmon: (lm75) Strengthen detect function

PATCH In review Guenter Roeck 3 participants 9 messages Dec 4, 2014 – Dec 6, 2014 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (lm75) Strengthen detect function

A chip returning 0x00 in all registers is erroneously detected as LM75. Check hysteresis and temperature limit registers and abort if both are 0 to reduce the likelyhood for this to happen.

---
 drivers/hwmon/lm75.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/lm75.c +6 -0
index f58439b..6753fd9 100644
@@ -415,6 +415,12 @@ static int lm75_detect(struct i2c_client *new_client,
 		 || i2c_smbus_read_byte_data(new_client, 7) != os)
 			return -ENODEV;
 	}
+	/*
+	 * It is very unlikely that this is a LM75 if both
+	 * hysteresis and temperature limit registers are 0.
+	 */
+	if (hyst = 0 && os = 0)
+		return -ENODEV;
 
 	/* Addresses cycling */
 	for (i = 8; i <= 248; i += 40) {
Signature · 7 lines
1.9.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Hello Guenter,

does it also make sense to include a check for the conf != 0 here (it should be set to 0 for POR from the datasheet)? Other than this quesiton/comment, the code looks fine to me.

thanks,

*** Rob.

Quoted 30 lines · Guenter Roeck

A chip returning 0x00 in all registers is erroneously detected as LM75. Check hysteresis and temperature limit registers and abort if both are 0 to reduce the likelyhood for this to happen.

---
 drivers/hwmon/lm75.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/lm75.c +6 -1
index f58439b..6753fd9 100644
@@ -415,6 +415,12 @@ static int lm75_detect(struct i2c_client *new_client,
                 || i2c_smbus_read_byte_data(new_client, 7) != os)
                        return -ENODEV;
        }
+       /*
+        * It is very unlikely that this is a LM75 if both
+        * hysteresis and temperature limit registers are 0.
+        */
+       if (hyst = 0 && os = 0)
+               return -ENODEV;
 
        /* Addresses cycling */
        for (i = 8; i <= 248; i += 40) {
--

1.9.1

Quoted 5 lines

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author maintainer
#2 lore raw
In reply to Guenter Roeck
Quoted 6 lines · Robert Coulson

Hello Guenter,

does it also make sense to include a check for the conf != 0 here (it should be set to 0 for POR from the datasheet)? Other than this quesiton/comment, the code looks fine to me.

Hi Rob,

the configuration register could be set to a non-zero value, for example by the BIOS or rommon. Sure, that is in theory possible for the hysteresis and limit registers as well, but that would be both unlikely and unreasonable.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

Reviewed-by on v1 1/1
#3 lore raw
In reply to Guenter Roeck
Quoted 9 lines · Guenter Roeck
Quoted 6 lines · Robert Coulson

Hello Guenter,

does it also make sense to include a check for the conf != 0 here (it should be set to 0 for POR from the datasheet)? Other than this quesiton/comment, the code looks fine to me.

Hi Rob,

Quoted 8 lines

the configuration register could be set to a non-zero value, for example by the BIOS or rommon. Sure, that is in theory possible for the hysteresis and limit registers as well, but that would be both unlikely and unreasonable.

Thanks,
Guenter

Good points. Without explicit values for chip detection, it will never be
guaranteed.

I appreciate your feedback,

*** Rob.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

Reviewed-by on v1 1/1
#4 lore raw
In reply to Guenter Roeck

Hi Guenter,

Quoted 16 lines · Guenter Roeck

A chip returning 0x00 in all registers is erroneously detected as LM75. Check hysteresis and temperature limit registers and abort if both are 0 to reduce the likelyhood for this to happen.

---
 drivers/hwmon/lm75.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/hwmon/lm75.c +0 -0
index f58439b..6753fd9 100644
@@ -415,6 +415,12 @@ static int lm75_detect(struct i2c_client *new_client,
 		 || i2c_smbus_read_byte_data(new_client, 7) != os)
 			return -ENODEV;

drivers/hwmon/lm75.c static int lm75_detect(struct i2c_client *new_client, · line 426

Quoted 10 lines
drivers/hwmon/lm75.c +6 -0
 	}
+	/*
+	 * It is very unlikely that this is a LM75 if both
+	 * hysteresis and temperature limit registers are 0.
+	 */
+	if (hyst = 0 && os = 0)
+		return -ENODEV;
 
 	/* Addresses cycling */
 	for (i = 8; i <= 248; i += 40) {

Looks reasonable.

Did sensors-detect misdetect that chip as an LM75 too, or was the extended detection logic there good enough already?

Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#5 lore raw
In reply to Guenter Roeck
Quoted 32 lines · Jean Delvare

Hi Guenter,

Quoted 16 lines · Guenter Roeck

A chip returning 0x00 in all registers is erroneously detected as LM75. Check hysteresis and temperature limit registers and abort if both are 0 to reduce the likelyhood for this to happen.

---
  drivers/hwmon/lm75.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/hwmon/lm75.c +0 -0
index f58439b..6753fd9 100644
@@ -415,6 +415,12 @@ static int lm75_detect(struct i2c_client *new_client,
  		 || i2c_smbus_read_byte_data(new_client, 7) != os)
  			return -ENODEV;

drivers/hwmon/lm75.c static int lm75_detect(struct i2c_client *new_client, · line 426

Quoted 10 lines
drivers/hwmon/lm75.c +6 -0
  	}
+	/*
+	 * It is very unlikely that this is a LM75 if both
+	 * hysteresis and temperature limit registers are 0.
+	 */
+	if (hyst = 0 && os = 0)
+		return -ENODEV;
 
  	/* Addresses cycling */
  	for (i = 8; i <= 248; i += 40) {

Looks reasonable.

Quoted 5 lines

Did sensors-detect misdetect that chip as an LM75 too, or was the extended detection logic there good enough already?

Hi Jean,

sensors-detect is fine. Easy to test -load i2c-stub and see what happens. I assume that is due to the "All registers hold same value" test. Should I use that test instead ? I kind of prefer it.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#6 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck
Quoted 2 lines

Did sensors-detect misdetect that chip as an LM75 too, or was the extended detection logic there good enough already?

sensors-detect is fine. Easy to test -load i2c-stub and see what happens.

That doesn't always work because the value returned for some non-existent register addresses depend on the previous read. You can only test that with a real chip. Plus I didn't know which chip was being misdetected for you ;-)

Quoted 2 lines

I assume that is due to the "All registers hold same value" test. Should I use that test instead ? I kind of prefer it.

The tests are different and thus may result in different outcomes for various chips. It's very hard to predict which is better. All I can say is that the sensors-detect code needs the value of the current temperature register, which isn't read during detection currently, so using that logic would make driver loading slightly slower. Not sure if it really matters.

All in all, I think that having the same detection code on both side is important, as it avoids unexpected results. I don't really care which one you pick, it can always be adjusted later (as is has already been over the years) if misdetections are reported.

Thanks,

Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#7 lore raw
In reply to Guenter Roeck

Hi Jean,

Quoted 9 lines · Jean Delvare
Quoted 5 lines · Guenter Roeck
Quoted 2 lines

Did sensors-detect misdetect that chip as an LM75 too, or was the extended detection logic there good enough already?

sensors-detect is fine. Easy to test -load i2c-stub and see what happens.

That doesn't always work because the value returned for some non-existent register addresses depend on the previous read. You can

Good point.

Quoted 3 lines

only test that with a real chip. Plus I didn't know which chip was being misdetected for you ;-)

I was trying to run a module test for tmp421 while having the lm75 driver loaded. Loading the i2c-stub driver with address 0x4c caused lm75 detection to run, which detected the simulated chip at 0x4c as lm75 (because all registers in i2c-stub are initially set to 0) and instantiated it. This of course was a bit of a bummer when I tried to manually instantiate the tmp421 afterwards, causing my module test to fail. So it wasn't a real chip, just an annoying side effect of trying to use i2c-stub while the lm75 driver was loaded.

Quoted 8 lines
Quoted 2 lines

I assume that is due to the "All registers hold same value" test. Should I use that test instead ? I kind of prefer it.

The tests are different and thus may result in different outcomes for various chips. It's very hard to predict which is better. All I can say is that the sensors-detect code needs the value of the current temperature register, which isn't read during detection currently, so using that logic would make driver loading slightly slower. Not sure if

Good point.

Quoted 7 lines

it really matters.

All in all, I think that having the same detection code on both side is important, as it avoids unexpected results. I don't really care which one you pick, it can always be adjusted later (as is has already been over the years) if misdetections are reported.

Guess I'll apply the patch as-is. If anything I wonder if it would make sense to add the same test to sensors-detect (in addition to the comparison).

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#8 lore raw
In reply to Guenter Roeck

Hi Guenter,

Quoted 8 lines · Guenter Roeck

I was trying to run a module test for tmp421 while having the lm75 driver loaded. Loading the i2c-stub driver with address 0x4c caused lm75 detection to run, which detected the simulated chip at 0x4c as lm75 (because all registers in i2c-stub are initially set to 0) and instantiated it. This of course was a bit of a bummer when I tried to manually instantiate the tmp421 afterwards, causing my module test to fail. So it wasn't a real chip, just an annoying side effect of trying to use i2c-stub while the lm75 driver was loaded.

Yes, I had the same problem with i2c-stub in the past while testing multiple drivers. I've fixed detection functions each time it happened. Feel tree to fix every i2c detection function which trips on all-zeroes.

Quoted 3 lines

(...)
Guess I'll apply the patch as-is. If anything I wonder if it would make sense to add the same test to sensors-detect (in addition to the comparison).

As you wish, I'm fine both ways.

Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors