From patchwork Mon Apr 25 22:13:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 614722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qv0sd3dpfz9s9n for ; Tue, 26 Apr 2016 08:15:33 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1auolb-00050k-Vw; Mon, 25 Apr 2016 22:14:07 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1auolT-0004n5-0J for linux-mtd@lists.infradead.org; Mon, 25 Apr 2016 22:14:00 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id A1C2624E0002; Tue, 26 Apr 2016 00:13:36 +0200 (CEST) X-Virus-Scanned: amavisd-new at mail.sigma-star.at Received: from linux.site (richard.vpn.sigmapriv.at [10.3.0.5]) by mail.sigma-star.at (Postfix) with ESMTPSA id CC5D016B4330; Tue, 26 Apr 2016 00:13:35 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 1/8] mtd-utils: Fix return status in mtd_torture test function Date: Tue, 26 Apr 2016 00:13:22 +0200 Message-Id: <1461622409-14970-2-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1461622409-14970-1-git-send-email-richard@nod.at> References: <1461622409-14970-1-git-send-email-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160425_151359_380417_4FB9B8B8 X-CRM114-Status: GOOD ( 16.49 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , david.oberhollenzer@sigma-star.at MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: David Oberhollenzer This patch fixes the return status of the mtd_torture function in libmtd. The torture test function is currently only used by the ubiformat utilitiy to check if a block is bad after a write fails (blocks are marked bad if the function returns an error status). However, the way the function was written, it ALWAYS returns an error value irregardless of whether it failed or not. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger Reviewed-by: Boris Brezillon --- lib/libmtd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index bf6d71f..1717468 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -939,7 +939,7 @@ static uint8_t patterns[] = {0xa5, 0x5a, 0x0}; * @patt: the pattern to check * @size: buffer size in bytes * - * This function returns %1 in there are only @patt bytes in @buf, and %0 if + * This function returns %0 if there are only @patt bytes in @buf, and %-1 if * something else was also found. */ static int check_pattern(const void *buf, uint8_t patt, int size) @@ -948,8 +948,8 @@ static int check_pattern(const void *buf, uint8_t patt, int size) for (i = 0; i < size; i++) if (((const uint8_t *)buf)[i] != patt) - return 0; - return 1; + return -1; + return 0; } int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) @@ -973,7 +973,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) goto out; err = check_pattern(buf, 0xFF, mtd->eb_size); - if (err == 0) { + if (err) { errmsg("erased PEB %d, but a non-0xFF byte found", eb); errno = EIO; goto out; @@ -992,7 +992,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) goto out; err = check_pattern(buf, patterns[i], mtd->eb_size); - if (err == 0) { + if (err) { errmsg("pattern %x checking failed for PEB %d", patterns[i], eb); errno = EIO; @@ -1005,7 +1005,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) out: free(buf); - return -1; + return err; } int mtd_is_bad(const struct mtd_dev_info *mtd, int fd, int eb)