* [PATCH] tmp102: Fix first temperature reading
@ 2017-10-24 0:55 Guenter Roeck
2017-10-24 7:21 ` Jean Delvare
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2017-10-24 0:55 UTC (permalink / raw)
To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck, Ralf Goebel
Commit 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read
delay") reduced the initial temperature read delay and made it dependent
on the chip's shutdown mode. If the chip was not in shutdown mode at probe,
the read delay no longer applies.
This ignores the fact that the chip initialization changes the temperature
sensor resolution, and that the temperature register values change when
the resolution is changed. As a result, the reported temperature is twice
as high as the real temperature until the first temperature conversion
after the configuration change is complete. This can result in unexpected
behavior and, worst case, in a system shutdown. To fix the problem,
let's just always wait for a conversion to complete before reporting
a temperature.
Fixes: 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read delay")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197167
Reported-by: Ralf Goebel <ralf.goebel@imago-technologies.com>
Cc: Ralf Goebel <ralf.goebel@imago-technologies.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/tmp102.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index 5eafbaada795..1af1932a72db 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -268,14 +268,7 @@ static int tmp102_probe(struct i2c_client *client,
return err;
}
- tmp102->ready_time = jiffies;
- if (tmp102->config_orig & TMP102_CONF_SD) {
- /*
- * Mark that we are not ready with data until the first
- * conversion is complete
- */
- tmp102->ready_time += msecs_to_jiffies(CONVERSION_TIME_MS);
- }
+ tmp102->ready_time = jiffies + msecs_to_jiffies(CONVERSION_TIME_MS);
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
tmp102,
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tmp102: Fix first temperature reading
2017-10-24 0:55 [PATCH] tmp102: Fix first temperature reading Guenter Roeck
@ 2017-10-24 7:21 ` Jean Delvare
2017-10-24 13:17 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2017-10-24 7:21 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Hardware Monitoring, Ralf Goebel
Hi Guenter,
On Mon, 23 Oct 2017 17:55:26 -0700, Guenter Roeck wrote:
> Commit 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read
> delay") reduced the initial temperature read delay and made it dependent
> on the chip's shutdown mode. If the chip was not in shutdown mode at probe,
> the read delay no longer applies.
>
> This ignores the fact that the chip initialization changes the temperature
> sensor resolution, and that the temperature register values change when
> the resolution is changed. As a result, the reported temperature is twice
> as high as the real temperature until the first temperature conversion
> after the configuration change is complete. This can result in unexpected
> behavior and, worst case, in a system shutdown. To fix the problem,
> let's just always wait for a conversion to complete before reporting
> a temperature.
>
> Fixes: 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read delay")
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=197167
> Reported-by: Ralf Goebel <ralf.goebel@imago-technologies.com>
> Cc: Ralf Goebel <ralf.goebel@imago-technologies.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/hwmon/tmp102.c | 9 +--------
> 1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
> index 5eafbaada795..1af1932a72db 100644
> --- a/drivers/hwmon/tmp102.c
> +++ b/drivers/hwmon/tmp102.c
> @@ -268,14 +268,7 @@ static int tmp102_probe(struct i2c_client *client,
> return err;
> }
>
> - tmp102->ready_time = jiffies;
> - if (tmp102->config_orig & TMP102_CONF_SD) {
> - /*
> - * Mark that we are not ready with data until the first
> - * conversion is complete
> - */
> - tmp102->ready_time += msecs_to_jiffies(CONVERSION_TIME_MS);
> - }
> + tmp102->ready_time = jiffies + msecs_to_jiffies(CONVERSION_TIME_MS);
>
> hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
> tmp102,
Thanks for the quick fix. The change itself looks good but why remove
the comment, which I think still retains its value?
Reviewed-by: Jean Delvare <jdelvare@suse.de>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tmp102: Fix first temperature reading
2017-10-24 7:21 ` Jean Delvare
@ 2017-10-24 13:17 ` Guenter Roeck
0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2017-10-24 13:17 UTC (permalink / raw)
To: Jean Delvare; +Cc: Hardware Monitoring, Ralf Goebel
Hi Jean,
On 10/24/2017 12:21 AM, Jean Delvare wrote:
> Hi Guenter,
>
> On Mon, 23 Oct 2017 17:55:26 -0700, Guenter Roeck wrote:
>> Commit 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read
>> delay") reduced the initial temperature read delay and made it dependent
>> on the chip's shutdown mode. If the chip was not in shutdown mode at probe,
>> the read delay no longer applies.
>>
>> This ignores the fact that the chip initialization changes the temperature
>> sensor resolution, and that the temperature register values change when
>> the resolution is changed. As a result, the reported temperature is twice
>> as high as the real temperature until the first temperature conversion
>> after the configuration change is complete. This can result in unexpected
>> behavior and, worst case, in a system shutdown. To fix the problem,
>> let's just always wait for a conversion to complete before reporting
>> a temperature.
>>
>> Fixes: 3d8f7a89a197 ("hwmon: (tmp102) Improve handling of initial read delay")
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=197167
>> Reported-by: Ralf Goebel <ralf.goebel@imago-technologies.com>
>> Cc: Ralf Goebel <ralf.goebel@imago-technologies.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> drivers/hwmon/tmp102.c | 9 +--------
>> 1 file changed, 1 insertion(+), 8 deletions(-)
>>
>> diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
>> index 5eafbaada795..1af1932a72db 100644
>> --- a/drivers/hwmon/tmp102.c
>> +++ b/drivers/hwmon/tmp102.c
>> @@ -268,14 +268,7 @@ static int tmp102_probe(struct i2c_client *client,
>> return err;
>> }
>>
>> - tmp102->ready_time = jiffies;
>> - if (tmp102->config_orig & TMP102_CONF_SD) {
>> - /*
>> - * Mark that we are not ready with data until the first
>> - * conversion is complete
>> - */
>> - tmp102->ready_time += msecs_to_jiffies(CONVERSION_TIME_MS);
>> - }
>> + tmp102->ready_time = jiffies + msecs_to_jiffies(CONVERSION_TIME_MS);
>>
>> hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
>> tmp102,
>
> Thanks for the quick fix. The change itself looks good but why remove
> the comment, which I think still retains its value?
>
Good point. I'll add it back in before sending the patch upstream.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-24 13:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-24 0:55 [PATCH] tmp102: Fix first temperature reading Guenter Roeck
2017-10-24 7:21 ` Jean Delvare
2017-10-24 13:17 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox