From patchwork Wed Aug 21 13:24:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Mats_K=C3=A4rrman?= X-Patchwork-Id: 268807 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 B792C2C009A for ; Wed, 21 Aug 2013 23:25:33 +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 1VC8Pf-0000fB-1H; Wed, 21 Aug 2013 13:25:27 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VC8Pd-0002Td-CI; Wed, 21 Aug 2013 13:25:25 +0000 Received: from tritech.se ([46.59.120.190]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VC8PW-0002T5-T0 for linux-mtd@lists.infradead.org; Wed, 21 Aug 2013 13:25:23 +0000 Received: from post.tritech.se (post.tritech.se [10.75.60.100]) by tritech.se (8.14.3/8.14.3) with ESMTP id r7LDOokT025140; Wed, 21 Aug 2013 15:24:55 +0200 Received: from POST.tritech.se ([fe80::b4fc:968e:bbef:54cb]) by post.tritech.se ([fe80::b4fc:968e:bbef:54cb%10]) with mapi id 14.02.0342.003; Wed, 21 Aug 2013 15:24:50 +0200 From: =?iso-8859-1?Q?Mats_K=E4rrman?= To: "linux-mtd@lists.infradead.org" Subject: [PATCH] ubifs: Correct data corruption range Thread-Topic: [PATCH] ubifs: Correct data corruption range Thread-Index: AQHOnm5ZauCbu0CMAUSVvhxTiJ41xg== Date: Wed, 21 Aug 2013 13:24:49 +0000 Message-ID: Accept-Language: en-US, sv-SE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [194.132.137.82] MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130821_092519_182362_1510092E X-CRM114-Status: UNSURE ( 6.37 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.7 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -2.8 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: Artem Bityutskiy 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 With power-cut emulation, it is possible that sometimes no data at all is corrupted and that confusing messages are printed due to errors in the computation of data corruption range. [1] The start of the range should be [0..len-1], not [0..len]. [2] The end of the range should always be at least 1 greater than the start. Signed-off-by: Mats Karrman diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 6e025e0..cc1febd 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c @@ -2563,9 +2563,9 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf, unsigned int from, to, ffs = chance(1, 2); unsigned char *p = (void *)buf; - from = prandom_u32() % (len + 1); - /* Corruption may only span one max. write unit */ - to = min(len, ALIGN(from, c->max_write_size)); + from = prandom_u32() % len; + /* Corruption span max to end of write unit */ + to = min(len, ALIGN(from + 1, c->max_write_size)); ubifs_warn("filled bytes %u-%u with %s", from, to - 1, ffs ? "0xFFs" : "random data");