From e59e38532ab43be003fade4c50a79d92c6376d04 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 12 Jan 2023 18:03:57 +0100 Subject: [PATCH] drivers: regulator: shell: fix fp number parsing Parser did not handle decimals correctly (multiplier was not decreased). Signed-off-by: Gerard Marull-Paretas --- drivers/regulator/regulator_shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/regulator_shell.c b/drivers/regulator/regulator_shell.c index 2e453b9701d..190130ec7c3 100644 --- a/drivers/regulator/regulator_shell.c +++ b/drivers/regulator/regulator_shell.c @@ -54,10 +54,13 @@ static int strtomicro(char *inp, char units, int32_t *val) /* numeric part */ *val = 0; - for (size_t i = start; i <= end; i++) { + for (size_t i = start; (i <= end) && (decdiv <= mult); i++) { if (isdigit((unsigned char)inp[i]) > 0) { *val = *val * 10 / decdiv + (int32_t)(inp[i] - '0') * mult / decdiv; + if (decdiv > 1) { + mult /= 10; + } } else if (inp[i] == '.') { decdiv = 10; } else {