From c75d1044ea8a04e6808e20814a92beb8657c8f95 Mon Sep 17 00:00:00 2001 From: Andrea Adami Date: Mon, 29 Jan 2018 23:07:12 +0100 Subject: ubi-utils: ubiformat.c: convert to integer arithmetic Do not cast percent to double, it is just used as upper limit. Avoid floating point to fix compilation for aarch64 against klibc: error: '-mgeneral-regs-only' is incompatible with floating-point code | int percent = ((double)si->ok_cnt)/si->good_cnt * 100; | ^~~~~~~ Notes: * The checks in the code above this line ensure that si->good_cnt is not 0. * The code assumes si->good_cnt * 100 will not overflow, then we can use (si->ok_cnt * 100) safely because the former is bigger. * The truncated result does not affect the logic: i.e. a value of 49.9 is truncated to 49 and is still <50. Signed-off-by: Andrea Adami Signed-off-by: David Oberhollenzer --- ubi-utils/ubiformat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ubi-utils') diff --git a/ubi-utils/ubiformat.c b/ubi-utils/ubiformat.c index ef0378a..c38b9b4 100644 --- a/ubi-utils/ubiformat.c +++ b/ubi-utils/ubiformat.c @@ -844,7 +844,7 @@ int main(int argc, char * const argv[]) } if (!args.override_ec && si->empty_cnt < si->good_cnt) { - int percent = ((double)si->ok_cnt)/si->good_cnt * 100; + int percent = (si->ok_cnt * 100) / si->good_cnt; /* * Make sure the majority of eraseblocks have valid -- cgit v1.2.3