From patchwork Sun Jul 10 14:54:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Oberhollenzer X-Patchwork-Id: 646774 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 3rnWbl6L8Sz9s5M for ; Mon, 11 Jul 2016 00:59:47 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bMGB0-0002QO-0a; Sun, 10 Jul 2016 14:57:46 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bMGAw-0002P8-QX for linux-mtd@lists.infradead.org; Sun, 10 Jul 2016 14:57:43 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id 1AF4D16B4334; Sun, 10 Jul 2016 16:57:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at mail.sigma-star.at Received: from arch-laptop.asozial (80-110-120-191.cgn.dynamic.surfer.at [80.110.120.191]) by mail.sigma-star.at (Postfix) with ESMTPSA id 2F5DA16B4331; Sun, 10 Jul 2016 16:57:16 +0200 (CEST) From: David Oberhollenzer To: linux-mtd@lists.infradead.org, David.Woodhouse@intel.com Subject: [RESEND PATCH] mtd-utils: Fix return status in mtd_torture test function Date: Sun, 10 Jul 2016 16:54:02 +0200 Message-Id: <20160710145402.2974-1-david.oberhollenzer@sigma-star.at> X-Mailer: git-send-email 2.9.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160710_075743_187179_F51E07C8 X-CRM114-Status: GOOD ( 14.42 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.4 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] 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: David Oberhollenzer MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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)