From patchwork Tue Oct 28 18:13:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 5178941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BC6CA9F349 for ; Tue, 28 Oct 2014 18:16:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA09820179 for ; Tue, 28 Oct 2014 18:16:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8DB620176 for ; Tue, 28 Oct 2014 18:16:41 +0000 (UTC) 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 1XjBH7-000546-5Y; Tue, 28 Oct 2014 18:13:45 +0000 Received: from mail-pa0-x22b.google.com ([2607:f8b0:400e:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XjBH1-00051v-Nk; Tue, 28 Oct 2014 18:13:41 +0000 Received: by mail-pa0-f43.google.com with SMTP id eu11so1305838pac.2 for ; Tue, 28 Oct 2014 11:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=qaQhHRER0IKfX1Ao2jWBL9be0CQu0tws5p6AJP8kIJw=; b=rb2Xa/JZGElZCLf+nsdS7mt5bfqdqLgrMJjnSAuXn3r2L2Lyq6zxdnLreG6CxS5Sta hjJ6DG/ao7N05xOgpMt/tXflt64lkbcu/m9tJiNIQkRluB0GQJNBezbGJARbHNHrGqCT atMcYgnZVz9NGxvmqYv6OJ0B1JwYJ5edT0xyLund/Ba73FVHm0Aot1q0xp8dw9FXG3P/ ELNF6kR25gs6uuf2aF/vOx9uNGrkgADWE0NDtkbIaf3AH+7tPADoHmZNx5WjskkHy1zc WsWBU3hhwRRH7wcQsuSnilqz8QrOXhRx8I3iAn+HrzUOB2tTipzV2JNJoXEPLoJDyokH dHiw== X-Received: by 10.68.175.196 with SMTP id cc4mr4512046pbc.147.1414519997809; Tue, 28 Oct 2014 11:13:17 -0700 (PDT) Received: from ld-irv-0074 (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id o5sm2267701pdc.24.2014.10.28.11.13.16 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 28 Oct 2014 11:13:17 -0700 (PDT) Date: Tue, 28 Oct 2014 11:13:11 -0700 From: Brian Norris To: Boris Brezillon Subject: Re: [PATCH v7 1/2] mtd: nand: add sunxi NAND flash controller support Message-ID: <20141028181310.GA23619@ld-irv-0074> References: <1413896922-11680-1-git-send-email-boris.brezillon@free-electrons.com> <1413896922-11680-2-git-send-email-boris.brezillon@free-electrons.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1413896922-11680-2-git-send-email-boris.brezillon@free-electrons.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141028_111340_061509_7DC3C767 X-CRM114-Status: GOOD ( 20.07 ) X-Spam-Score: -0.8 (/) Cc: Mark Rutland , devicetree@vger.kernel.org, Pawel Moll , Ian Campbell , linux-kernel@vger.kernel.org, Yassin Jaffer , linux-sunxi@googlegroups.com, Rob Herring , linux-mtd@lists.infradead.org, Kumar Gala , David Woodhouse , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Boris, On Tue, Oct 21, 2014 at 03:08:41PM +0200, Boris Brezillon wrote: > +static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd, > + struct nand_ecc_ctrl *ecc, > + struct device_node *np) > +{ > + struct nand_ecclayout *layout; > + int i, j; > + int ret; > + > + ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np); > + if (ret) > + return ret; > + > + ecc->read_page = sunxi_nfc_hw_ecc_read_page; > + ecc->write_page = sunxi_nfc_hw_ecc_write_page; > + layout = ecc->layout; > + > + for (i = 0; i < ecc->steps; i++) { Hmm, did you retest this since changing this to ecc->steps? I think this won't work, since ecc->steps is only initialized in nand_scan_tail(), which comes after this. I only recommended the change for the {read,write}_page() type of functions, not the initialization functions. [snip the rest] So I'd suggest the following additional patch, and otherwise, the series is fine with me. If you give your ack, I can just squash this in and apply it to my tree: diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c index ea615dc442a4..ccaa8e283388 100644 --- a/drivers/mtd/nand/sunxi_nand.c +++ b/drivers/mtd/nand/sunxi_nand.c @@ -931,6 +931,7 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd, struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); struct sunxi_nand_hw_ecc *data; struct nand_ecclayout *layout; + int nsectors; int ret; int i; @@ -959,13 +960,14 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd, ecc->bytes = ALIGN(ecc->bytes, 2); layout = &data->layout; + nsectors = mtd->writesize / ecc->size; - if (mtd->oobsize < ((ecc->bytes + 4) * ecc->steps)) { + if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) { ret = -EINVAL; goto err; } - layout->eccbytes = (ecc->bytes * ecc->steps); + layout->eccbytes = (ecc->bytes * nsectors); ecc->layout = layout; ecc->priv = data; @@ -988,6 +990,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd, struct device_node *np) { struct nand_ecclayout *layout; + int nsectors; int i, j; int ret; @@ -998,8 +1001,9 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd, ecc->read_page = sunxi_nfc_hw_ecc_read_page; ecc->write_page = sunxi_nfc_hw_ecc_write_page; layout = ecc->layout; + nsectors = mtd->writesize / ecc->size; - for (i = 0; i < ecc->steps; i++) { + for (i = 0; i < nsectors; i++) { if (i) { layout->oobfree[i].offset = layout->oobfree[i - 1].offset + @@ -1022,13 +1026,13 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd, layout->oobfree[i].length + j; } - if (mtd->oobsize > (ecc->bytes + 4) * ecc->steps) { - layout->oobfree[ecc->steps].offset = - layout->oobfree[ecc->steps - 1].offset + - layout->oobfree[ecc->steps - 1].length + + if (mtd->oobsize > (ecc->bytes + 4) * nsectors) { + layout->oobfree[nsectors].offset = + layout->oobfree[nsectors - 1].offset + + layout->oobfree[nsectors - 1].length + ecc->bytes; - layout->oobfree[ecc->steps].length = mtd->oobsize - - ((ecc->bytes + 4) * ecc->steps); + layout->oobfree[nsectors].length = mtd->oobsize - + ((ecc->bytes + 4) * nsectors); } return 0; @@ -1039,6 +1043,7 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd, struct device_node *np) { struct nand_ecclayout *layout; + int nsectors; int i; int ret; @@ -1051,8 +1056,9 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd, ecc->write_page = sunxi_nfc_hw_syndrome_ecc_write_page; layout = ecc->layout; + nsectors = mtd->writesize / ecc->size; - for (i = 0; i < (ecc->bytes * ecc->steps); i++) + for (i = 0; i < (ecc->bytes * nsectors); i++) layout->eccpos[i] = i; layout->oobfree[0].length = mtd->oobsize - i;