lm87: Fix masking of config register in
PATCH 1/2 lm87: Fix masking of config register in
lm87_init_client() does:
if ((config & 0x81) != 0x01) {
/* Start monitoring */
lm87_write_value(client, LM87_REG_CONFIG,
(config & 0xF7) | 0x01);
}This means that if the Start bit is clear or the Initialization bit is set we set the Start bit and clear the INT#_Clear bit. I think this should actually clear the Initialization bit and that 0xF7 is a typo for 0x7F.
--- drivers/hwmon/lm87.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hwmon/lm87.c +1 -1
@@ -870,7 +870,7 @@ static void lm87_init_client(struct i2c_client *client)if ((config &0x81 ) !=0x01 ) {/* Start monitoring */ lm87_write_value (client,LM87_REG_CONFIG , - (config &0xF7 ) |0x01 ); + (config & ~0x80 ) |0x01 ); } }
Signature · 8 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked. _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 1/2] lm87: Fix masking of config register
Hi Ben,
Quoted 23 lines · Ben Hutchings
lm87_init_client()does:if ((config & 0x81) != 0x01) { /* Start monitoring */ lm87_write_value(client, LM87_REG_CONFIG, (config & 0xF7) | 0x01); }This means that if the Start bit is clear or the Initialization bit is set we set the Start bit and clear the INT#_Clear bit. I think this should actually clear the Initialization bit and that
0xF7is a typo for0x7F.Signed-off-by Ben Hutchings <[email protected]>--- drivers/hwmon/lm87.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/hwmon/lm87.c +0
-0
drivers/hwmon/lm87.c static void lm87_init_client(struct i2c_client *client) · line 876
Quoted 8 lines
drivers/hwmon/lm87.c +1
-1@@ -870,7 +870,7 @@ static void lm87_init_client(struct i2c_client *client)if ((config &0x81 ) !=0x01 ) {/* Start monitoring */ lm87_write_value (client,LM87_REG_CONFIG , - (config &0xF7 ) |0x01 ); + (config & ~0x80 ) |0x01 ); } }
I agree that the current code is incorrect, but I disagree with your analysis (I don't think the 0xF7 is a typo) and the proposed fix.
First of all, checking for bit 7 (Initialization) doesn't make sense. This bit self-clears, so we're never going to see it set.
Secondly, clearing bit 3 (INT#_Clear) is a good idea. According to the datasheet, monitoring is stopped while this bit is set, and it is set by default. So we really want to clear it as part of the initialization. Meaning that we also want to check if it is set.
So I would change the code as follows:
if ((config & 0x09) != 0x01) {
/* Start monitoring */
lm87_write_value(client, LM87_REG_CONFIG,
(config & 0x77) | 0x01);
}What do you think?
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 1/2] lm87: Fix masking of config register
In reply to Ben HutchingsJean Delvare wrote:
[...]
Quoted 5 lines
I agree that the current code is incorrect, but I disagree with your analysis (I don't think the
0xF7is a typo) and the proposed fix.First of all, checking for bit 7 (Initialization) doesn't make sense. This bit self-clears, so we're never going to see it set.
Right.
Quoted 7 lines
Secondly, clearing bit 3 (INT#_Clear) is a good idea. According to the datasheet, monitoring is stopped while this bit is set, and it is set by default. So we really want to clear it as part of the initialization. Meaning that we also want to check if it is set.
So I would change the code as follows:
Quoted 7 lines
if ((config & 0x09) != 0x01) { /* Start monitoring */ lm87_write_value(client, LM87_REG_CONFIG, (config & 0x77) | 0x01); }What do you think?
That makes sense. Perhaps the comment should also say that we're clearing INT#_Clear.
Ben.
Signature · 8 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked. _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH 1/2] lm87: Fix masking of config register
In reply to Ben HutchingsQuoted 23 lines · Ben Hutchings
Jean Delvare wrote:
[...]Quoted 5 lines
I agree that the current code is incorrect, but I disagree with your analysis (I don't think the
0xF7is a typo) and the proposed fix.First of all, checking for bit 7 (Initialization) doesn't make sense. This bit self-clears, so we're never going to see it set.
Right.
Quoted 13 lines
Secondly, clearing bit 3 (INT#_Clear) is a good idea. According to the datasheet, monitoring is stopped while this bit is set, and it is set by default. So we really want to clear it as part of the initialization. Meaning that we also want to check if it is set.
So I would change the code as follows:
if ((config & 0x09) != 0x01) { /* Start monitoring */ lm87_write_value(client, LM87_REG_CONFIG, (config & 0x77) | 0x01); }
Quoted 4 lines
Quoted 1 line
What do you think?
That makes sense. Perhaps the comment should also say that we're clearing INT#_Clear.
Alright. If you update your patch to do that, I'll review it and queue it for 2.6.27.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors