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: 775212 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 3wnBMG6vCpz9s0Z for ; Wed, 14 Jun 2017 00:03:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TCd9xViQ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="C5D3VJUi"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="Noz6e7Eb"; 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=EXaV+8ZKbGrplhlVggBD66vkWfcnUxCLFUUTN8Ooc6A=; b=TCd9xViQ3yc8LoEQAzmqkuTJET Iklp+Sh3EzrbujPDVE2URJpPQADY8t8rSBBqwDpkDQS8czqCD+hocOycYEC+xC0hh2w6dnvsAVhe3 eiARN65obPrffb5CkDL6+mTr4Nc9t/XVjKtcET30/a9TgH2h+qB04aVSHZAfYpKt4Ty5TUTaNpccY nQ6cwIpWIk/dYs9zxgvM9P1xgGvh/MvaYMILckv0z50cmtovAqP1ZebqI/e6GLwSLzZ2xOVloN1s4 Z5I3Q0b6g9TwPIBtNKGYFGmiZOKJBOXPu7P2rKwOrSoqPO+ZKAJj2f4UQffW5BMIDxhU0NIBcYabw tZgmTxxw==; 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 1dKmPz-0003Pc-OX; Tue, 13 Jun 2017 14:03:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKmJg-0007D2-FK for linux-mtd@bombadil.infradead.org; Tue, 13 Jun 2017 13:57:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yHmciAuFy6YgdjeirBEGC6s4bonnciJTKcty035fXpU=; b=C5D3VJUi1GnVH+1YCabf6HZyL xzK+BG6vIXRwhBp71er29DJuzhgdiNli0ohf9bOLgC6vOuPFR+T5GQBi8kCUChZFHhM8Rbinvi+EP oiYvNbl/8Kw/y7IThlxOqbmurPsCIXdmjdBlJ0xjX7cNU/i2+VJ/lPRPPRwejLBnyub8nJR1yRrcg 4qbfCwjahTI/zk77Fcoqz/OMHOfzDKDRkWumDwjmRDZw23PzieHKBTIXk5s1mmkPXOzcx2zxypLJV f2pYOtF9BfWhvmx7I6t7Xy98tyI+uMSwstWs+Qr8NzMwX6Hfjv0xF1Yh+7VVMUXwcPz8g7s3FZthH 3U5BrSgsg==; Received: from conuserg-09.nifty.com ([210.131.2.76]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dKmAM-00018U-7o for linux-mtd@lists.infradead.org; Tue, 13 Jun 2017 13:47:34 +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 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170613_144731_082671_BB263911 X-CRM114-Status: GOOD ( 16.35 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.2 points, 5.0 required) 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_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 , Richard Weinberger , Marek Vasut , Masahiro Yamada , Artem Bityutskiy , Dinh Nguyen , linux-kernel@vger.kernel.org, Cyrille Pitchen , Enrico Jorns , Russell King , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Brian Norris , David Woodhouse 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 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(-) 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);