drivers: iio: pressure: dps310: Fix failure to read negative numbers
Subsystems (2)
PATCH 1/1 drivers: iio: pressure: dps310: Fix failure to read negative numbers
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 <[email protected]>
--- drivers/iio/pressure/dps310.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/iio/pressure/dps310.c +5 -4
@@ -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 :
Signature · 1 line
2.34.1