From patchwork Sat Jul 27 02:14:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 262370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CFBD72C0106 for ; Sat, 27 Jul 2013 12:16:05 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2u2l-0003Df-O2; Sat, 27 Jul 2013 02:15:40 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2u2j-0008JW-T0; Sat, 27 Jul 2013 02:15:37 +0000 Received: from mail-pb0-x233.google.com ([2607:f8b0:400e:c01::233]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2u2Y-0008FY-JF for linux-mtd@lists.infradead.org; Sat, 27 Jul 2013 02:15:35 +0000 Received: by mail-pb0-f51.google.com with SMTP id um15so2652681pbc.24 for ; Fri, 26 Jul 2013 19:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=p72CbrneM/zglibduBwE+44voXMFv5+XZ2hUuDO2I7U=; b=vnKhJulLrQ5Ew7E7vbN/ze/GHRqNgVgi/HWW5GO9NwaKF8YLBIkXb8l/YxImVNLO3r MzHzifnItSCiFeG1tPzYmdWUp83vtUNetH8BF6sH70WPT7OLIqqV7aTUUViivR4mj4z7 SQQejBHm2hl34uh0OlvigU15BixjKJBfz+PexOqvDo7TnDL6m2eMLx6aNVbVv5ugaKC2 vzNNYFOtu4Zn8GVtRhWCkFOSQfAB+SF4ntRTmJvDjHDA/gStmoPzEjYttjrnYsW4Pv7V BPLc+mf0pTrXEWmYV0CqCYKIkVPoH7xQXwuV+vQDgUA88eMi3QnCpTpyGgJx7M7u9wci vo1A== X-Received: by 10.66.253.69 with SMTP id zy5mr53538827pac.29.1374891303551; Fri, 26 Jul 2013 19:15:03 -0700 (PDT) Received: from localhost.localdomain (KD113145060135.ppp-bb.dion.ne.jp. [113.145.60.135]) by mx.google.com with ESMTPSA id bg3sm62887200pbb.44.2013.07.26.19.15.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 26 Jul 2013 19:15:03 -0700 (PDT) From: Akinobu Mita To: linux-mtd@lists.infradead.org Subject: [PATCH -next 2/7] mtd: mtd_oobtest: use mtd_test module Date: Sat, 27 Jul 2013 11:14:11 +0900 Message-Id: <1374891256-20248-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1374891256-20248-1-git-send-email-akinobu.mita@gmail.com> References: <1374891256-20248-1-git-send-email-akinobu.mita@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130726_221527_041335_EEBBE99E X-CRM114-Status: GOOD ( 16.72 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (akinobu.mita[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Artem Bityutskiy , David Woodhouse , Akinobu Mita , Adrian Hunter X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use mtdtest_scan_for_bad_eraseblocks(), mtdtest_erase_whole_device(), and mtdtest_erase_eraseblock() in mtd_test module. Signed-off-by: Akinobu Mita Cc: Adrian Hunter Cc: Artem Bityutskiy Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- drivers/mtd/tests/mtd_oobtest.c | 92 ++++++----------------------------------- 1 file changed, 12 insertions(+), 80 deletions(-) diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index ab81e9a..8d5e35c 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -31,6 +31,8 @@ #include #include +#include "mtd_test.h" + static int dev = -EINVAL; module_param(dev, int, S_IRUGO); MODULE_PARM_DESC(dev, "MTD device number to use"); @@ -49,49 +51,6 @@ static int use_len_max; static int vary_offset; static struct rnd_state rnd_state; -static int erase_eraseblock(int ebnum) -{ - int err; - struct erase_info ei; - loff_t addr = ebnum * mtd->erasesize; - - memset(&ei, 0, sizeof(struct erase_info)); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err = mtd_erase(mtd, &ei); - if (err) { - pr_err("error %d while erasing EB %d\n", err, ebnum); - return err; - } - - if (ei.state == MTD_ERASE_FAILED) { - pr_err("some erase error occurred at EB %d\n", ebnum); - return -EIO; - } - - return 0; -} - -static int erase_whole_device(void) -{ - int err; - unsigned int i; - - pr_info("erasing whole device\n"); - for (i = 0; i < ebcnt; ++i) { - if (bbt[i]) - continue; - err = erase_eraseblock(i); - if (err) - return err; - cond_resched(); - } - pr_info("erased %u eraseblocks\n", i); - return 0; -} - static void do_vary_offset(void) { use_len -= 1; @@ -304,36 +263,6 @@ static int verify_all_eraseblocks(void) return 0; } -static int is_block_bad(int ebnum) -{ - int ret; - loff_t addr = ebnum * mtd->erasesize; - - ret = mtd_block_isbad(mtd, addr); - if (ret) - pr_info("block %d is bad\n", ebnum); - return ret; -} - -static int scan_for_bad_eraseblocks(void) -{ - int i, bad = 0; - - bbt = kmalloc(ebcnt, GFP_KERNEL); - if (!bbt) - return -ENOMEM; - - pr_info("scanning for bad eraseblocks\n"); - for (i = 0; i < ebcnt; ++i) { - bbt[i] = is_block_bad(i) ? 1 : 0; - if (bbt[i]) - bad += 1; - cond_resched(); - } - pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); - return 0; -} - static int __init mtd_oobtest_init(void) { int err = 0; @@ -383,8 +312,11 @@ static int __init mtd_oobtest_init(void) writebuf = kmalloc(mtd->erasesize, GFP_KERNEL); if (!writebuf) goto out; + bbt = kzalloc(ebcnt, GFP_KERNEL); + if (!bbt) + goto out; - err = scan_for_bad_eraseblocks(); + err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt); if (err) goto out; @@ -396,7 +328,7 @@ static int __init mtd_oobtest_init(void) /* First test: write all OOB, read it back and verify */ pr_info("test 1 of 5\n"); - err = erase_whole_device(); + err = mtdtest_erase_whole_device(mtd, bbt, ebcnt); if (err) goto out; @@ -416,7 +348,7 @@ static int __init mtd_oobtest_init(void) */ pr_info("test 2 of 5\n"); - err = erase_whole_device(); + err = mtdtest_erase_whole_device(mtd, bbt, ebcnt); if (err) goto out; @@ -446,7 +378,7 @@ static int __init mtd_oobtest_init(void) */ pr_info("test 3 of 5\n"); - err = erase_whole_device(); + err = mtdtest_erase_whole_device(mtd, bbt, ebcnt); if (err) goto out; @@ -479,7 +411,7 @@ static int __init mtd_oobtest_init(void) /* Fourth test: try to write off end of device */ pr_info("test 4 of 5\n"); - err = erase_whole_device(); + err = mtdtest_erase_whole_device(mtd, bbt, ebcnt); if (err) goto out; @@ -571,7 +503,7 @@ static int __init mtd_oobtest_init(void) errcnt += 1; } - err = erase_eraseblock(ebcnt - 1); + err = mtdtest_erase_eraseblock(mtd, ebcnt - 1); if (err) goto out; @@ -620,7 +552,7 @@ static int __init mtd_oobtest_init(void) pr_info("test 5 of 5\n"); /* Erase all eraseblocks */ - err = erase_whole_device(); + err = mtdtest_erase_whole_device(mtd, bbt, ebcnt); if (err) goto out;