From patchwork Sun Apr 9 14:17:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 748755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w1FlJ1SPdz9s2P for ; Mon, 10 Apr 2017 00:17:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tJsh5zi9"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Byn1WJm5+pUF0MNJ7359ADlEwGEdVdnVu9neiUimheY=; b=tJsh5zi9EdU8oE DGY9FzjOMJzFz7XyUobH8ijEccqPGte5vOQmUKzRE49fmIyhQhVLx7XYlvQTSkg1AVzzk0R1a/GG4 8HqtyHquHxIcbLbl5+JTGy9g1vZDNsA/DBC7pMpo6G9UKnD0h3SU6y4Ygjbdm/CO01ANhH5tzN1Ov ygUySf0c8rHtimSG5hnH/aY4ZTJTev1k92il+1kUvSX2RNC0tGt78HuznhtAnd7lWcdRekYNX/mVD DXz2U/lxwzoVVIpuHOBkk+v5ZPH0r6qSTckDUYoVXkKP2XA8ar7dE94aozEzGZTO/4rCUHWGOKc/A O/vXpCC10fF3grNGdknQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cxDex-0001Hu-Fc; Sun, 09 Apr 2017 14:17:43 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cxDet-0001En-FO for linux-mtd@lists.infradead.org; Sun, 09 Apr 2017 14:17:41 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 84A5820834; Sun, 9 Apr 2017 16:17:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.free-electrons.com (Postfix) with ESMTPSA id 42A6E20759; Sun, 9 Apr 2017 16:17:17 +0200 (CEST) Date: Sun, 9 Apr 2017 16:17:17 +0200 From: Boris Brezillon To: Masahiro Yamada Subject: Re: [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset Message-ID: <20170409161717.0f59bc9d@bbrezillon> In-Reply-To: <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170409_071739_810579_0655D91D X-CRM114-Status: GOOD ( 20.93 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 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.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Enrico Jorns , Artem Bityutskiy , linux-kernel@vger.kernel.org, Dinh Nguyen , linux-mtd@lists.infradead.org, Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , David Woodhouse , Graham Moore Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On Thu, 30 Mar 2017 17:15:04 +0900 Masahiro Yamada wrote: > Some NAND controllers are using DMA engine requiring a specific > buffer alignment. The core provides no guarantee on the nand_buffers > pointers, which forces some drivers to allocate their own buffers > and pass the NAND_OWN_BUFFERS flag. > > Rework the nand_buffers allocation logic to allocate each buffer > independently. This should make most NAND controllers/DMA engine > happy, and allow us to get rid of these custom buf allocation in > NAND controller drivers. > > Signed-off-by: Masahiro Yamada > --- > > Changes in v3: > - Reword git-log > > Changes in v2: > - Newly added > > drivers/mtd/nand/nand_base.c | 34 +++++++++++++++++++++++++++------- > 1 file changed, 27 insertions(+), 7 deletions(-) > > diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c > index f828ad7..e9d3195 100644 > --- a/drivers/mtd/nand/nand_base.c > +++ b/drivers/mtd/nand/nand_base.c > @@ -4613,13 +4613,25 @@ int nand_scan_tail(struct mtd_info *mtd) > } > > if (!(chip->options & NAND_OWN_BUFFERS)) { > - nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize > - + mtd->oobsize * 3, GFP_KERNEL); > + nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); > if (!nbuf) > return -ENOMEM; > - nbuf->ecccalc = (uint8_t *)(nbuf + 1); > - nbuf->ecccode = nbuf->ecccalc + mtd->oobsize; > - nbuf->databuf = nbuf->ecccode + mtd->oobsize; > + nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); > + if (!nbuf->ecccalc) { > + ret = -EINVAL; > + goto err_free; You have a memory leak here, because chip->buffers = nbuf is only done after all allocations have succeeded. > + } > + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); > + if (!nbuf->ecccode) { > + ret = -EINVAL; ret = -ENOMEM; I have the following fixup patch, let me know if you're okay with it and I'll squash it in the original commit. Thanks, Boris --->8--- From 7903e4c997da101bc0f15016936116c4bb9db78c Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Sun, 9 Apr 2017 16:14:36 +0200 Subject: [PATCH] fixup! mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset --- drivers/mtd/nand/nand_base.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 23a415d1f124..ed49a1d634b0 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -4501,7 +4501,7 @@ int nand_scan_tail(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); struct nand_ecc_ctrl *ecc = &chip->ecc; - struct nand_buffers *nbuf; + struct nand_buffers *nbuf = NULL; int ret; /* New bad blocks should be marked in OOB, flash-based BBT, or both */ @@ -4518,20 +4518,23 @@ int nand_scan_tail(struct mtd_info *mtd) nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); if (!nbuf) return -ENOMEM; + nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); if (!nbuf->ecccalc) { - ret = -EINVAL; + ret = -ENOMEM; goto err_free; } + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); if (!nbuf->ecccode) { - ret = -EINVAL; + ret = -ENOMEM; goto err_free; } + nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); if (!nbuf->databuf) { - ret = -EINVAL; + ret = -ENOMEM; goto err_free; } @@ -4773,11 +4776,11 @@ int nand_scan_tail(struct mtd_info *mtd) /* Build bad block table */ return chip->scan_bbt(mtd); err_free: - if (!(chip->options & NAND_OWN_BUFFERS)) { - kfree(chip->buffers->databuf); - kfree(chip->buffers->ecccode); - kfree(chip->buffers->ecccalc); - kfree(chip->buffers); + if (nbuf) { + kfree(nbuf->databuf); + kfree(nbuf->ecccode); + kfree(nbuf->ecccalc); + kfree(nbuf); } return ret; } @@ -4829,7 +4832,7 @@ void nand_cleanup(struct nand_chip *chip) /* Free bad block table memory */ kfree(chip->bbt); - if (!(chip->options & NAND_OWN_BUFFERS)) { + if (!(chip->options & NAND_OWN_BUFFERS) && chip->buffers) { kfree(chip->buffers->databuf); kfree(chip->buffers->ecccode); kfree(chip->buffers->ecccalc);