public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] [v2] fix print_size printing fractional gigabyte numbers on 32-bit platforms
@ 2010-03-30 22:34 Timur Tabi
  2010-03-30 22:43 ` Scott Wood
  0 siblings, 1 reply; 3+ messages in thread
From: Timur Tabi @ 2010-03-30 22:34 UTC (permalink / raw)
  To: u-boot

In print_size(), the math that calculates the fractional remainder of a number
used the same integer size as a physical address.  However, the "10 *" factor
of the algorithm means that a large number (e.g. 1.5GB) can overflow the
integer if we're running on a 32-bit system.  Therefore, we need to
disassociate this function from the size of a physical address.

Signed-off-by: Timur Tabi <timur@freescale.com>
---
 include/common.h              |    2 +-
 lib_generic/display_options.c |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/common.h b/include/common.h
index a133e34..4e77727 100644
--- a/include/common.h
+++ b/include/common.h
@@ -218,7 +218,7 @@ void	hang		(void) __attribute__ ((noreturn));
 /* */
 phys_size_t initdram (int);
 int	display_options (void);
-void	print_size (phys_size_t, const char *);
+void	print_size(unsigned long long, const char *);
 int	print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
 
 /* common/main.c */
diff --git a/lib_generic/display_options.c b/lib_generic/display_options.c
index 2dc2567..da17a62 100644
--- a/lib_generic/display_options.c
+++ b/lib_generic/display_options.c
@@ -43,10 +43,10 @@ int display_options (void)
  * xxx GB, or xxx.y GB as needed; allow for optional trailing string
  * (like "\n")
  */
-void print_size (phys_size_t size, const char *s)
+void print_size(unsigned long long size, const char *s)
 {
-	ulong m = 0, n;
-	phys_size_t d = 1 << 30;		/* 1 GB */
+	unsigned long m = 0, n;
+	unsigned long long d = 1 << 30; 	/* 1 GB */
 	char  c = 'G';
 
 	if (size < d) {			/* try MB */
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-30 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-30 22:34 [U-Boot] [PATCH] [v2] fix print_size printing fractional gigabyte numbers on 32-bit platforms Timur Tabi
2010-03-30 22:43 ` Scott Wood
2010-03-30 22:52   ` Timur Tabi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox