From: George Liu <liuxiwei1013@gmail.com>
To: openbmc@lists.ozlabs.org, joel@jms.id.au
Subject: [PATCH] drivers: iio: pressure: dps310: Fix failure to read negative numbers
Date: Thu, 1 Feb 2024 16:52:04 +0800 [thread overview]
Message-ID: <20240201085204.202822-1-liuxiwei@ieisystem.com> (raw)
The dps310 chip driver fails to read the temperature when the
temperature reaches below zero.
The dps310_calculate_temp method will return the current temperature
(rc). If the temperature drops to 0 degrees, then rc < 0, it will
return directly without assigning a value to `val`.
Tested: When the temperature reaches below 0 degrees
1. without this patch:
```
cat /sys/bus/i2c/drivers/dps310/7-0076/iio\:device2/in_temp_input
cat: read error: Unknown error 2370
```
2. with this patch:
```
cat /sys/bus/i2c/drivers/dps310/7-0076/iio\:device2/in_temp_input
cat: read error: Unknown error -3370
```
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
---
drivers/iio/pressure/dps310.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 1ff091b2f764..fcbfdc5e85b7 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -730,7 +730,7 @@ static int dps310_read_pressure(struct dps310_data *data, int *val, int *val2,
}
}
-static int dps310_calculate_temp(struct dps310_data *data)
+static int dps310_calculate_temp(struct dps310_data *data, int *val)
{
s64 c0;
s64 t;
@@ -746,7 +746,9 @@ static int dps310_calculate_temp(struct dps310_data *data)
t = c0 + ((s64)data->temp_raw * (s64)data->c1);
/* Convert to milliCelsius and scale the temperature */
- return (int)div_s64(t * 1000LL, kt);
+ *val = (int)div_s64(t * 1000LL, kt);
+
+ return 0;
}
static int dps310_read_temp(struct dps310_data *data, int *val, int *val2,
@@ -768,11 +770,10 @@ static int dps310_read_temp(struct dps310_data *data, int *val, int *val2,
if (rc)
return rc;
- rc = dps310_calculate_temp(data);
+ rc = dps310_calculate_temp(data, val);
if (rc < 0)
return rc;
- *val = rc;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
--
2.34.1
next reply other threads:[~2024-02-01 8:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 8:52 George Liu [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-02-01 8:25 [PATCH] drivers: iio: pressure: dps310: Fix failure to read negative numbers George Liu
2024-02-01 8:32 ` Paul Menzel
2024-02-01 8:52 ` George Liu
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=20240201085204.202822-1-liuxiwei@ieisystem.com \
--to=liuxiwei1013@gmail.com \
--cc=joel@jms.id.au \
--cc=openbmc@lists.ozlabs.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).