Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/string_helpers.c:string_get_size(): use 32 bit arithmetic when possible

The remainder from do_div is always a u32, and after size has been reduced
to be below 1000 (or 1024), it certainly fits in u32. So both remainder
and sf_cap can be made u32s, the format specifiers can be simplified (%lld
wasn't the right thing to use for _unsigned_ long long anyway), and we can
replace a do_div with an ordinary 32/32 bit division.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Rasmus Villemoes and committed by
Linus Torvalds
84b9fbed 7eed8fde

+4 -5
+4 -5
lib/string_helpers.c
··· 42 42 [STRING_UNITS_2] = 1024, 43 43 }; 44 44 int i, j; 45 - u64 remainder = 0, sf_cap; 45 + u32 remainder = 0, sf_cap; 46 46 char tmp[8]; 47 47 48 48 tmp[0] = '\0'; ··· 59 59 60 60 if (j) { 61 61 remainder *= 1000; 62 - do_div(remainder, divisor[units]); 63 - snprintf(tmp, sizeof(tmp), ".%03lld", 64 - (unsigned long long)remainder); 62 + remainder /= divisor[units]; 63 + snprintf(tmp, sizeof(tmp), ".%03u", remainder); 65 64 tmp[j+1] = '\0'; 66 65 } 67 66 } 68 67 69 - snprintf(buf, len, "%lld%s %s", (unsigned long long)size, 68 + snprintf(buf, len, "%u%s %s", (u32)size, 70 69 tmp, units_str[units][i]); 71 70 72 71 return 0;