Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp214546ybb; Tue, 7 Apr 2020 21:01:44 -0700 (PDT) X-Google-Smtp-Source: APiQypIi5g1+7bX+tRb1MU69RQhLqKuokrnHxkn799Zd3EEnXHmo0sZX15N9ySwpI/b0TSG361tz X-Received: by 2002:aca:5444:: with SMTP id i65mr1004506oib.101.1586318504083; Tue, 07 Apr 2020 21:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586318504; cv=none; d=google.com; s=arc-20160816; b=pjvqK2v+MctnLEh3D2XSZL/l+9MwsHWsrtxmhGYWHOXBQopkZuBGJxfuCNJnzoly/4 fUUGJ3kiiFXGg6JQaEK6u1zaosUNCjLld50xqQ9tCcKX0AWr9uUjXoeFvlDYOF2lSP2z 3Oxtjv7Ri41dNWCa909hATWbix+jWKCVuejl8OscbO7CSVL3EhjyCEnvoBw7Ocm6LF1z IXW5Bf6v2/hVpONEIVhCO1Jv7H9oNPw2i/Lf+HqTb4eatRzyvYdlPqyrGSos/UbblDVP QlwUN2uvgevDX6WSVt3Jn5b2BiKC3egIrcSvG2bdSkCnz4KWtJSCvdlyntpJq7QnnEKG aYvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:date:message-id :organization:from:references:to:subject; bh=GJqXVc9Om2LkPgCmvhGekSnAb3xVkS/U/iZtdAmTPa8=; b=t+kdpEXAWXKf3UgKR9OF0e+qlHdPJK7EAeIKaDkUjmhTZIbShd1AXoKwsLiIe9BOod peAjckXA2rwHaNfztFmtFdFDNklkYHQfZDZh/AHWJyquu+Z5pqEcAxUaphg0iiiCT22L lnoVK7Z705/7IjJNRnAXdtM0aCKIYZlxP6y5SnZ01DBbdKurkrnK2HTJQ3CbGyNNhgK1 wiu3qvFgS6EfWTivPL2FidT/OTcS46DKH3y8CeBVfIotbLeQNIsgo4IGQRzBy4CbKf34 tdoeDAPgH7S88xS1en1Svu4aA0l17Tp5DSEdKw2osj0FXertrrS/HQtdf+BD3cYOo8ZJ yQpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l132si113457oib.268.2020.04.07.21.01.27; Tue, 07 Apr 2020 21:01:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726513AbgDHD7X (ORCPT + 99 others); Tue, 7 Apr 2020 23:59:23 -0400 Received: from mail.itouring.de ([188.40.134.68]:45750 "EHLO mail.itouring.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbgDHD7X (ORCPT ); Tue, 7 Apr 2020 23:59:23 -0400 Received: from tux.applied-asynchrony.com (p5B07E2B3.dip0.t-ipconnect.de [91.7.226.179]) by mail.itouring.de (Postfix) with ESMTPSA id 14A1B4160ED7; Wed, 8 Apr 2020 05:59:21 +0200 (CEST) Received: from [192.168.100.223] (ragnarok.applied-asynchrony.com [192.168.100.223]) by tux.applied-asynchrony.com (Postfix) with ESMTP id BD004F01600; Wed, 8 Apr 2020 05:59:20 +0200 (CEST) Subject: Re: hwmon: drivetemp: bogus values after wake up from suspend To: Guenter Roeck , LKML References: <1af049a1-63ae-ee55-05d5-0e55eb00bd0e@applied-asynchrony.com> <03b3159b-e9ca-011d-d95c-6572cc07d895@roeck-us.net> From: =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= Organization: Applied Asynchrony, Inc. Message-ID: <51052162-6d79-f5c0-a811-b77587b51195@applied-asynchrony.com> Date: Wed, 8 Apr 2020 05:59:20 +0200 MIME-Version: 1.0 In-Reply-To: <03b3159b-e9ca-011d-d95c-6572cc07d895@roeck-us.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/7/20 3:41 AM, Guenter Roeck wrote: > On 4/6/20 9:23 AM, Holger Hoffstätte wrote: >> >> I've been giving the drivetemp hwmon driver a try and am very happy >> with it; works right away and - much to my surprise - doesn't wake up >> HDDs that have gone to sleep. Nice! >> >> I did notice one tiny thing though: after waking up from suspend, my SSD >> (Samsung 850 Pro) reports a few initial bogus values - suspiciously -128°, >> which is definitely not the temperature in my office. While this is more >> a cosmetic problem, it cramps my monitoring setup and leads to wrong graphs. >> Can't have that! >> >> So I looked into the source and found that the values are (understandably) >> passed on unfiltered/uncapped. Since it's unlikely any active device has >> operating temperature below-zero, I figured the laziest way is to cap the >> value to positive: >> >> diff -rup a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c >> --- a/drivers/hwmon/drivetemp.c    2020-04-02 08:02:32.000000000 +0200 >> +++ b/drivers/hwmon/drivetemp.c    2020-04-06 18:13:04.892554087 +0200 >> @@ -147,7 +147,7 @@ static LIST_HEAD(drivetemp_devlist); >>  #define INVALID_TEMP        0x80 >> >>  #define temp_is_valid(temp)    ((temp) != INVALID_TEMP) >> -#define temp_from_sct(temp)    (((s8)(temp)) * 1000) >> +#define temp_from_sct(temp)    (max(0, ((s8)(temp)) * 1000)) >> >>  static inline bool ata_id_smart_supported(u16 *id) >>  { >> >> The assumption is of course *theoretically* wrong since some >> equipment might indeed operate in negative C°. One way might be >> to use the device's "low" operating point first, but then that >> might not be available and we'd be back to capping to 0. >> I'm open to other suggestions. :) >> > > Looking into the code, 0x80 or -128 indeed reflects an invalid temperature. Excellent, that's of course much better than just capping to 0. > Any chance you can apply the following to see if it helps ? > > diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c > index 370d0c74eb01..c27239eb28cf 100644 > --- a/drivers/hwmon/drivetemp.c > +++ b/drivers/hwmon/drivetemp.c > @@ -264,6 +264,8 @@ static int drivetemp_get_scttemp(struct drivetemp_data *st, u32 attr, long *val) > return err; > switch (attr) { > case hwmon_temp_input: > + if (!temp_is_valid(buf[SCT_STATUS_TEMP])) > + return -ENODATA; > *val = temp_from_sct(buf[SCT_STATUS_TEMP]); > break; > case hwmon_temp_lowest: > > I am not sure what the best error code would be - suggestions welcome. Gave it a try and had to wait overnight for things to cool down (just suspending for an hour wouldn't do it). Right after wakeup sensors now shows "N/A" as expected, and no illegal values in drivetemp or my monitoring; missing values are perfectly fine. After a few minutes correct values show up and all is good. In case you submit this as official patch feel free to add my Reported-by/Tested-by. Thanks for looking into it! cheers Holger