From: David Lambert <dave@lambsys.com>
To: dedekind1@gmail.com
Cc: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: Re: Bug in mtd_speedtest?
Date: Fri, 04 Mar 2011 11:53:18 -0600 [thread overview]
Message-ID: <4D71270E.9030204@lambsys.com> (raw)
In-Reply-To: <1299221982.2735.7.camel@localhost>
[-- Attachment #1: Type: text/plain, Size: 586 bytes --]
Artem,
Please find attached patch.
Regards,
Dave.
On 03/04/2011 12:59 AM, Artem Bityutskiy wrote:
> On Thu, 2011-03-03 at 17:45 -0600, David Lambert wrote:
>> I think I may have found an overflow condition in the speed calculation
>> of mtd_speedtest on some platforms with larger flash partitions:
>>
>> Consider for example if goodebcnt = 15000, and mtd->erasesize =
>> 256*1024, then there is an intermediate product of 3932160000 which
>> results in the sign bit being set on a 32 bit integer. Maybe k should be
>> an unsigned long long?
> Please, just send a patch :-)
>
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1006 bytes --]
Index: mtd_speedtest.c
===================================================================
RCS file: /home/cvsroot/ECMB/src/snapgear/linux-2.6.30.1.x/drivers/mtd/tests/mtd_speedtest.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 mtd_speedtest.c
--- mtd_speedtest.c 10 Aug 2009 19:42:00 -0000 1.1.1.1
+++ mtd_speedtest.c 4 Mar 2011 17:51:23 -0000
@@ -281,13 +281,14 @@
static long calc_speed(void)
{
- long ms, k, speed;
+ uint64_t k;
+ long ms;
- ms = (finish.tv_sec - start.tv_sec) * 1000 +
- (finish.tv_usec - start.tv_usec) / 1000;
- k = goodebcnt * mtd->erasesize / 1024;
- speed = (k * 1000) / ms;
- return speed;
+ ms = (finish.tv_sec - start.tv_sec) * 1000 + /* Time in milli-seconds from start to ...*/
+ (finish.tv_usec - start.tv_usec) / 1000; /* finish */
+ k = (goodebcnt * (mtd->erasesize / 1024) * 1000); /* Number of kBytes transferred * 1000 */
+ do_div(k, ms); /* k now contains number of kBytes/second */
+ return k;
}
static int scan_for_bad_eraseblocks(void)
next prev parent reply other threads:[~2011-03-04 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-03 23:45 Bug in mtd_speedtest? David Lambert
2011-03-04 6:59 ` Artem Bityutskiy
2011-03-04 17:53 ` David Lambert [this message]
2011-03-07 4:11 ` Jon Povey
2011-03-07 10:09 ` Artem Bityutskiy
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=4D71270E.9030204@lambsys.com \
--to=dave@lambsys.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox