From 5572d9410074b56ad25d35b0d3e17c93d8dbaeb0 Mon Sep 17 00:00:00 2001 From: Mikhail Kshevetskiy Date: Sat, 1 Nov 2025 09:24:23 +0300 Subject: [PATCH] cmd: mtd: benchmark: use lldiv() instead of 64-bit division As was noted by Heinrich Schuchardt, some SoCs may not support 64-bit divisions. Fix an issue by using lldiv() instead. The code assumes that the benchmark never takes more than 4294 seconds and thus the difference will be less than U32_MAX. Also replace (speed / 1024) by (speed >> 10) to avoid potential 64-bit division. Signed-off-by: Mikhail Kshevetskiy --- cmd/mtd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/mtd.c b/cmd/mtd.c index d0072129659..7f25144098b 100644 --- a/cmd/mtd.c +++ b/cmd/mtd.c @@ -10,6 +10,7 @@ #include #include +#include #include #if CONFIG_IS_ENABLED(CMD_MTD_OTP) #include @@ -595,10 +596,10 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, if (benchmark && bench_start) { bench_end = timer_get_us(); - speed = (len * 1000000) / (bench_end - bench_start); + speed = lldiv(len * 1000000, bench_end - bench_start); printf("%s speed: %lukiB/s\n", read ? "Read" : "Write", - (unsigned long)(speed / 1024)); + (unsigned long)(speed >> 10)); } led_activity_off(); -- 2.47.3