linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd-utils: flash_erase: Fix output of offsets
@ 2010-10-16 20:54 Brian Norris
  2010-10-16 21:24 ` Mike Frysinger
  2010-10-17  8:04 ` Artem Bityutskiy
  0 siblings, 2 replies; 3+ messages in thread
From: Brian Norris @ 2010-10-16 20:54 UTC (permalink / raw)
  To: linux-mtd
  Cc: Kevin Cernekee, Brian Norris, David Woodhouse, Mike Frysinger,
	Artem Bityutskiy

Need to use unsigned arithmetic and a 64-bit cast in order to
calculate and output the correct offset for eraseblocks at large
offsets. Signed integer arithmetic does not produce the correct
result "uint64_t" result, so for offsets over 2GB we get
messages like:

	Erasing 512 Kibyte @ ffffffff83180000 -- 4308642136 % complete.

Note that this error was not affecting proper erasure; it just
produced incorrect status messages.

Also, we should not add an extra eraseblock for the final status
message; this gives misleading output when, for example, the
following statement is executed:

	$ flash_erase /dev/mtd0 0 1
	Erasing 512 Kibyte @ 80000 -- 100 % complete

We aren't erasing at offset 0x80000; it should display offset 0.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 flash_erase.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/flash_erase.c b/flash_erase.c
index 8929054..1a7b52e 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -93,7 +93,8 @@ int main(int argc, char *argv[])
 {
 	libmtd_t mtd_desc;
 	struct mtd_dev_info mtd;
-	int fd, clmpos = 0, clmlen = 8, eb, eb_start, eb_cnt;
+	int fd, clmpos = 0, clmlen = 8;
+	unsigned int eb, eb_start, eb_cnt;
 	int isNAND;
 	int error = 0;
 	uint64_t offset = 0;
@@ -232,7 +233,7 @@ int main(int argc, char *argv[])
 		eb_cnt = (mtd.size / mtd.eb_size) - eb_start;
 
 	for (eb = eb_start; eb < eb_start + eb_cnt; eb++) {
-		offset = eb * mtd.eb_size;
+		offset = (uint64_t)eb * mtd.eb_size;
 
 		if (!noskipbad) {
 			int ret = mtd_is_bad(&mtd, fd, eb);
@@ -285,7 +286,6 @@ int main(int argc, char *argv[])
 		}
 		verbose(!quiet, " Cleanmarker written at %"PRIx64, offset);
 	}
-	offset += mtd.eb_size;
 	show_progress(&mtd, offset, eb, eb_start, eb_cnt);
 	bareverbose(!quiet, "\n");
 
-- 
1.7.0.4

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

* Re: [PATCH] mtd-utils: flash_erase: Fix output of offsets
  2010-10-16 20:54 [PATCH] mtd-utils: flash_erase: Fix output of offsets Brian Norris
@ 2010-10-16 21:24 ` Mike Frysinger
  2010-10-17  8:04 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2010-10-16 21:24 UTC (permalink / raw)
  To: Brian Norris; +Cc: David Woodhouse, Kevin Cernekee, linux-mtd, Artem Bityutskiy

On Sat, Oct 16, 2010 at 16:54, Brian Norris wrote:
> Also, we should not add an extra eraseblock for the final status
> message; this gives misleading output when, for example, the
> following statement is executed:
>
>        $ flash_erase /dev/mtd0 0 1
>        Erasing 512 Kibyte @ 80000 -- 100 % complete
>
> We aren't erasing at offset 0x80000; it should display offset 0.

yeah, this was to fix the display not getting to 100%, but then i
fixed it another way and forgot to undo this line

Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike

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

* Re: [PATCH] mtd-utils: flash_erase: Fix output of offsets
  2010-10-16 20:54 [PATCH] mtd-utils: flash_erase: Fix output of offsets Brian Norris
  2010-10-16 21:24 ` Mike Frysinger
@ 2010-10-17  8:04 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2010-10-17  8:04 UTC (permalink / raw)
  To: Brian Norris; +Cc: David Woodhouse, Kevin Cernekee, linux-mtd, Mike Frysinger

On Sat, 2010-10-16 at 13:54 -0700, Brian Norris wrote:
> Need to use unsigned arithmetic and a 64-bit cast in order to
> calculate and output the correct offset for eraseblocks at large
> offsets. Signed integer arithmetic does not produce the correct
> result "uint64_t" result, so for offsets over 2GB we get
> messages like:
> 
> 	Erasing 512 Kibyte @ ffffffff83180000 -- 4308642136 % complete.
> 
> Note that this error was not affecting proper erasure; it just
> produced incorrect status messages.
> 
> Also, we should not add an extra eraseblock for the final status
> message; this gives misleading output when, for example, the
> following statement is executed:
> 
> 	$ flash_erase /dev/mtd0 0 1
> 	Erasing 512 Kibyte @ 80000 -- 100 % complete
> 
> We aren't erasing at offset 0x80000; it should display offset 0.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>

Pushed, thanks!

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

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

end of thread, other threads:[~2010-10-17  8:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-16 20:54 [PATCH] mtd-utils: flash_erase: Fix output of offsets Brian Norris
2010-10-16 21:24 ` Mike Frysinger
2010-10-17  8:04 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).