Received: by 10.192.165.148 with SMTP id m20csp4061778imm; Tue, 8 May 2018 02:09:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZro6fVFtlPyalQKspwWq7zamff7LeFM5YaY2ZgVN08pPUa7EiFvMVWQm+YxLiMjaKgIk496 X-Received: by 2002:a65:4a02:: with SMTP id s2-v6mr31861556pgq.265.1525770577808; Tue, 08 May 2018 02:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525770577; cv=none; d=google.com; s=arc-20160816; b=NjNm88UI8VVWCvwEZA0coa+B8n8fC9ppkiqLv0KnGeMTVuOKvoOgb8cB3K8x2+Ivkd amh6N6gzdX53WkQ+9A/U+e9pV/UDShJspsFDc5wMH7rMIQdTiIGru+GLAew6IsuY87Ks RRwbXLRrnqgnHgePlCbkyIB9Gqfitfp4fuCzVcfwC9HyZ1R4/NqiS0pRfgdIo1ftIb11 /q5KqWUAFMsT4pqXPj6MtO6orbrxVDr/i2V9gb/0DvX4xx81nghlFrGL9oOl4z629Unm hEvUIv2uazgsJfG/HM8xiKgHFOfso8wjloA5pmizN6tCs5ympZzI5p3KLxV+ir46Iwr+ YKyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=nBWVDMq4X4nndCqhveCnA3M2SmaXuUYOYQ6TrxM1yM8=; b=E+uOM6HeLcIJbpLUDusG2a3XGTcb7Tq/DuTguFKmtWYhtpY3irtSssWy6BOH0ldbHr ZxAsyMBOQkLsiJ6A/Lnks+BC3D8OGfOvQmCZCK+uNSYdN+HSqjvz+mdkSM5HQMyrS0bn K5HCENnwERRwidAWWGv7Qh1GVteFf4qz7/F4JAB8QBNIFxHP2iOdRTkbsd8zVv9vCS+q /e0P6fmLsw48KTSMN+mBjQh4AxKLh+SrH/M5ipGnLjqI9rK7wkIO8WERyDeEyyVabN+M W/leOeyF4ON3N3z2WwVxakEiRmWxkrI8ln3hZFhcdkenmm5BVLqcHDs/Xuk2HoOGgdoT T4+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si14213884pfm.110.2018.05.08.02.09.23; Tue, 08 May 2018 02:09:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932221AbeEHJJM (ORCPT + 99 others); Tue, 8 May 2018 05:09:12 -0400 Received: from mail.bootlin.com ([62.4.15.54]:45884 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754233AbeEHJJL (ORCPT ); Tue, 8 May 2018 05:09:11 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 1F6C82072C; Tue, 8 May 2018 11:09:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id B9CE12068D; Tue, 8 May 2018 11:08:58 +0200 (CEST) Date: Tue, 8 May 2018 11:08:58 +0200 From: Boris Brezillon To: Jane Wan Cc: miquel.raynal@bootlin.com, dwmw2@infradead.org, computersforpeace@gmail.com, richard@nod.at, marek.vasut@gmail.com, yamada.masahiro@socionext.com, prabhakar.kushwaha@nxp.com, shawnguo@kernel.org, jagdish.gediya@nxp.com, shreeya.patel23498@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, ties.bos@nokia.com Subject: Re: [PATCH v3 2/2] mtd: rawnand: fsl_ifc: use bit-wise majority to recover the contents of ONFI parameter Message-ID: <20180508110858.7b1432f5@bbrezillon> In-Reply-To: <1525710855-8159-1-git-send-email-Jane.Wan@nokia.com> References: <1525710855-8159-1-git-send-email-Jane.Wan@nokia.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 7 May 2018 09:34:15 -0700 Jane Wan wrote: > Per ONFI specification (Rev. 4.0), if all parameter pages have invalid > CRC values, the bit-wise majority may be used to recover the contents of > the parameter pages from the parameter page copies present. > > Signed-off-by: Jane Wan I never received patch 1 of this series. When you fix something in a commit, please resend the whole patchset, even if other patches haven't changed. > --- > drivers/mtd/nand/raw/nand_base.c | 41 ++++++++++++++++++++++++++++++-------- > 1 file changed, 33 insertions(+), 8 deletions(-) > > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > index 72f3a89..48f2dec 100644 > --- a/drivers/mtd/nand/raw/nand_base.c > +++ b/drivers/mtd/nand/raw/nand_base.c > @@ -5086,15 +5086,18 @@ static int nand_flash_detect_ext_param_page(struct nand_chip *chip, > return ret; > } > > +#define GET_BIT(bit, val) (((val) >> (bit)) & 0x01) > + > /* > * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. > */ > static int nand_flash_detect_onfi(struct nand_chip *chip) > { > struct mtd_info *mtd = nand_to_mtd(chip); > - struct nand_onfi_params *p; > + struct nand_onfi_params *p = NULL; > char id[4]; > - int i, ret, val; > + int i, ret, val, pagesize; > + u8 *buf = NULL; > > /* Try ONFI for unknown chip or LP */ > ret = nand_readid_op(chip, 0x20, id, sizeof(id)); > @@ -5102,8 +5105,9 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) > return 0; > > /* ONFI chip: allocate a buffer to hold its parameter page */ > - p = kzalloc(sizeof(*p), GFP_KERNEL); > - if (!p) > + pagesize = sizeof(*p); > + buf = kzalloc((pagesize * 3), GFP_KERNEL); Not sure why you have to add a new buf variable here, and pagesize is not needed either, just use sizeof(*p) directly. > + if (!buf) > return -ENOMEM; > > ret = nand_read_param_page_op(chip, 0, NULL, 0); > @@ -5113,7 +5117,8 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) > } > > for (i = 0; i < 3; i++) { > - ret = nand_read_data_op(chip, p, sizeof(*p), true); > + p = (struct nand_onfi_params *)&buf[i*pagesize]; > + ret = nand_read_data_op(chip, p, pagesize, true); > if (ret) { > ret = 0; > goto free_onfi_param_page; > @@ -5126,8 +5131,27 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) > } > > if (i == 3) { > - pr_err("Could not find valid ONFI parameter page; aborting\n"); > - goto free_onfi_param_page; > + int j, k, l; > + u8 v, m; > + > + pr_err("Could not find valid ONFI parameter page\n"); > + pr_info("Recover ONFI params with bit-wise majority\n"); > + for (j = 0; j < pagesize; j++) { > + v = 0; > + for (k = 0; k < 8; k++) { > + m = 0; > + for (l = 0; l < 3; l++) > + m += GET_BIT(k, buf[l*pagesize + j]); > + if (m > 1) > + v |= BIT(k); > + } > + ((u8 *)p)[j] = v; > + } Can you move the bit-wise majority code in a separate function? > + if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) != > + le16_to_cpu(p->crc)) { > + pr_err("ONFI parameter recovery failed, aborting\n"); > + goto free_onfi_param_page; > + } > } > > /* Check version */ > @@ -5220,7 +5244,8 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) > sizeof(p->vendor)); > > free_onfi_param_page: > - kfree(p); > + if (buf != NULL) > + kfree(buf); kfree() already handles the buf == NULL case, no need to check it here. > return ret; > } >