Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3463870ybb; Mon, 6 Apr 2020 09:24:01 -0700 (PDT) X-Google-Smtp-Source: APiQypLl4BgjA+Z6Ysrapn1MeK3svPiKUTVInwqihAw8eOvfJKJhO1DaOLkj3BqET3QBX3PoGxZx X-Received: by 2002:aca:dc44:: with SMTP id t65mr81328oig.176.1586190241526; Mon, 06 Apr 2020 09:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586190241; cv=none; d=google.com; s=arc-20160816; b=TqSrYHfT9qTSFQoqhwjQQt1aQcy2plKtOnYhs/3c98hHJKPNaC/aSgvyHBKXUyLpwu B6iDZVoNcs6rh1a9agbBIrYa5qxSTjV7ZHq3Kdr35MwpFeOO007tOWVEiXZWRHfv0hui YubFsrbqOo7qwom1UzRPoK331MF5BJupxoqKb4Jb5nG1yALYsTWa72VMCjCuQjuPWFLr 4UD9dek32BNeIpUtwShbnMWZ30fLmCrLQx3jsNmRAq2i4JhJX27Q24SCWHTcd3r4uqdj secsfntE1J+LyiNbvdCvCobEkcZ1bBLFkRX5x1WJA+YU8XZ9qIt+KCZOXlRUnIcSEC3o zzxw== 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:mime-version:date:message-id:organization:subject :from:to; bh=0sBKteNjgvapymAAx3MNNFwjmDTUTcbLSpTzAvZj5Rw=; b=KMtcntFvg6yDbkkjjm5e0Bt/pldrFR4R1mNph2dzLQ7KwHI201dFKA+hKZIgtKZost Zykf7uU4HqA/+tmwu149qux0uqyDKAHteyLOmM2kdN3H3hnFJWdVsm+svOQOOCF3FOXw NYvMgpKKxxbZFkGoRVIrV+vRqYDUFn2t1/vD0Rj+f974VFhbw+oD31UsA58PYbivXkHR YR9k7PI0/IjskANM+ZawpGcjj1vrhmPkFbtDZOoQS11d2Bcggo3vyjR4Lm0fz4It1wE3 2vIMT0oYSlPzPLPD+0+QB2o3pdOMg81NlHklCMX6OxQ50JafXuPGHB/pKxgOgnnS62dI roeQ== 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 x14si4557ooc.26.2020.04.06.09.23.47; Mon, 06 Apr 2020 09:24:01 -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 S1729198AbgDFQXC (ORCPT + 99 others); Mon, 6 Apr 2020 12:23:02 -0400 Received: from mail.itouring.de ([188.40.134.68]:39532 "EHLO mail.itouring.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728924AbgDFQXC (ORCPT ); Mon, 6 Apr 2020 12:23:02 -0400 Received: from tux.applied-asynchrony.com (p5B07E2B3.dip0.t-ipconnect.de [91.7.226.179]) by mail.itouring.de (Postfix) with ESMTPSA id 5C7D04161A57; Mon, 6 Apr 2020 18:23:01 +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 18391F01600; Mon, 6 Apr 2020 18:23:01 +0200 (CEST) To: LKML , Guenter Roeck From: =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= Subject: hwmon: drivetemp: bogus values after wake up from suspend Organization: Applied Asynchrony, Inc. Message-ID: <1af049a1-63ae-ee55-05d5-0e55eb00bd0e@applied-asynchrony.com> Date: Mon, 6 Apr 2020 18:23:01 +0200 MIME-Version: 1.0 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 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. :) thanks, Holger