From patchwork Thu Mar 30 08:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 96256 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp127977qgd; Thu, 30 Mar 2017 01:16:24 -0700 (PDT) X-Received: by 10.98.153.11 with SMTP id d11mr4864060pfe.15.1490861784721; Thu, 30 Mar 2017 01:16:24 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id i63si1446492pge.321.2017.03.30.01.16.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 01:16:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3xAqDNQbFCJ+DGGg11ydkSNkQdl7YeX9WyWHGnrgLCI=; b=ZdwHlFs7yw7HoZ/1cTL+8lvhoc jXPRfVfRNygAFloDuHGVIzckMLDaZ3CqcGNm7h7PQUeLZHElaDkaKEUW59znaqXNa0S300/ugEVYb I5nRxsZXlntxzxYWVNHtH+nfx4kDWfzDshezMmmHPVQcGTxqyNDE/yl5d+RjfYK+rWhqszJVuRsVO EiJ4hzeNbrqDTzBNBDNtkJ2F4b+UIboEt75bhTlXoJ605rMpzeu6tm2DbIY28G79j9w9oMhgtqOQO wcHTmYlsk2FVPr1ddyV9x10koP3LthRmphSCBbo7brir7dF39czjuJTfX1wXx+CdaAzPaRFzDiS4V hUdKljuA==; 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 1ctVFh-0003qV-Fj; Thu, 30 Mar 2017 08:16:17 +0000 Received: from conuserg-09.nifty.com ([210.131.2.76]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctVFd-0003og-PW for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 08:16:15 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2U8FQ9g018607; Thu, 30 Mar 2017 17:15:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2U8FQ9g018607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490861730; bh=IOrRGFWxoDPYCwyqFkpr8IGkTaZKj8twEnnJUl4yrk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VdB0ev6Q0iaJQAxtcXhlNp20oZB+EDSFFPxnvzjS8InNZKKzSHuHwcFhDbkwZ8TYp okTGJ2/FQX58X9auZbAlBUluI0v2p52c+mfrrmQhC1oJLjAJKJqu7/xqW76WouvOzu CN0pa3/0JzYefj+Wrbe1A3ZFWOHH/UvtDaH8SxIDtAuaVAG8U+7D9SWTT0TA5Lp3VP 2imkLMjyCHYEtSV5GvGdx0XiLb5RXjZZSn/yD2F+Nfboa5k7fRjKxtSWscDRhFcsvy O2prWTNTCReEXpUlygyOMGHYYnwfWbYn30clnJxN0r0s/iTAkVIBdnE0duRBt0cFaD 2Sm8j91pmdSKg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset Date: Thu, 30 Mar 2017 17:15:04 +0900 Message-Id: <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_011614_111690_BC9B9FE9 X-CRM114-Status: GOOD ( 11.07 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Boris Brezillon , Marek Vasut , Enrico Jorns , Artem Bityutskiy , linux-kernel@vger.kernel.org, Dinh Nguyen , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , David Woodhouse , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org 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(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ 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; + } + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!nbuf->ecccode) { + ret = -EINVAL; + goto err_free; + } + nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize, + GFP_KERNEL); + if (!nbuf->databuf) { + ret = -EINVAL; + goto err_free; + } chip->buffers = nbuf; } else { @@ -4862,8 +4874,12 @@ 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)) + if (!(chip->options & NAND_OWN_BUFFERS)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } return ret; } EXPORT_SYMBOL(nand_scan_tail); @@ -4914,8 +4930,12 @@ 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)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } /* Free bad block descriptor memory */ if (chip->badblock_pattern && chip->badblock_pattern->options