From patchwork Tue Oct 24 00:55:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10023397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B822D601E8 for ; Tue, 24 Oct 2017 00:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A778728956 for ; Tue, 24 Oct 2017 00:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B5E28958; Tue, 24 Oct 2017 00:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DC9028956 for ; Tue, 24 Oct 2017 00:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751226AbdJXAzc (ORCPT ); Mon, 23 Oct 2017 20:55:32 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:47875 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751216AbdJXAzc (ORCPT ); Mon, 23 Oct 2017 20:55:32 -0400 Received: by mail-pg0-f68.google.com with SMTP id r25so13138088pgn.4 for ; Mon, 23 Oct 2017 17:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=qJjs8Nlrl4fq+hkDfeF8PSA2NW3byA8VhdveRzftP6g=; b=qbLUV5PP/eg4MmjbBNHQJoTpRIqTsAy5TR2MfQOpmFrVMzlfDQrSlulhPhSRn3Huhv V7sdwx17WkTnyzxs4xH1ZIEfiraqmwcAFH+BXETzKZOwRaR5m6MI7Wk5E3sZ12U5OIdN FUdm8JXkUwFeALj/BPzBWOPqVCiU6rXFNLIxeQSdu8B8osM2otTg7ND06Pu/CVaseLXJ ipBj8HTF1mir1dBiEwrvB34GEWnkYQGjufh4/bQ/0NAKX/fM28bIHALDBzGrTdLnGX8j ZWM+Rc2xRpxX0iC3H3jfA/OexRowrGCUE5nT5e2kv4mYh5UTdmaZW0EMP2U2qxOb4xZD f1Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=qJjs8Nlrl4fq+hkDfeF8PSA2NW3byA8VhdveRzftP6g=; b=Dhl1qxn7INBb+CB8tBDZyIhgi4VG8nY4zH0uJPELpAkyvT8LM2/Y8bt8sYOBe7xQiL rXRpUZAtJGdapJhgzgHZZNH9HQni8sn0G4bvdlQL5BLrG9wGuX6GubU4NUh6BVxY0oIH biv3wc8cx8kQQBKJFr+D5GCeYvPv9xnJX8XKhlsCC4K4V10mJjJI8pLxFNEYZqmkJepK hmzCMctLudHW+mGugLxK+cCgucYV2oIezKtRfhHRglDKgQOr4EUNGxDjZFQR5XCVtiPo c0+5bIPYIpIFaGv1Y2wxkmi9mZ73ERDD9biY89KS7X0C4iqNO3zFuLyfdhjKDAJw1omB AEUQ== X-Gm-Message-State: AMCzsaXXiHWd0WTGZELdYmXm12zNiXDMoKltA7JWaG3M3rTnTjMN3B6l YP7squhwVGtu34w30gjqkDSB1g== X-Google-Smtp-Source: ABhQp+QtjXhaOEgcXdUFRol3aKesWj7xDlUG5gfvfqAmGDq//X2z85E0rNWPN9B+dGZQoIPiHTBKxQ== X-Received: by 10.98.158.202 with SMTP id f71mr14378780pfk.175.1508806531464; Mon, 23 Oct 2017 17:55:31 -0700 (PDT) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id w20sm14472063pfi.89.2017.10.23.17.55.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 17:55:29 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Ralf Goebel Subject: [PATCH] tmp102: Fix first temperature reading Date: Mon, 23 Oct 2017 17:55:26 -0700 Message-Id: <1508806526-28489-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Ralf Goebel Signed-off-by: Guenter Roeck Reviewed-by: Jean Delvare --- 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,