From: Sergei Shtylyov <sshtylyov@mvista.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] disk/part.c: 'usb storage' avoiding overflow when output capacity
Date: Sun, 08 Aug 2010 14:01:10 +0400 [thread overview]
Message-ID: <4C5E8066.9020002@mvista.com> (raw)
In-Reply-To: <1281258332-28928-1-git-send-email-slyfox@inbox.ru>
Hello.
Sergei Trofimovich wrote:
> Before:
> Marvell>> usb storage
> Device 0: Vendor: StoreJet Rev: Prod: Transcend
> Type: Hard Disk
> Capacity: 28759.9 MB = 28.0 GB (488397168 x 512)
> After:
> Marvell>> usb storage
> Device 0: Vendor: StoreJet Rev: Prod: Transcend
> Type: Hard Disk
> Capacity: 238475.1 MB = 232.8 GB (488397168 x 512)
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> ---
> disk/part.c | 28 +++++++++++++++++++++++-----
> 1 files changed, 23 insertions(+), 5 deletions(-)
> diff --git a/disk/part.c b/disk/part.c
> index b6bae17..ee5be2b 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -109,14 +109,31 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
> /*
> * reports device info to the user
> */
> -void dev_print (block_dev_desc_t *dev_desc)
> -{
> +
> #ifdef CONFIG_LBA48
> - uint64_t lba512; /* number of blocks if 512bytes block size */
> +typedef uint64_t lba512_t;
> #else
> - lbaint_t lba512;
> +typedef lbaint_t lba512_t;
> #endif
>
> +/*
> + * Overflowless variant of (block_count * mul_by / div_by)
> + * when div_by > mul_by
> + */
> +static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
> +{
> + lba512_t bc_quot, bc_rem;
> +
> + /* x * m / d == x / d * m + (x % d) * m / d */
> + bc_quot = block_count / div_by;
> + bc_rem = block_count - div_by * bc_quot;
> + return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
Please use tabs to indent the code to match the style of that file.
WBR, Sergei
next prev parent reply other threads:[~2010-08-08 10:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-07 7:18 [U-Boot] 'usb start' works very unstable Sergei Trofimovich
2010-08-07 11:22 ` Wolfgang Denk
2010-08-07 13:39 ` Sergei Trofimovich
2010-08-07 15:47 ` Wolfgang Denk
2010-08-07 19:35 ` Prafulla Wadaskar
2010-08-07 20:57 ` Sergei Trofimovich
2010-08-08 9:05 ` [U-Boot] [PATCH] disk/part.c: 'usb storage' avoiding overflow when output capacity Sergei Trofimovich
2010-08-08 10:01 ` Sergei Shtylyov [this message]
2010-08-08 12:05 ` Sergei Trofimovich
2010-08-09 5:38 ` Prafulla Wadaskar
2010-08-09 18:19 ` Sergei Trofimovich
2010-08-10 21:10 ` Wolfgang Denk
2010-08-07 19:47 ` [U-Boot] 'usb start' works very unstable Prafulla Wadaskar
2010-08-07 22:27 ` Wolfgang Denk
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=4C5E8066.9020002@mvista.com \
--to=sshtylyov@mvista.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.