From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 887E6C5DF89 for ; Thu, 20 Aug 2026 10:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UjXCLvmT8CfcWEYI4cs8TN8sZKnSj6LESLVTGSs9NrM=; b=XcEibLcHo5dROn 9xjCFKjYZNoDAYJt5r3ARmBSGoY9morBRYxsi4UzlnXYt4HhCobYHEwDD/HiQI9PiGwt9+nfAj50t YlXywytah6rP8msVwkpFwk5K892eS6/0CUSbd2ZrFQVl1t150KAixu7uZcubEgyaCNilFNM1/rU9v qWKVL7ZsJ8yjglb2R7mfiNA/DiaZDPcg6lYc4CNA52fkapXzm/h2dJrSithGSp98Ytst2Mq1C2DFT 17LkxcgwwsqFCYj1AP9szcw4VGOG8nQjbHPoPSPg6xD8yn+seFwgv1WCn1Crsy49TS3QTkvGY/VXT W42V1WJUU8dg3e8x6VZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wx0SN-0000000BOc1-1LGw; Thu, 20 Aug 2026 10:57:11 +0000 Received: from canpmsgout03.his.huawei.com ([113.46.200.218]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wx0SJ-0000000BOYC-1c35 for linux-mtd@lists.infradead.org; Thu, 20 Aug 2026 10:57:09 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=7L0QcGcokJqrXi4agQNPP9tmzIEptjTM0q6SvndD1xI=; b=pHfltcAGC4jhg9CRuD5NTSdjGSwvr7m0U0qeMEKuhHmPA4rJdwmYjLx28zCVRigj7CEgL13qt JkmgJWQycskn3HiaQS6AFEd9uZl0K9xFg8L/bbON1Fq3mD1pnYRXcCGeXVP5wQumjXnxWQ7K3QL Y+CmAjmW47XhV20DoENuay0= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4hQg8S3fKhzpT0s; Thu, 20 Aug 2026 18:46:00 +0800 (CST) Received: from dggpemr100018.china.huawei.com (unknown [7.185.36.64]) by mail.maildlp.com (Postfix) with ESMTPS id 687724057F; Thu, 20 Aug 2026 18:56:58 +0800 (CST) Received: from huawei.com (10.50.85.155) by dggpemr100018.china.huawei.com (7.185.36.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Thu, 20 Aug 2026 18:56:57 +0800 From: zhouminqiang To: , CC: , , , , Subject: [PATCH 2/6] jffs2: write verify: replace memcmp with byte-by-byte comparison Date: Thu, 20 Aug 2026 18:49:58 +0800 Message-ID: <20260820105003.2525647-3-zhouminqiang2@huawei.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260820105003.2525647-1-zhouminqiang2@huawei.com> References: <20260820105003.2525647-1-zhouminqiang2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.85.155] X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemr100018.china.huawei.com (7.185.36.64) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260820_035707_785430_0EEAD3CE X-CRM114-Status: GOOD ( 14.41 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org jffs2_verify_write() uses memcmp() to compare the write buffer against data read back from flash. While memcmp() compares byte by byte internally, it only reports equal or not-equal without identifying the mismatch offset. To pinpoint the exact mismatch offset, replace this with the approach used by UBI's self_check_write(): compare byte by byte and, on mismatch, report the first differing offset and dump up to 128 bytes of both the source and read-back data. Signed-off-by: zhouminqiang --- fs/jffs2/wbuf.c | 53 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index 7e4608b43a4e..da6da813a4ef 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -231,8 +231,8 @@ static struct jffs2_raw_node_ref **jffs2_incore_replace_raw(struct jffs2_sb_info static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, uint32_t ofs) { - int ret; - size_t retlen; + int ret = 0; + size_t retlen, i; char *eccstr; void *verify_buf; @@ -246,37 +246,46 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, verify_buf); if (ret && ret != -EUCLEAN && ret != -EBADMSG) { pr_warn("%s(): Read back of page at %08x failed: %d\n", - __func__, c->wbuf_ofs, ret); + __func__, ofs, ret); goto out_free; } else if (retlen != c->wbuf_pagesize) { - pr_warn("%s(): Read back of page at %08x gave short read: %zd not %d\n", + pr_warn("%s(): Read back of page at %08x gave short read: %zu not %d\n", __func__, ofs, retlen, c->wbuf_pagesize); ret = -EIO; goto out_free; } - if (!memcmp(buf, verify_buf, c->wbuf_pagesize)) { - ret = 0; - goto out_free; - } - if (ret == -EUCLEAN) - eccstr = "corrected"; - else if (ret == -EBADMSG) - eccstr = "correction failed"; - else - eccstr = "OK or unused"; + for (i = 0; i < c->wbuf_pagesize; i++) { + uint8_t c1 = ((uint8_t *)buf)[i]; + uint8_t c2 = ((uint8_t *)verify_buf)[i]; + int dump_len; - pr_warn("Write verify error (ECC %s) at %08x. Wrote:\n", - eccstr, c->wbuf_ofs); - print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, - c->wbuf, c->wbuf_pagesize, 0); + if (c1 == c2) + continue; - pr_warn("Read back:\n"); - print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, - verify_buf, c->wbuf_pagesize, 0); + if (ret == -EUCLEAN) + eccstr = "corrected"; + else if (ret == -EBADMSG) + eccstr = "correction failed"; + else + eccstr = "OK or unused"; + + dump_len = min_t(int, 128, c->wbuf_pagesize - i); + pr_warn("Write verify error (ECC %s) at %08x (+%zu/%d). Wrote:\n", + eccstr, ofs, i, c->wbuf_pagesize); + print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, + buf + i, dump_len, 0); + + pr_warn("Read back:\n"); + print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, + verify_buf + i, dump_len, 0); + + ret = -EIO; + goto out_free; + } vfree(verify_buf); - return -EIO; + return 0; out_free: vfree(verify_buf); -- 2.52.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45CA1418A22 for ; Thu, 20 Aug 2026 10:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223429; cv=none; b=cnNn5pZIOJy3W+gU7RoDoDf1aQ+U+i0Lx2xwIdV/0ksEM+Ueqmhp3DBJUFaBjPFY1CBgcGQTTun8w0IK3EcHamkCbX9DkAtxIWlIjrJOFsy1jLrb3TPMxeU9iI6HJFDkeg6KkSBO9TGDCYg6Z2+QfDlY3LC9MatNWRvFvzXYaIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223429; c=relaxed/simple; bh=eHENmoZvaqXm0RQxAw595OSPeWY8yCsoBEmrdF6LTzM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Hj83WtP2xnuVmW0msNO/PBjRU7UQ0z8+sdXQWwCSdOwwNro0anvw1dEA8thxLwLbrdkxNNjArqQiG+A3djClVATQ/LMCbsicHGfiE7NTCtmZAk2lN+j5vdSSamsesCCHgRR2CvRVBruOraRiyJ3dBoyc/3n59Wmo8Ony8zpqfSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=pHfltcAG; arc=none smtp.client-ip=113.46.200.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="pHfltcAG" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=7L0QcGcokJqrXi4agQNPP9tmzIEptjTM0q6SvndD1xI=; b=pHfltcAGC4jhg9CRuD5NTSdjGSwvr7m0U0qeMEKuhHmPA4rJdwmYjLx28zCVRigj7CEgL13qt JkmgJWQycskn3HiaQS6AFEd9uZl0K9xFg8L/bbON1Fq3mD1pnYRXcCGeXVP5wQumjXnxWQ7K3QL Y+CmAjmW47XhV20DoENuay0= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4hQg8S3fKhzpT0s; Thu, 20 Aug 2026 18:46:00 +0800 (CST) Received: from dggpemr100018.china.huawei.com (unknown [7.185.36.64]) by mail.maildlp.com (Postfix) with ESMTPS id 687724057F; Thu, 20 Aug 2026 18:56:58 +0800 (CST) Received: from huawei.com (10.50.85.155) by dggpemr100018.china.huawei.com (7.185.36.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Thu, 20 Aug 2026 18:56:57 +0800 From: zhouminqiang To: , CC: , , , , Subject: [PATCH 2/6] jffs2: write verify: replace memcmp with byte-by-byte comparison Date: Thu, 20 Aug 2026 18:49:58 +0800 Message-ID: <20260820105003.2525647-3-zhouminqiang2@huawei.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260820105003.2525647-1-zhouminqiang2@huawei.com> References: <20260820105003.2525647-1-zhouminqiang2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemr100018.china.huawei.com (7.185.36.64) jffs2_verify_write() uses memcmp() to compare the write buffer against data read back from flash. While memcmp() compares byte by byte internally, it only reports equal or not-equal without identifying the mismatch offset. To pinpoint the exact mismatch offset, replace this with the approach used by UBI's self_check_write(): compare byte by byte and, on mismatch, report the first differing offset and dump up to 128 bytes of both the source and read-back data. Signed-off-by: zhouminqiang --- fs/jffs2/wbuf.c | 53 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index 7e4608b43a4e..da6da813a4ef 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -231,8 +231,8 @@ static struct jffs2_raw_node_ref **jffs2_incore_replace_raw(struct jffs2_sb_info static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, uint32_t ofs) { - int ret; - size_t retlen; + int ret = 0; + size_t retlen, i; char *eccstr; void *verify_buf; @@ -246,37 +246,46 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, verify_buf); if (ret && ret != -EUCLEAN && ret != -EBADMSG) { pr_warn("%s(): Read back of page at %08x failed: %d\n", - __func__, c->wbuf_ofs, ret); + __func__, ofs, ret); goto out_free; } else if (retlen != c->wbuf_pagesize) { - pr_warn("%s(): Read back of page at %08x gave short read: %zd not %d\n", + pr_warn("%s(): Read back of page at %08x gave short read: %zu not %d\n", __func__, ofs, retlen, c->wbuf_pagesize); ret = -EIO; goto out_free; } - if (!memcmp(buf, verify_buf, c->wbuf_pagesize)) { - ret = 0; - goto out_free; - } - if (ret == -EUCLEAN) - eccstr = "corrected"; - else if (ret == -EBADMSG) - eccstr = "correction failed"; - else - eccstr = "OK or unused"; + for (i = 0; i < c->wbuf_pagesize; i++) { + uint8_t c1 = ((uint8_t *)buf)[i]; + uint8_t c2 = ((uint8_t *)verify_buf)[i]; + int dump_len; - pr_warn("Write verify error (ECC %s) at %08x. Wrote:\n", - eccstr, c->wbuf_ofs); - print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, - c->wbuf, c->wbuf_pagesize, 0); + if (c1 == c2) + continue; - pr_warn("Read back:\n"); - print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, - verify_buf, c->wbuf_pagesize, 0); + if (ret == -EUCLEAN) + eccstr = "corrected"; + else if (ret == -EBADMSG) + eccstr = "correction failed"; + else + eccstr = "OK or unused"; + + dump_len = min_t(int, 128, c->wbuf_pagesize - i); + pr_warn("Write verify error (ECC %s) at %08x (+%zu/%d). Wrote:\n", + eccstr, ofs, i, c->wbuf_pagesize); + print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, + buf + i, dump_len, 0); + + pr_warn("Read back:\n"); + print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, + verify_buf + i, dump_len, 0); + + ret = -EIO; + goto out_free; + } vfree(verify_buf); - return -EIO; + return 0; out_free: vfree(verify_buf); -- 2.52.0