From patchwork Mon Jan 13 10:25:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 309782 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 ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E9C32C007A for ; Mon, 13 Jan 2014 21:37:29 +1100 (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 1W2etU-0002P7-5J; Mon, 13 Jan 2014 10:37:20 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W2etS-0002KK-Eg; Mon, 13 Jan 2014 10:37:18 +0000 Received: from mail.karo-electronics.de ([81.173.242.67]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W2etQ-0002JR-Oh for linux-mtd@lists.infradead.org; Mon, 13 Jan 2014 10:37:17 +0000 From: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= To: linux-mtd@lists.infradead.org, David Woodhouse , Brian Norris , Artem Bityutskiy , Akinobu Mita , Andrew Morton , =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= , Huang Shijie , linux-kernel@vger.kernel.org Subject: [PATCH] mtd: mtd_oobtest: fix verify errors due to incorrect use of prandom_bytes_state() Date: Mon, 13 Jan 2014 11:25:39 +0100 Message-Id: <1389608739-10945-1-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140113_053716_952387_7383B2ED X-CRM114-Status: GOOD ( 11.10 ) 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 [81.173.242.67 listed in list.dnswl.org] -0.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= 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: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When using prandom_bytes_state() it is critical to use the same block size in all invocations that are to produce the same random sequence. Otherwise the state of the PRNG will be out of sync if the blocksize is not divisible by 4. This leads to bogus verification errors in several tests which use different block sizes to initialize the buffer for writing and comparison. Signed-off-by: Lothar Waßmann --- drivers/mtd/tests/oobtest.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/tests/oobtest.c b/drivers/mtd/tests/oobtest.c index 2e9e2d1..72c7359 100644 --- a/drivers/mtd/tests/oobtest.c +++ b/drivers/mtd/tests/oobtest.c @@ -213,8 +213,15 @@ static int verify_eraseblock_in_one_go(int ebnum) int err = 0; loff_t addr = ebnum * mtd->erasesize; size_t len = mtd->ecclayout->oobavail * pgcnt; + int i; + + for (i = 0; i < pgcnt; i++) + prandom_bytes_state(&rnd_state, &writebuf[i * use_len], + use_len); + if (len % use_len) + prandom_bytes_state(&rnd_state, &writebuf[i * use_len], + len % use_len); - prandom_bytes_state(&rnd_state, writebuf, len); ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0; ops.retlen = 0; @@ -594,7 +601,10 @@ static int __init mtd_oobtest_init(void) if (bbt[i] || bbt[i + 1]) continue; prandom_bytes_state(&rnd_state, writebuf, - mtd->ecclayout->oobavail * 2); + mtd->ecclayout->oobavail); + prandom_bytes_state(&rnd_state, + writebuf + mtd->ecclayout->oobavail, + mtd->ecclayout->oobavail); addr = (i + 1) * mtd->erasesize - mtd->writesize; ops.mode = MTD_OPS_AUTO_OOB; ops.len = 0;