diff options
author | Dimitri Fedrau <dima.fedrau@gmail.com> | 2024-04-24 20:59:10 +0200 |
---|---|---|
committer | Jonathan Cameron <jonathan.cameron@huawei.com> | 2024-05-03 11:48:56 +0100 |
commit | 827dca3129708a8465bde90c86c2e3c38e62dd4f (patch) | |
tree | 04274c6c1e843e6b07de683cacc3dc405931d2ac /drivers/iio | |
parent | 51fafb3cd7fcf4f4682693b4d2883e2a5bfffe33 (diff) | |
download | linux-827dca3129708a8465bde90c86c2e3c38e62dd4f.tar.gz linux-827dca3129708a8465bde90c86c2e3c38e62dd4f.tar.bz2 linux-827dca3129708a8465bde90c86c2e3c38e62dd4f.zip |
iio: temperature: mcp9600: Fix temperature reading for negative values
Temperature is stored as 16bit value in two's complement format. Current
implementation ignores the sign bit. Make it aware of the sign bit by
using sign_extend32.
Fixes: 3f6b9598b6df ("iio: temperature: Add MCP9600 thermocouple EMF converter")
Signed-off-by: Dimitri Fedrau <dima.fedrau@gmail.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Tested-by: Andrew Hepp <andrew.hepp@ahepp.dev>
Link: https://lore.kernel.org/r/20240424185913.1177127-1-dima.fedrau@gmail.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/temperature/mcp9600.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c index 46845804292b..7a3eef5d5e75 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -52,7 +52,8 @@ static int mcp9600_read(struct mcp9600_data *data, if (ret < 0) return ret; - *val = ret; + + *val = sign_extend32(ret, 15); return 0; } |