From patchwork Tue Jun 13 13:45:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105348 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp414924qgd; Tue, 13 Jun 2017 06:49:43 -0700 (PDT) X-Received: by 10.98.245.24 with SMTP id n24mr56362887pfh.80.1497361783346; Tue, 13 Jun 2017 06:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497361783; cv=none; d=google.com; s=arc-20160816; b=Qe3JCgkXdYUS6zuHy8IKhGxuxaD9qmQlkdJA9feRYHzpN4W9FePsFN7K97KDCORlv5 nwkHWNMt2+bzBeslm7Eh3nrFwj8qZl78ePN9YoYFA72llz+EMfLfRuVPv7pbRluyuXTH FXyJVKBIwvExm4lPnGf4h/4NcpWNGtHlx24E7vzJKc45i6VoFVC/Gg2hY9ip/C2KvOWE Ufy6D+nbtbCTFLsSfUfmNE5MS2Bwe+0tLYz+uLiOtuq9aLP9ED63JkVQtdPMw/aWUHHD sfEVekQX32MFw5LZC2jiI0oJC2C+84WevWxI7uIedGt1JC03FNQNLdkw56Hqr1GZNvg3 Gzkw== 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=yHmciAuFy6YgdjeirBEGC6s4bonnciJTKcty035fXpU=; b=nJO3V1Uju4/0z9nlk5Yjar3HhwFl8PHQRr4JfmO6UvwuE/2Kwtu8AJ5VZ0APYZ74e3 LMTVsE1VRQOFVcSlvDCLv0KV0TLEZ6Ir+BfpTfOB3B9OhFkno9UJ8uyc3YXaSH79Euv3 c9SXIMuwUg+s+k0i+mioqnj7NxnYnETD3V0SASRVPSTIg9PYn2lLqStSD1J6dAYGg4ax TZJE4R8jZ9Mz9L7MN9kfVc+o8a/gvPiQJEkGbOPTf0euMC8uIH7TjxQ1M8b01g9d78X8 Tku6qmUP6Alq08ORMU+3nIs6XyW8nvIsfFUK6oIttnp3OwoiUzii6DiZQPJF7y9Ox3YR dSfA== 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 s61si9485071plb.503.2017.06.13.06.49.43; Tue, 13 Jun 2017 06:49:43 -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 S1753727AbdFMNta (ORCPT + 25 others); Tue, 13 Jun 2017 09:49:30 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:32353 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753706AbdFMNt2 (ORCPT ); Tue, 13 Jun 2017 09:49:28 -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 v5DDjxix031338; Tue, 13 Jun 2017 22:46:22 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v5DDjxix031338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1497361583; bh=yHmciAuFy6YgdjeirBEGC6s4bonnciJTKcty035fXpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Noz6e7Ebheamu7ZWSkY42kDBIbtQotvxUwpeMEDjvgXl0fv8Ye4K1yts1nPj/ny9e T9R8vYp0lokm/HW+z5z+fe/3KCkVyuqxVXB1LFHUceyDDGNTXFgLjHRJRqZkz/eeWv 87FHPz/eFixrD+e4nCZDtsBSDNR4oe+rreOKB5OimkBg8WAOlohW59V+e8TJT0H74V 65JFMLzrLVF4IwbMrfqGcQ6LLDwcPRVoypGCKbRiN9T9magE+p9IEcVt/o/WUayvQf 1LxGgSZKtR0BFHw8D5ARp4pcmQ3zmcs1vV7J37+ydzj/y+20sKi7n3nPxs8tszbTCX pSGlMKss0NcqQ== 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 v7 14/16] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Tue, 13 Jun 2017 22:45:48 +0900 Message-Id: <1497361550-8115-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497361550-8115-1-git-send-email-yamada.masahiro@socionext.com> References: <1497361550-8115-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 v7: None 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 ec5fc8da5f9a..bb2da2fd069e 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "denali.h" @@ -1352,13 +1353,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; @@ -1443,17 +1437,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); @@ -1467,6 +1474,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);