From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79EEAC48BE5 for ; Tue, 15 Jun 2021 15:50:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64D5D61923 for ; Tue, 15 Jun 2021 15:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232425AbhFOPwi (ORCPT ); Tue, 15 Jun 2021 11:52:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:45708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbhFOPvu (ORCPT ); Tue, 15 Jun 2021 11:51:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 09FFC6148E; Tue, 15 Jun 2021 15:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623772185; bh=4N5XB1kMClR4uHWK6xi+bP3P4je3OwE/wcElNSnGzR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjCg3pDFyFqxulMyHHREhpDhhSEQDs8zRH4ELML63yLVY3n8c2anjmebE2R+O3sLX 4nkMA3U1LJJ2d45RB2/HABxkG+KLtyIFbBUVw2woBa5jG0+9eAyorP7BZ9EB4+5SC7 Rv9GjOoydx5SZ5dBM5NeKYakcmFdIa9Fi6rzulchV9mlfnIyYUUR0bO1BtDnqb6ipQ gCSEVJiTCgWrksaL83rCe35IYweCKPafEF/zEtwqtAlio32T3IWzsW99FdY2C4NLO5 j+wACulERn+Hy6ZDXRMIttE8SkDE7qEc6ykMY0bQg49XhSfsseOKnTCWZfDO9UHWaO XoARGyuCrXzZA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Riwen Lu , Xin Chen , Guenter Roeck , Sasha Levin , linux-hwmon@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 29/30] hwmon: (scpi-hwmon) shows the negative temperature properly Date: Tue, 15 Jun 2021 11:49:06 -0400 Message-Id: <20210615154908.62388-29-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210615154908.62388-1-sashal@kernel.org> References: <20210615154908.62388-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Riwen Lu [ Upstream commit 78d13552346289bad4a9bf8eabb5eec5e5a321a5 ] 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 Link: https://lore.kernel.org/r/20210604030959.736379-1-luriwen@kylinos.cn Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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.30.2