]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: ubiformat.c: convert to integer arithmetic
authorAndrea Adami <andrea.adami@gmail.com>
Mon, 29 Jan 2018 22:07:12 +0000 (23:07 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Tue, 30 Jan 2018 08:24:22 +0000 (09:24 +0100)
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 <andrea.adami@gmail.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubi-utils/ubiformat.c

index ef0378a63403c53c73d05276830cfaf42b0c69de..c38b9b4abb1638d4d53e344bf7be1c1e09f411d6 100644 (file)
@@ -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