From patchwork Thu Mar 30 08:15:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 745142 X-Patchwork-Delegate: boris.brezillon@free-electrons.com 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 3vtyKP0NsZz9s2Q for ; Thu, 30 Mar 2017 19:22:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W/fW+pXk"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="WmdCxCtu"; 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: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=9P0+8CgvqijFuueGJyLF7qDnOMLhu1v7lkrB0O+Cucc=; b=W/fW+pXkBb83JymcYOyj7lDT1p /AtjSVZNiI2yPuRVPwtOCdwh4nuoSSyxXmx0lWQzZ3fNzwU5PbrijlSY1b8XyCE7It7ChJDySXBND S/jIgoZb26bUEQ6I/zPVWJtPX478oEa6Bq/GwLSrCI4xl1d5y9yC+tezs42DOYs+ypDMLdbSEfLia p0WT+DTKedDYNPSBr9UYi5UbpLb+xL70SNAJfF7n8Dm6oHz4ev93NPxNfvL7V5FgAL8KfrRcVBStN kcaW7zpstqjdaDPavMsiFngodBceuGjTGXce4jjcuTo+AUMQrt6OvuaXXuePaVj7xG2Wh4WY9SP4Q wc2pSMzg==; 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 1ctVL4-0006zL-H7; Thu, 30 Mar 2017 08:21:50 +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 1ctVG5-0003uH-CW for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 08:16:44 +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 v2U8FQ9j018607; Thu, 30 Mar 2017 17:15:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2U8FQ9j018607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490861734; bh=0CEBIFRr8sld2Gifou4C3ZDK6k+BvNgn4dT7mojRxPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WmdCxCtuSmU4m23FOERl+cXASLgHRZIBQwhRGTTacmJO/7TM/Owrk2/cx+sHxOsfO YbPYMK88IYDvQdUB62j1M4BqXlxHar8ayndbXy9JBjcdpwjOlZHh+VaL2/TIHdOOZ2 ANMK1hcFdoSZP9BqzAUDHq8iuhVffJhrNdSIWLceFNbbWHSLWwILPHCKEUvR/NOi1c GDjHBwaR11b0Fmt7PD2woFiwfxcJ5+W+e8dYqK3MvCSUJikruGxo5JDE69meUdIytM XfyBE04Xsjn/+WFP/VI1nll803i0xUzYP3/Z+vT3tb26zwkzOIyZrhkqzvvnDAslVd 4mAYFe7EUa+kQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v3 36/37] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Thu, 30 Mar 2017 17:15:07 +0900 Message-Id: <1490861708-27813-6-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_011641_762901_7061D691 X-CRM114-Status: GOOD ( 13.36 ) 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 , Lars-Peter Clausen , Marek Vasut , Enrico Jorns , Artem Bityutskiy , linux-kernel@vger.kernel.org, Dinh Nguyen , Russell King , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , David Woodhouse , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.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 Acked-by: Robin Murphy --- Changes in v3: None Changes in v2: - Newly added drivers/mtd/nand/denali.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 87e5f0f..d10702d 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "denali.h" @@ -1388,13 +1389,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; @@ -1514,17 +1508,30 @@ int denali_init(struct denali_nand_info *denali) if (ret) goto disable_irq; + /* + * This buffer is DMA-mapped by denali_{read,write}_page_raw. Do not + * use devm_kmalloc() because the memory allocated by devm_ does not + * guarantee DMA-safe alignment. + */ + 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); @@ -1544,6 +1551,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);