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=unavailable 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 20C09C48BDF for ; Tue, 15 Jun 2021 15:54:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F28F560FE9 for ; Tue, 15 Jun 2021 15:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbhFOP4u (ORCPT ); Tue, 15 Jun 2021 11:56:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:47234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232261AbhFOPxA (ORCPT ); Tue, 15 Jun 2021 11:53:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9CDEC6142E; Tue, 15 Jun 2021 15:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623772226; bh=wRJuFAUKBN9IqlvNRNlL4iFilXRpZrVKLPOlZFTk0FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FOA5D6VWKFX3+NSinWuk4/INot03nc1j2aarjphbeOJx8utK8NRUwJgvmfLcFJPRK E3CK80OHZeLd4A8UejcTWS5DdsZItauRtSQloIXdB2AhgMPXrXUqBlCWDyWSCisMcA CJY8OQizO6PU4CprQlVZ7nUoTawwNEBRZ+MiIEK1ljQ/0CDscTFF0HiJM2OLRTAtQy 2ksAaIb4oG6rJl9z45A+zTdCrpx3Bm6XokpwLlFwcKJ9/bNX/RqlLjoFGA8Y8W7lCL W4FcdJjxXLHrLfuvUdKfyiD/IM+tQmAF9+j+iHz8sUDU9CMVEx9+htFeV8CaoARdud C5bImN2kia8sw== 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 4.19 12/12] hwmon: (scpi-hwmon) shows the negative temperature properly Date: Tue, 15 Jun 2021 11:50:09 -0400 Message-Id: <20210615155009.62894-12-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210615155009.62894-1-sashal@kernel.org> References: <20210615155009.62894-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-kernel@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 7e49da50bc69..562f3e287297 100644 --- a/drivers/hwmon/scpi-hwmon.c +++ b/drivers/hwmon/scpi-hwmon.c @@ -107,6 +107,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