diff options
author | Yuval Peress <peress@chromium.org> | 2021-03-05 12:14:19 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-05 21:52:19 +0000 |
commit | 8676038c098e1cfb0d27bcd743164c924a853c31 (patch) | |
tree | b8854c74f3c7b1fd020dc3f9fb8ca60ba1dc3e39 | |
parent | 66bb29e13fdd61733c411b12e584cd5007ceb47b (diff) | |
download | chrome-ec-8676038c098e1cfb0d27bcd743164c924a853c31.tar.gz |
zephyr: adc: add error check for adc_read()
adc_read() shouldn't ignore the return value. It is possible that
calling adc_raw_to_millivolts() is invalid if the read command
failed.
BRANCH=none
BUG=none
TEST=build/flash volteer and run adc command
Signed-off-by: Yuval Peress <peress@chromium.org>
Change-Id: Id668811f0f00e1f3d59a084354171c938ae6751e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2739708
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/shim/src/adc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c index 6f5a7d58de..3ceb7c4cc8 100644 --- a/zephyr/shim/src/adc.c +++ b/zephyr/shim/src/adc.c @@ -30,7 +30,7 @@ SYS_INIT(init_device_bindings, POST_KERNEL, 51); int adc_read_channel(enum adc_channel ch) { - int ret = 0; + int ret = 0, rv; struct adc_sequence seq = { .options = NULL, .channels = BIT(adc_channels[ch].input_ch), @@ -41,7 +41,10 @@ int adc_read_channel(enum adc_channel ch) .calibrate = false, }; - adc_read(adc_dev, &seq); + rv = adc_read(adc_dev, &seq); + if (rv) + return rv; + adc_raw_to_millivolts(adc_ref_internal(adc_dev), ADC_GAIN_1, CONFIG_PLATFORM_EC_ADC_RESOLUTION, &ret); return ret; |