Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantell...@idf-hit.com>
---
 lib/display_options.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/display_options.c b/lib/display_options.c
index 86df05d..eca5415 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -45,14 +45,14 @@ int display_options (void)
  */
 void print_size(unsigned long long size, const char *s)
 {
-       unsigned long m = 0, n;
+       unsigned long m = 0, n, rem;
        static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
-       unsigned long long d = 1ULL << (10 * ARRAY_SIZE(names));
+       unsigned int d_shift = 10 * ARRAY_SIZE(names);
        char c = 0;
        unsigned int i;
 
-       for (i = 0; i < ARRAY_SIZE(names); i++, d >>= 10) {
-               if (size >= d) {
+       for (i = 0; i < ARRAY_SIZE(names); i++, d_shift -= 10) {
+               if (size >= (1ULL << d_shift)) {
                        c = names[i];
                        break;
                }
@@ -63,11 +63,12 @@ void print_size(unsigned long long size, const char *s)
                return;
        }
 
-       n = size / d;
+       n = size >> d_shift;
+       rem = size - (n << d_shift);
 
        /* If there's a remainder, deal with it */
-       if(size % d) {
-               m = (10 * (size - (n * d)) + (d / 2) ) / d;
+       if(rem) {
+               m = (10 * rem + (1ULL << (d_shift -1 ))) >> d_shift;
 
                if (m >= 10) {
                        m -= 10;
-- 
1.7.0.5

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to