From patchwork Wed Jun 7 11:52:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 103241 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1715075obh; Wed, 7 Jun 2017 04:56:24 -0700 (PDT) X-Received: by 10.84.208.102 with SMTP id f35mr23783437plh.92.1496836584554; Wed, 07 Jun 2017 04:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496836584; cv=none; d=google.com; s=arc-20160816; b=T+3qA5691jmT0ShW1F4U31ozKLKYvSFx5lNs66ldwhuF2Wm3YSuePd178Qb83pnIGZ 59Z7lLoCiwnzvc8ORxnqCvU136mgICuo7NtLD/g8p6ty1R6EHjfZwNhy1elH/lnHQp3t 92TIs4Q/kvr0HfkveKE5x5f2SYPzVaJ2XbDvyUVaV3sIYZhYlkhEcgtX9JOlZDCu8uEV JfjF11G/nE4OsureqcFtNg9tE/LPqGtCHb/U69k5g8/4Ml7U0T19whOZkSM1Rx1Ll/1l OGvsBcHOZdWMs1DupPwXk2TsR2kpKO52MKqgqHFHMPFU2+vyHWfLvAxvk9soxf1Rxqsd YMaA== 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=IGtzcXChHR8L6XB3tbuR6nceT3T4zeLYQMP519Y7uuk=; b=d8j2gtsP8Een17ZU3XzBeaqYHNHD7RNA3XWScjHofPy7eRFV5a5TmNxMCnsll16oM0 +E7mUHC1JZ3E4ta6EywqdcVPcSTOEqs0lzc8ZB6lHTX+9vbqVarqatah53xuMdOBUdIb Esm3EOJ/AOikeeKkt8ifsDBWb18gb+FpaZBw1b+USx9ceUEmvxva25meQamrxdbufWMe nJBXIc3fgcKeyFAENHeUJB813/DQELknRHksK0CeiTHViOeeDsA7KNRHG3/a7J126yo/ sEf6B85tPi/li2Bsm2K9kWGPrv8sDGbHCEsOZY5HWtKJo5BOPjIEbBFdZTrypZi8QzZA lKMA== 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 g77si1675645pfb.41.2017.06.07.04.56.24; Wed, 07 Jun 2017 04:56:24 -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 S1751816AbdFGL4G (ORCPT + 25 others); Wed, 7 Jun 2017 07:56:06 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:43591 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751457AbdFGL4D (ORCPT ); Wed, 7 Jun 2017 07:56:03 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id v57BqjZl014276; Wed, 7 Jun 2017 20:53:12 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com v57BqjZl014276 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1496836393; bh=IGtzcXChHR8L6XB3tbuR6nceT3T4zeLYQMP519Y7uuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bqulELfkqsM39nc6r7tthRZInZDRwiBvHqIgKwJpNaTwIb6JnBtIfK2tzDsZDM0tB 5TZjl99rwOVKmQkkwhdTQEL4fgt8XAcQOOXXSkPr7KjTilQVZognkq4lEcg9kf0psb rbi5oUhC0VswTQ3yK8mw8IrauuHgJcqJRkUneaNjaF8fuqkSCoxjCAjO+DSOz0tlwr 8qcySsjU6B7qZu1+wyg+kPAXYqpNOSZsKrbGuAQrTR5oV661bnzwmp5jpMT8sa7PNj SMMIa1CaTU4dXU7Gxq4p8ZX7Mf9U8Vlw4hKSzBdT90+Bj7Z4C76qkcN0igwXhCssXn 3l7WsVhUdQBKA== 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 v5 22/23] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Wed, 7 Jun 2017 20:52:31 +0900 Message-Id: <1496836352-8016-23-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496836352-8016-1-git-send-email-yamada.masahiro@socionext.com> References: <1496836352-8016-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 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 963638693850..904f859e19b6 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "denali.h" @@ -1386,13 +1387,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; @@ -1477,17 +1471,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); @@ -1501,6 +1508,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);