From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sergei Shtylyov Date: Sun, 08 Aug 2010 14:01:10 +0400 Subject: [U-Boot] [PATCH] disk/part.c: 'usb storage' avoiding overflow when output capacity In-Reply-To: <1281258332-28928-1-git-send-email-slyfox@inbox.ru> References: <20100807235701.5d441ca5@mosly> <1281258332-28928-1-git-send-email-slyfox@inbox.ru> Message-ID: <4C5E8066.9020002@mvista.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > --- > 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