diff options
author | Alice Sheng <alicesheng@google.com> | 2022-10-04 16:46:34 -0700 |
---|---|---|
committer | Alice Sheng <alicesheng@google.com> | 2022-10-05 14:12:45 -0700 |
commit | 6fb04aba6f9cb2994abe092017d821cb4532a666 (patch) | |
tree | 6b7925fa5a9c928f90e8ea273772bb43f0e08f08 | |
parent | 7871fc5719b3d20b2b1bbff632e741a1312143ae (diff) | |
download | drivers-android-exynos-r11-4.19-android11-wear-jr2.tar.gz |
ntc-thermal: fix NTC reading comparisonandroid-wear-11.0.0_r0.6android-wear-11.0.0_r0.5android-wear-11.0.0_r0.4android-exynos-r11-4.19-android11-wear-jr2
Compare it to the previous check, not just the last reading. This will
prevent false positives for errors in cases where the temperature
actually jumped a lot.
Bug: 250564489
Change-Id: I19844854ad64d3d2f90701670731c9ef0d8e7caf
-rw-r--r-- | battery/ntc-thermal.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/battery/ntc-thermal.c b/battery/ntc-thermal.c index 60e3522..3f9df74 100644 --- a/battery/ntc-thermal.c +++ b/battery/ntc-thermal.c @@ -103,10 +103,17 @@ static int ntc_thermal_try_temp(struct ntc_sensor *ntc_sensor, int* temp) diff = *temp - ntc_sensor->prev_temp; else diff = ntc_sensor->prev_temp - *temp; - if (ntc_sensor->prev_temp != -INT_MIN && diff > NTC_ERROR_DIFFERENCE) { - dev_err(ntcdev->dev, "IIO channel returned unusual temperature %d, prev_temp %d\n", *temp, ntc_sensor->prev_temp); - // Treat too different of a temperature as a NTC error - return -EINVAL; + if (*temp == ntcdev->lookup_table[ntcdev->nlookup_table - 1].temp) { + // Always treat max NTC value as a NTC error + dev_err(ntcdev->dev, "IIO channel returned unusual temperature %d\n", *temp); + ret = -EINVAL; + } else { + if (ntc_sensor->prev_temp != -INT_MIN && diff > NTC_ERROR_DIFFERENCE) { + dev_err(ntcdev->dev, "IIO channel returned unusual temperature %d, prev_temp %d\n", *temp, ntc_sensor->prev_temp); + // Treat too different of a temperature as a NTC error + ret = -EINVAL; + } + ntc_sensor->prev_temp = *temp; } return ret; @@ -125,7 +132,6 @@ static int ntc_thermal_get_temp(void *data, int *temp) msleep(10); ret = ntc_thermal_try_temp(ntc_sensor, temp); } - ntc_sensor->prev_temp = *temp; if (ret < 0) { return ret; |