Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Murad Masimov <m.masimov@maxima.ru>
To: Eric Tremblay <etremblay@distech-controls.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>, <linux-hwmon@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org>,
	Murad Masimov <m.masimov@maxima.ru>
Subject: [PATCH 3/3] hwmon: (tmp513) Fix interpretation of values of Temperature Result and Limit Registers
Date: Mon, 16 Dec 2024 20:36:48 +0300	[thread overview]
Message-ID: <20241216173648.526-4-m.masimov@maxima.ru> (raw)
In-Reply-To: <20241216173648.526-1-m.masimov@maxima.ru>

The values returned by the driver after processing the contents of the
Temperature Result and the Temperature Limit Registers do not correspond to the
TMP512/TMP513 specifications. A raw register value is converted to a signed
integer value by a sign extension in accordance with the algorithm provided
in the specification, but due to the off-by-one error in the sign bit index,
the result is incorrect.

According to the TMP512 and TMP513 datasheets, the Temperature Result (08h to 0Bh)
and Limit (11h to 14h) Registers are 13-bit two's complement integer values,
shifted left by 3 bits. The value is scaled by 0.0625 degrees Celsius per bit.
E.g., if regval = 1 1110 0111 0000 000, the output should be -25 degrees,
but the driver will return +487 degrees.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 59dfa75e5d82 ("hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.")
Signed-off-by: Murad Masimov <m.masimov@maxima.ru>
---
 drivers/hwmon/tmp513.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
index dacce7417bfd..be63a049923a 100644
--- a/drivers/hwmon/tmp513.c
+++ b/drivers/hwmon/tmp513.c
@@ -234,7 +234,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
 	case TMP51X_REMOTE_TEMP_LIMIT_2:
 	case TMP513_REMOTE_TEMP_LIMIT_3:
 		// 1lsb = 0.0625 degrees centigrade
-		*val = sign_extend32(regval, 16) >> TMP51X_TEMP_SHIFT;
+		*val = sign_extend32(regval, 15) >> TMP51X_TEMP_SHIFT;
 		*val = DIV_ROUND_CLOSEST(*val * 625, 10);
 		break;
 	case TMP51X_N_FACTOR_AND_HYST_1:
--
2.39.2


      parent reply	other threads:[~2024-12-16 17:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16 17:36 [PATCH 0/3] hwmon: (tmp513) Fix interpretation of values of TMP513 registers Murad Masimov
2024-12-16 17:36 ` [PATCH 1/3] hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and Limit Registers Murad Masimov
2024-12-16 23:53   ` Guenter Roeck
2024-12-16 17:36 ` [PATCH 2/3] hwmon: (tmp513) Fix Current Register value interpretation Murad Masimov
2024-12-16 23:55   ` Guenter Roeck
2024-12-16 17:36 ` Murad Masimov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241216173648.526-4-m.masimov@maxima.ru \
    --to=m.masimov@maxima.ru \
    --cc=etremblay@distech-controls.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lvc-project@linuxtesting.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox