Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp771342pxj; Thu, 3 Jun 2021 20:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYv7VU2MoSCj2Dm52NibWz7h+TZ7Z/U5yQlPCswoUdMtUVWk7+bgOGo0mZzTCWnltKbVZM X-Received: by 2002:a05:6402:34c8:: with SMTP id w8mr2440990edc.243.1622776360821; Thu, 03 Jun 2021 20:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622776360; cv=none; d=google.com; s=arc-20160816; b=YWgbL/jWmce/Q/zWrJp7D+G5fsOZuRDUYjyctskAgWuHFbk3sJgWjxxPr+QZ3Ops2V cqQInJL9eO3SNcl3FyV40Fn9a9h/lUBd+or+ofDfbJfB13FAirndIb626ycUrCfa0I7S HhXtDo77XHFI/oFWb/yV9Nd7MTYm4c+jZjkhfQ7seP4dkxr0FxE3eJLh/pviw1wyypuv fibdz9oTI6CLrtQl7uB7dzU/F0s1zI4tlfle/v7C/t0JL029bKa3BFyB1WIiCJlR3TVH LoyEzsAFH20d2vG2zYg8DKLyyKT6nRZwRVTCP4Sb27FS+HNPBGnOSKBkY+JmDI88ISME A6Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6ag1hom8d5Wj8VOtacASrCLGo7rtuyGn2UMrZjYRDTo=; b=FkftzjMgy7/EpJ0ZbHE407e+a2/0ovIOLxb6h6m/M3CngRsZy/+yj8EwXxlFTAUPwy q5SLd4UYuIk2LIP2xtBUJdyLWpA5zD7smHKpLUC6BtW0i4VnnTx9XsU/BAR/nB70hIcW cYYrxpPtM1nWcE5YTz/YWSIRmh16oSdA2cL3vFeHKi5g3eynZuz9fcTkl6G5YwGY6jxw Wi8zZqYDnbqqeX88lXJQ2Htbg2Io+Xb1Dj88S2rvOPAq+PedFaKyXbHAaG0RXcPIaK0n iz4a476OYzKlL2QEyuf9gyXzYyAjN5/+tWjUz8CC0gdpDrP+uUqRwWk0QopzZidndSpi ZVBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o15si3536047edr.335.2021.06.03.20.12.15; Thu, 03 Jun 2021 20:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbhFDDLv (ORCPT + 99 others); Thu, 3 Jun 2021 23:11:51 -0400 Received: from mailgw.kylinos.cn ([123.150.8.42]:47092 "EHLO nksmu.kylinos.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229718AbhFDDLu (ORCPT ); Thu, 3 Jun 2021 23:11:50 -0400 X-UUID: da0bcbaed8fc4653ab6935434e2e54ea-20210604 X-UUID: da0bcbaed8fc4653ab6935434e2e54ea-20210604 X-User: luriwen@kylinos.cn Received: from localhost.localdomain [(116.128.244.169)] by nksmu.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 5188936; Fri, 04 Jun 2021 11:09:45 +0800 From: Riwen Lu To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Riwen Lu , Xin Chen Subject: [PATCH v3] hwmon: (scpi-hwmon) shows the negative temperature properly Date: Fri, 4 Jun 2021 11:09:59 +0800 Message-Id: <20210604030959.736379-1-luriwen@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The scpi hwmon shows the sub-zero temperature in an unsigned integer, which would confuse the users when the machine works in low temperature environment. This shows the sub-zero temperature in an signed value and users can get it properly from sensors. Signed-off-by: Riwen Lu Tested-by: Xin Chen --- Changes since v1: - Add judgment for sensor->info.class. If it is TEMPERATURE situation, return the sensor value as a signed value, otherwise return it as a unsigned value. Changes since v2: - Add a typecast u64 to s64 when it is a temperature value. - Add a comment ahead of the if statement. - Remove the unnecessary 'else' statement. --- drivers/hwmon/scpi-hwmon.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c index 25aac40f2764..919877970ae3 100644 --- a/drivers/hwmon/scpi-hwmon.c +++ b/drivers/hwmon/scpi-hwmon.c @@ -99,6 +99,15 @@ scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf) scpi_scale_reading(&value, sensor); + /* + * Temperature sensor values are treated as signed values based on + * observation even though that is not explicitly specified, and + * because an unsigned u64 temperature does not really make practical + * sense especially when the temperature is below zero degrees Celsius. + */ + if (sensor->info.class == TEMPERATURE) + return sprintf(buf, "%lld\n", (s64)value); + return sprintf(buf, "%llu\n", value); } -- 2.25.1 No virus found Checked by Hillstone Network AntiVirus