From 6a4514ddc070f4df39be3d11425dba94e891e81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Stenberg?= Date: Wed, 6 Mar 2024 13:52:57 +0100 Subject: [PATCH] adc: Use int64_t in voltage divider calculation to avoid overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit int32_t overflows above 1.3kOhm if using vref 3300 mV. Signed-off-by: Björn Stenberg --- include/zephyr/drivers/adc/voltage_divider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/drivers/adc/voltage_divider.h b/include/zephyr/drivers/adc/voltage_divider.h index 692442d4b3..caf6f821ff 100644 --- a/include/zephyr/drivers/adc/voltage_divider.h +++ b/include/zephyr/drivers/adc/voltage_divider.h @@ -51,7 +51,7 @@ static inline int voltage_divider_scale_dt(const struct voltage_divider_dt_spec } /* voltage scaled by voltage divider values using DT binding */ - *v_to_v = *v_to_v * spec->full_ohms / spec->output_ohms; + *v_to_v = (int64_t)*v_to_v * spec->full_ohms / spec->output_ohms; return 0; }