From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Tue, 30 Mar 2010 17:19:29 -0500 Subject: [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms In-Reply-To: <4BB2766F.9070808@freescale.com> References: <1269985996-13130-1-git-send-email-timur@freescale.com> <4BB275B7.90509@freescale.com> <4BB2766F.9070808@freescale.com> Message-ID: <4BB278F1.40705@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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