From patchwork Tue Jun 13 05:04:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 103700 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp236338qgd; Mon, 12 Jun 2017 22:08:18 -0700 (PDT) X-Received: by 10.101.70.70 with SMTP id k6mr60528510pgr.39.1497330498162; Mon, 12 Jun 2017 22:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497330498; cv=none; d=google.com; s=arc-20160816; b=ZPI0zp5WQRGqBRuvT9JRB/8SatTTQ7JBmAv3qunng7EcJtqmHpbWNwuf46MtxtBmTL VpEev9nj8+Fo6GatL238zvyLs4JqpjcQxxFqjWVWGljrlZWSOnymqWJ2+LTUF7H2wMgV Qx/+CNrSutaHORTWptY/yUv94sbHjbZB8nB7eypTZ3LRbUWtRVF78LabWsxN9nuzUZOF d6Puv/iScrqxyvxTU2jkJ4/UUBUSil6vfDF1mIHrzTR2Mba5yt2iqpc0qhkOvWoWTPm3 AheRuxxnqm1p0YWVSzkmEcaxl8Ax8kWZBdZie9cCRSd4BmcpTCstxKxyvmx22BDtpdlA jFsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=+N/Lh4wla0YPpJKHh//TpnMBYOjIAoc8Qu5K+4qrsWI=; b=O4MGWrpRqZe6Qp92L5LyKviIkaPxfl9gWPMoG+ClOoWPw4AaOAPLBZkdJ5ZjNTjXdW SAItttP+WuayMfJdn2XcR7j+QBwkXxp6XZ4QerrfHb/lAGnU95XONrSjAioP1MkUnTfU 5+alo2QS7WMOBakeajru5nhedK2kGK8U9Y/lGN/mHmef43yh1/tAoejvjiWY7PHw4ZcG 4GGAgNmZE7KbbdNp6mvGLx74W79W8+W18FWpYuh97w2HAY0JROrZdG4M/u39SAwqBpis tvwN85sa0saNLikzuHVC11osja1YhIFMF5rP9F7JJbAbHH9QdRIceTHbmqoVsApG/TFu BugQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k130si8390134pfc.300.2017.06.12.22.08.17; Mon, 12 Jun 2017 22:08:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752543AbdFMFHp (ORCPT + 25 others); Tue, 13 Jun 2017 01:07:45 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:48477 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518AbdFMFHn (ORCPT ); Tue, 13 Jun 2017 01:07:43 -0400 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 v5D54ENu023096; Tue, 13 Jun 2017 14:04:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v5D54ENu023096 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1497330274; bh=+N/Lh4wla0YPpJKHh//TpnMBYOjIAoc8Qu5K+4qrsWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MA8vZKPBm+Z1oNzRDdRhGX51YUwAT00N9N/b5AEJZoI4MdQEkt70e0K4mOHh3uF25 yMt+jch5mqkSUrSaFe3XE+iNxSjs5XqgHripuA/q/0dgArkrP2+7ub2Njc7OsZVXDL 5DC/IZhc+E+miXXM4kMCQbMQwxcZF31TT9EVgm1cIRuzFT62ESsrLqvYndZWglDPd2 ow1zCItfSqaykw1CiB32m7+Mumxx+vdxx1uf9KjHK3F8somvuiP7evDU+IpPy61ZLi QOQlTminiOChlRchbezdDf4N876S3KL21kZ67RQAlAxMJQst0X2W+MCcXD+AQQcxbE kEJEhCdC5crXA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Enrico Jorns , Artem Bityutskiy , Dinh Nguyen , Boris Brezillon , Marek Vasut , David Woodhouse , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Masahiro Yamada , Russell King , Lars-Peter Clausen , Cyrille Pitchen , linux-kernel@vger.kernel.org, Brian Norris , Richard Weinberger Subject: [PATCH v6 16/18] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Tue, 13 Jun 2017 14:04:08 +0900 Message-Id: <1497330250-17348-17-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497330250-17348-1-git-send-email-yamada.masahiro@socionext.com> References: <1497330250-17348-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Newly added drivers/mtd/nand/denali.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 918b9b9bbe53..d37fb82f39ed 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; @@ -1434,17 +1428,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); @@ -1458,6 +1465,7 @@ void denali_remove(struct denali_nand_info *denali) struct mtd_info *mtd = nand_to_mtd(&denali->nand); nand_release(mtd); + kfree(denali->buf); denali_disable_irq(denali); } EXPORT_SYMBOL(denali_remove);