From patchwork Thu Mar 23 00:18:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 95871 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp497664qgd; Wed, 22 Mar 2017 17:35:41 -0700 (PDT) X-Received: by 10.98.9.156 with SMTP id 28mr49775901pfj.199.1490229341117; Wed, 22 Mar 2017 17:35:41 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id a68si2521057pfg.49.2017.03.22.17.35.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 17:35:41 -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=@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=s4ub9P3tiUS2FtprF4IYnXkNt12SVlMHXELrnWSr/iY=; b=eLb+9K97ZjqBLQS6WTxYe7KnA+ Hx2Me6Y/fUVIriLFK9mKi+ra1RruSI5uF87dssXjLTAvyf5OZocyLFiyklgVg5yAVYtfRYVYPJqXu HAPubpLKWyArxe94gd1sDXGBNIImgyPInGMYII8qwOUR4FeLSkwaDJfvwCdO78JOtlaKfBFQrWbnX 5naXvq3PKG/XzDjSvssurI9AJ6T+oBI68ROZg3TmOnikHCxiGnAzRdhf9jFgJZtfdoD2vd0axfrUZ kMaXA+abZ7KQjw0KJH8a9sEogolwgp4yk8veDtwRzlr32UdBrXjzq8Np8A/eh0331/xYtN6BMenVi ITzx4jjA==; 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 1cqqiz-0006br-St; Thu, 23 Mar 2017 00:35:33 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqix-0005Jp-Sk for linux-mtd@bombadil.infradead.org; Thu, 23 Mar 2017 00:35:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5+Kpnw0NBHfXQtqa9eqVNXZsagmz9byp09rBI4SpLl4=; b=qa/2kXspC2++TREyboqZfrxDx /mcK5VhLMm4T34hfZOuaPDKnctae82sPKtIY886NBmd9LN3z8owMC0n522Kd9D3SPkGnrSv1YwqAA jJqxRCbzwWVMjSWbGfhtv0jifPaNglSIMPNv5E89hK2BP1LzgQqOdML97VbXR/dBECwf08cZe9i0t ygydiyKuwY5L4behRkoG/Rppjr6viG+dUBlB3Yk+ez5wfRzBHa4FMMTSNgzJlvJ4IlFzVcsGg/qMD mttKKUgrehcOCUHfrBR/XBmkUlWNMBsE1GrJxOLNnWgY3WcHLJJNU6cI2HnYo3JjsRdNBZ9h6AESq WMqKPJMOw==; Received: from conuserg-09.nifty.com ([210.131.2.76]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqTY-0001Gb-7K for linux-mtd@lists.infradead.org; Thu, 23 Mar 2017 00:19:38 +0000 Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2N0I4c4008011; Thu, 23 Mar 2017 09:18:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2N0I4c4008011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490228316; bh=5+Kpnw0NBHfXQtqa9eqVNXZsagmz9byp09rBI4SpLl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rVsEdaYYPMtA3CeRzU6rStnkh02GcbvOY65QSAbHGM+PbFq09wRsc22/K6WLxxHlu AwWMv3PKXAo5K74y3HUSPSewoiW6x1D8R/2vre+Bzxcs1SMP1PNOEBjuzqBU2Banlf F7G7Ne9hlYEgLFCu9L0P2P2T9anWUoGnXa66sJrYychC9PolyT2lLGOewCKsi73bdr Hrygy5u7VHcVBfBSPRR8Cxkad1bRWg7sipilxLzQ+La5EdEqz9uSpqqcoSOU65IXAm 6A1if1RRyNacTmOmTSR5LWdOE45LBHc6WR8BVzlftmwiRjXIm2JMp/fZLyf4+zjW6T 9aURClMfWT+CA== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [RESEND PATCH v2 52/53] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Thu, 23 Mar 2017 09:18:01 +0900 Message-Id: <1490228282-10805-26-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> References: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170323_001936_910476_D839CDD9 X-CRM114-Status: GOOD ( 16.46 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.2 points, 5.0 required) 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_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: laurent.monat@idquantique.com, Boris Brezillon , thorsten.christiansson@idquantique.com, Lars-Peter Clausen , Dinh Nguyen , Enrico Jorns , Artem Bityutskiy , Robin Murphy , Marek Vasut , Russell King , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Brian Norris , David Woodhouse , Rob Herring , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org As Russell and Lars stated in the discussion [1], using devm_k*alloc() with DMA is not a good idea. Let's use kmalloc (not kzalloc because no need for zero-out). Also, allocate the buffer as late as possible because it must be freed for any error that follows. [1] https://lkml.org/lkml/2017/3/8/693 Signed-off-by: Masahiro Yamada Cc: Russell King Cc: Lars-Peter Clausen Cc: Robin Murphy --- Changes in v2: - Newly added drivers/mtd/nand/denali.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ Acked-by: Robin Murphy diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 4900745..28622a9 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "denali.h" @@ -1343,13 +1344,6 @@ int denali_init(struct denali_nand_info *denali) if (ret) goto disable_irq; - denali->buf = devm_kzalloc(denali->dev, mtd->writesize + mtd->oobsize, - GFP_KERNEL); - if (!denali->buf) { - ret = -ENOMEM; - goto disable_irq; - } - if (ioread32(denali->flash_reg + FEATURES) & FEATURES__DMA) denali->dma_avail = 1; @@ -1460,17 +1454,29 @@ int denali_init(struct denali_nand_info *denali) if (ret) goto disable_irq; + /* + * This buffer may be DMA-mapped. Do not use devm_kmalloc() because + * the memory allocated by devm_ is not cache line aligned. + */ + denali->buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); + if (!denali->buf) { + ret = -ENOMEM; + goto disable_irq; + } + ret = nand_scan_tail(mtd); if (ret) - goto disable_irq; + goto free_buf; ret = mtd_device_register(mtd, NULL, 0); if (ret) { dev_err(denali->dev, "Failed to register MTD: %d\n", ret); - goto disable_irq; + goto free_buf; } return 0; +free_buf: + kfree(denali->buf); disable_irq: denali_disable_irq(denali); @@ -1490,6 +1496,7 @@ void denali_remove(struct denali_nand_info *denali) int bufsize = mtd->writesize + mtd->oobsize; nand_release(mtd); + kfree(denali->buf); denali_disable_irq(denali); dma_unmap_single(denali->dev, denali->dma_addr, bufsize, DMA_BIDIRECTIONAL);