[U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms

Scott Wood scottwood at freescale.com
Wed Mar 31 00:19:29 CEST 2010


Timur Tabi wrote:
> Scott Wood wrote:
>> In changing "d" from phys_size_t to unsigned long, I think you're 
>> introducing overflow in "n * d" (consider 5.5G rather than 1.5G).
>>
>> Wouldn't a more straightforward fix, that doesn't affect the function 
>> signature, be to just change "10 *" to "10ULL *"?
> 
> I don't see how that suggestion would make the code any different.

It would make the 10 * (...) product 64-bit regardless of phys_size_t, 
without changing the function signature (overflow is an internal 
implementation detail).

>  Here's the expression:
> 
> 	(10 * (size - (n * d)) + (d / 2) ) / d;
> 
> I made 'size' into a u64, and I assume that the compiler will evaluate every other subexpression as a u64.  That may be wrong.

The "n * d" subexpression does not involve size, and thus will not be 
64-bit.

> However, changing 10 to 10ULL makes the same assumption.

The difference is that "d" remains phys_size_t, rather than being 
converted to unsigned long.

-Scott


More information about the U-Boot mailing list