From patchwork Sun Oct 28 07:19:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 194657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 03AB62C0090 for ; Sun, 28 Oct 2012 18:21:34 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TSNAD-0001N8-8q; Sun, 28 Oct 2012 07:20:05 +0000 Received: from mail-da0-f49.google.com ([209.85.210.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TSN9s-0001JB-RX for linux-mtd@lists.infradead.org; Sun, 28 Oct 2012 07:19:45 +0000 Received: by mail-da0-f49.google.com with SMTP id q27so1746305daj.36 for ; Sun, 28 Oct 2012 00:19:44 -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=/6JB/M9u8bFMfGvwHHfsfEQQ2Te+yVMYVNFncZG9PVQ=; b=iA9u1UAo1DQB/6FsCDY220C6RKqCxaJCgg7bLuge/ytw/qLZn31gz3I4Y6qhydgwXH BVysXG/P6ikM58nmxLzCSKtDydhDC7faFmz9mE7WEWsh/b9XBhXuAI3AtBxLpavL4WvN EGxRZEcqks6X5VmbEbY8pPOKdv7rkdUKDG1v4ZsCtaPUSpw0nJcyh7ZH0sMw+csyvBpx VXwPa0i/JMEx5mkusVilKAVFeMvZyglnAq4d99PPT9I491CYnCG6WTaz0aVxldKE12HE bu3BL0JNbKQKR0X/jarWwbgMVPoy1GvC/klyJovZjh1MxhpVcSaXxrm1FwEPTBDKtgYf MF4Q== Received: by 10.66.81.199 with SMTP id c7mr74600132pay.19.1351408784608; Sun, 28 Oct 2012 00:19:44 -0700 (PDT) Received: from localhost.localdomain (p1120-ipbf2201hodogaya.kanagawa.ocn.ne.jp. [123.220.186.120]) by mx.google.com with ESMTPS id lb4sm3961166pbc.6.2012.10.28.00.19.42 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 28 Oct 2012 00:19:44 -0700 (PDT) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Subject: [PATCH 6/9] mtd: mtd_oobtest: convert to use prandom32_get_bytes() Date: Sun, 28 Oct 2012 16:19:03 +0900 Message-Id: <1351408746-8623-6-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351408746-8623-1-git-send-email-akinobu.mita@gmail.com> References: <1351408746-8623-1-git-send-email-akinobu.mita@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.49 listed in list.dnswl.org] 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: linux-mtd@lists.infradead.org, David Woodhouse , Akinobu Mita , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This removes home-brewed pseudo-random number generator and use prandom32_get_bytes(). Signed-off-by: Akinobu Mita Cc: Artem Bityutskiy Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- drivers/mtd/tests/mtd_oobtest.c | 49 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index ed9b628..41670ed 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -27,6 +27,7 @@ #include #include #include +#include #define PRINT_PREF KERN_INFO "mtd_oobtest: " @@ -46,26 +47,7 @@ static int use_offset; static int use_len; static int use_len_max; static int vary_offset; -static unsigned long next = 1; - -static inline unsigned int simple_rand(void) -{ - next = next * 1103515245 + 12345; - return (unsigned int)((next / 65536) % 32768); -} - -static inline void simple_srand(unsigned long seed) -{ - next = seed; -} - -static void set_random_data(unsigned char *buf, size_t len) -{ - size_t i; - - for (i = 0; i < len; ++i) - buf[i] = simple_rand(); -} +static struct rnd_state rnd_state; static int erase_eraseblock(int ebnum) { @@ -130,7 +112,7 @@ static int write_eraseblock(int ebnum) loff_t addr = ebnum * mtd->erasesize; for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { - set_random_data(writebuf, use_len); + prandom32_get_bytes(&rnd_state, writebuf, use_len); ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0; ops.retlen = 0; @@ -183,7 +165,7 @@ static int verify_eraseblock(int ebnum) loff_t addr = ebnum * mtd->erasesize; for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { - set_random_data(writebuf, use_len); + prandom32_get_bytes(&rnd_state, writebuf, use_len); ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0; ops.retlen = 0; @@ -275,7 +257,7 @@ static int verify_eraseblock_in_one_go(int ebnum) loff_t addr = ebnum * mtd->erasesize; size_t len = mtd->ecclayout->oobavail * pgcnt; - set_random_data(writebuf, len); + prandom32_get_bytes(&rnd_state, writebuf, len); ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0; ops.retlen = 0; @@ -426,12 +408,12 @@ static int __init mtd_oobtest_init(void) if (err) goto out; - simple_srand(1); + prandom32_seed(&rnd_state, 1); err = write_whole_device(); if (err) goto out; - simple_srand(1); + prandom32_seed(&rnd_state, 1); err = verify_all_eraseblocks(); if (err) goto out; @@ -446,13 +428,13 @@ static int __init mtd_oobtest_init(void) if (err) goto out; - simple_srand(3); + prandom32_seed(&rnd_state, 3); err = write_whole_device(); if (err) goto out; /* Check all eraseblocks */ - simple_srand(3); + prandom32_seed(&rnd_state, 3); printk(PRINT_PREF "verifying all eraseblocks\n"); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) @@ -481,7 +463,7 @@ static int __init mtd_oobtest_init(void) use_len = mtd->ecclayout->oobavail; use_len_max = mtd->ecclayout->oobavail; vary_offset = 1; - simple_srand(5); + prandom32_seed(&rnd_state, 5); err = write_whole_device(); if (err) @@ -492,7 +474,7 @@ static int __init mtd_oobtest_init(void) use_len = mtd->ecclayout->oobavail; use_len_max = mtd->ecclayout->oobavail; vary_offset = 1; - simple_srand(5); + prandom32_seed(&rnd_state, 5); err = verify_all_eraseblocks(); if (err) goto out; @@ -651,7 +633,7 @@ static int __init mtd_oobtest_init(void) goto out; /* Write all eraseblocks */ - simple_srand(11); + prandom32_seed(&rnd_state, 11); printk(PRINT_PREF "writing OOBs of whole device\n"); for (i = 0; i < ebcnt - 1; ++i) { int cnt = 2; @@ -661,7 +643,7 @@ static int __init mtd_oobtest_init(void) continue; addr = (i + 1) * mtd->erasesize - mtd->writesize; for (pg = 0; pg < cnt; ++pg) { - set_random_data(writebuf, sz); + prandom32_get_bytes(&rnd_state, writebuf, sz); ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0; ops.retlen = 0; @@ -683,12 +665,13 @@ static int __init mtd_oobtest_init(void) printk(PRINT_PREF "written %u eraseblocks\n", i); /* Check all eraseblocks */ - simple_srand(11); + prandom32_seed(&rnd_state, 11); printk(PRINT_PREF "verifying all eraseblocks\n"); for (i = 0; i < ebcnt - 1; ++i) { if (bbt[i] || bbt[i + 1]) continue; - set_random_data(writebuf, mtd->ecclayout->oobavail * 2); + prandom32_get_bytes(&rnd_state, writebuf, + mtd->ecclayout->oobavail * 2); addr = (i + 1) * mtd->erasesize - mtd->writesize; ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0;