From patchwork Sat Oct 16 20:54:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 68052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4CBBCB6F11 for ; Sun, 17 Oct 2010 08:01:04 +1100 (EST) Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1P7DlC-00058M-6s; Sat, 16 Oct 2010 20:53:46 +0000 Received: from mms1.broadcom.com ([216.31.210.17]) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1P7Dl7-00057x-U5 for linux-mtd@lists.infradead.org; Sat, 16 Oct 2010 20:53:43 +0000 Received: from [10.9.200.133] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Sat, 16 Oct 2010 13:53:28 -0700 X-Server-Uuid: 02CED230-5797-4B57-9875-D5D2FEE4708A Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB02.corp.ad.broadcom.com (10.9.200.133) with Microsoft SMTP Server id 8.2.247.2; Sat, 16 Oct 2010 13:54:46 -0700 Received: from localhost.localdomain (ld-irv-0074.broadcom.com [10.12.160.50]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id 3D11569CA8; Sat, 16 Oct 2010 13:53:28 -0700 (PDT) From: "Brian Norris" To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd-utils: flash_erase: Fix output of offsets Date: Sat, 16 Oct 2010 13:54:05 -0700 Message-ID: <1287262445-19654-1-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-WSS-ID: 60A4CF4247826538495-01-01 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20101016_165342_192639_1458EAFA X-CRM114-Status: GOOD ( 14.91 ) X-Spam-Score: 1.2 (+) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is freemail (computersforpeace[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 1.2 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL Cc: Kevin Cernekee , Brian Norris , David Woodhouse , Mike Frysinger , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 Acked-by: Mike Frysinger --- 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");