Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755594AbcLBE0u (ORCPT ); Thu, 1 Dec 2016 23:26:50 -0500 Received: from conssluserg-02.nifty.com ([210.131.2.81]:36747 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752437AbcLBE0t (ORCPT ); Thu, 1 Dec 2016 23:26:49 -0500 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com uB24QSpi001515 X-Nifty-SrcIP: [209.85.161.169] MIME-Version: 1.0 In-Reply-To: <20161127164235.6ad93fab@bbrezillon> References: <1480183585-592-1-git-send-email-yamada.masahiro@socionext.com> <1480183585-592-16-git-send-email-yamada.masahiro@socionext.com> <20161127164235.6ad93fab@bbrezillon> From: Masahiro Yamada Date: Fri, 2 Dec 2016 13:26:27 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 15/39] mtd: nand: denali: improve readability of handle_ecc() To: Boris Brezillon Cc: linux-mtd@lists.infradead.org, Linux Kernel Mailing List , Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse , Cyrille Pitchen Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1919 Lines: 68 Hi Boris, 2016-11-28 0:42 GMT+09:00 Boris Brezillon : >> + if (err_byte < ECC_SECTOR_SIZE) { >> + struct mtd_info *mtd = >> + nand_to_mtd(&denali->nand); >> + int offset; >> + >> + offset = (err_sector * ECC_SECTOR_SIZE + err_byte) * >> + denali->devnum + err_device; >> + /* correct the ECC error */ >> + buf[offset] ^= err_correction_value; >> + mtd->ecc_stats.corrected++; >> + bitflips++; > > Hm, bitflips is what is set in max_bitflips, and apparently the > implementation (which is not yours) is not doing what the core expects. > > You should first count bitflips per sector with something like that: > > bitflips[err_sector]++; > > > And then once you've iterated over all errors do: > > for (i = 0; i < nsectors; i++) > max_bitflips = max(bitflips[err_sector], max_bitflips); I see. For soft ECC fixup, we can calculate bitflips for each ECC sector, so I can fix the max_bitflips as the core framework expects. For hard ECC fixup, the register only reports the number of corrected bit-flips in the whole page (sum from all ECC sectors). We cannot calculate max_bitflips, I think. BTW, I noticed another problem of the current code. buf[offset] ^= err_correction_value; mtd->ecc_stats.corrected++; bitflips++; This code is counting the number of corrected bytes, not the number of corrected bits. I think multiple bit-flips within one byte can happen. Perhaps, we should add hweight8(buf[offset] ^ err_correction_value) to ecc_stats.corrected and bitflips. -- Best Regards Masahiro Yamada