From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms
Date: Tue, 30 Mar 2010 17:05:43 -0500 [thread overview]
Message-ID: <4BB275B7.90509@freescale.com> (raw)
In-Reply-To: <1269985996-13130-1-git-send-email-timur@freescale.com>
Timur Tabi wrote:
> 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 | 5 ++---
> 2 files changed, 3 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..cafb603 100644
> --- a/lib_generic/display_options.c
> +++ b/lib_generic/display_options.c
> @@ -43,10 +43,9 @@ 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, d = 1 << 30 /* 1 GB */;
> char c = 'G';
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 *"?
-Scott
next prev parent reply other threads:[~2010-03-30 22:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-30 21:53 [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms Timur Tabi
2010-03-30 22:05 ` Scott Wood [this message]
2010-03-30 22:08 ` Timur Tabi
2010-03-30 22:19 ` Scott Wood
2010-03-30 22:32 ` Timur Tabi
2010-03-30 22:39 ` Scott Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BB275B7.90509@freescale.com \
--to=scottwood@freescale.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.