From patchwork Mon Jun 5 23:22: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: 103106 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp1008681obh; Mon, 5 Jun 2017 16:26:16 -0700 (PDT) X-Received: by 10.84.130.99 with SMTP id 90mr17920726plc.165.1496705176858; Mon, 05 Jun 2017 16:26:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496705176; cv=none; d=google.com; s=arc-20160816; b=Q7fMEKtdqwLWfVmgFqJXUZX9aNSICdR9lj5HbF8t4RxvnHD6zpEv8vC5MugPIR9FYf xo5CRdEatVtDZxGgcVUCir2u4LlHz77VWUMY7Egd4tEazMnR644w+m5DdQo1RfqxkbIN IeFVPWga4RxbkmChvygvQ9plolOak7tQfyQyAv567l6O3QpF1pDaupSf29lTjlQcWk27 JoYpSQofwSd091j192Xa1Gi+M+m3sYU185G25/orvGbYWc+zd+0st6j80Mr0902bci5D JMNzT6kPjma1Ja0sXv5YcQOD1SNA5PLainOZi+MCTpmD/bXKUXgFCWAYyJZMgYej8fux yf6w== 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=X8h7KinnPluL+lW1v2CJ7MKtlc/wGtCugyJkh29v8uY=; b=x0LR5YVm49DIKGqCfldn56IwJVJ4nEYIzAq8Ys3fCYvipW47PmKt1bne1ciaV4BBE7 PdGTTxnT4+nRyIhfYMn0CBaKXDgjioTYs7qCbpgeOY/XBpH4fOUT5HZnlN2F9GLwYZ1r RccVdJalZ6NZgZt/BE0IljYeDxtuWn1uq3vTVTR366U2DaAY8yAZTQ0odBttrwwj9Mpr IyPobP7+fhGCi8Wkldp9LmI85Y7qEPMrz/JF89Po3zTEOzQxXGiNsVLBPLLK3bGztFAZ 0OXUpY+2TNe5x/xhPf2iEamD00phOKJNwXEIbgk2n2ZpUWM8if+2e48N9STcOhXt4VaF Cusw== 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 v61si8327189plb.188.2017.06.05.16.26.16; Mon, 05 Jun 2017 16:26:16 -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 S1751471AbdFEXZx (ORCPT + 25 others); Mon, 5 Jun 2017 19:25:53 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:33068 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751246AbdFEXZv (ORCPT ); Mon, 5 Jun 2017 19:25:51 -0400 Received: from grover.sesame (FL1-118-110-19-204.osk.mesh.ad.jp [118.110.19.204]) (authenticated) by conuserg-10.nifty.com with ESMTP id v55NMD5w004412; Tue, 6 Jun 2017 08:22:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com v55NMD5w004412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1496704974; bh=X8h7KinnPluL+lW1v2CJ7MKtlc/wGtCugyJkh29v8uY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pnV9ErzQCnpkiSF2MOotd6Ki0oyg0BtJc5YLYHvyTEmgu/FrAV/gFWOf5MqyOYxZR BYa1nPCQsP49TUkm95HsOPs651/X971GSqXHPOroQfTGkGUYmpAbLgjVXmI5Zb8RBc ttGpt4DMrbThg0o5xMX76yVK/AwZ5/doCbtzyw5oyn57MbX64Y5j9buUse9Qils7+b meR7XclVc/yH7T4bo32rNY43Jc7pkSBhnBnHNpBXGn4qwPWFDfm07F+o9mDscY+Y6H L1uLPW4B0A9Y4kFTgIAScSBdeGHEB0tNI4PyyO20bN612yRU1vigfC9PoK/QfOgwyo My4inj02JE+Og== X-Nifty-SrcIP: [118.110.19.204] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Enrico Jorns , Artem Bityutskiy , Dinh Nguyen , Boris Brezillon , Marek Vasut , Graham Moore , 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 v4 22/23] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Date: Tue, 6 Jun 2017 08:22:01 +0900 Message-Id: <1496704922-12261-23-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496704922-12261-1-git-send-email-yamada.masahiro@socionext.com> References: <1496704922-12261-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 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 e4ab397..f2b1592 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "denali.h" @@ -1402,13 +1403,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; @@ -1492,17 +1486,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); @@ -1516,6 +1523,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);