From: Adam Rizkalla <ajarizzo@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Vasileios Amoiridis <vassilisamir@gmail.com>,
linux-iio@vger.kernel.org, Adam Rizkalla <ajarizzo@gmail.com>
Subject: [PATCH] iio: pressure: bmp280: fix bmp580 temp read
Date: Sun, 2 Jun 2024 15:12:01 -0500 [thread overview]
Message-ID: <20240602201200.30418-1-ajarizzo@gmail.com> (raw)
Fix overflow when storing bmp580 temperature reading and preserve sign.
This patch re-applies the fix in [1] after the merge conflict resolution
mentioned in [2].
[1] https://lore.kernel.org/all/Zin2udkXRD0+GrML@adam-asahi.lan/
[2] https://lore.kernel.org/linux-kernel/20240531140621.264f0848@canb.auug.org.au/
Signed-off-by: Adam Rizkalla <ajarizzo@gmail.com>
---
drivers/iio/pressure/bmp280-core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 95c88b0e1c49..3a003843c79c 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -1752,6 +1752,8 @@ static int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp)
dev_err(data->dev, "reading temperature skipped\n");
return -EIO;
}
+ *raw_temp = sign_extend32(*raw_temp, 23);
+ *raw_temp = ((s64)*raw_temp * 1000) / (1 << 16);
return 0;
}
@@ -2154,7 +2156,7 @@ static irqreturn_t bmp580_buffer_handler(int irq, void *p)
static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT };
-static const int bmp580_temp_coeffs[] = { 1000, 16 };
+static const int bmp580_temp_coeffs[] = { 1, 0 };
static const int bmp580_press_coeffs[] = { 1, 64000};
const struct bmp280_chip_info bmp580_chip_info = {
@@ -2184,7 +2186,7 @@ const struct bmp280_chip_info bmp580_chip_info = {
.iir_filter_coeff_default = 2,
.temp_coeffs = bmp580_temp_coeffs,
- .temp_coeffs_type = IIO_VAL_FRACTIONAL_LOG2,
+ .temp_coeffs_type = IIO_VAL_INT,
.press_coeffs = bmp580_press_coeffs,
.press_coeffs_type = IIO_VAL_FRACTIONAL,
--
2.40.1
next reply other threads:[~2024-06-02 20:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-02 20:12 Adam Rizkalla [this message]
2024-06-04 19:01 ` [PATCH] iio: pressure: bmp280: fix bmp580 temp read Jonathan Cameron
2024-06-04 19:19 ` Vasileios Amoiridis
2024-06-17 19:57 ` Jonathan Cameron
2024-06-17 20:30 ` Vasileios Amoiridis
2024-06-17 23:23 ` Vasileios Amoiridis
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=20240602201200.30418-1-ajarizzo@gmail.com \
--to=ajarizzo@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=vassilisamir@gmail.com \
/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