Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752791AbdDJAUl (ORCPT ); Sun, 9 Apr 2017 20:20:41 -0400 Received: from conssluserg-01.nifty.com ([210.131.2.80]:29115 "EHLO conssluserg-01.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752696AbdDJAUd (ORCPT ); Sun, 9 Apr 2017 20:20:33 -0400 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com v3A0KJ9v000843 X-Nifty-SrcIP: [209.85.213.180] MIME-Version: 1.0 In-Reply-To: <20170409161717.0f59bc9d@bbrezillon> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> <20170409161717.0f59bc9d@bbrezillon> From: Masahiro Yamada Date: Mon, 10 Apr 2017 09:20:18 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset To: Boris Brezillon Cc: linux-mtd@lists.infradead.org, Linux Kernel Mailing List , David Woodhouse , Marek Vasut , Dinh Nguyen , Artem Bityutskiy , Graham Moore , Enrico Jorns , Chuanxiao Dong , Masami Hiramatsu , Jassi Brar Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2518 Lines: 82 Hi Boris, 2017-04-09 23:17 GMT+09:00 Boris Brezillon : > On Thu, 30 Mar 2017 17:15:04 +0900 > Masahiro Yamada wrote: > >> Some NAND controllers are using DMA engine requiring a specific >> buffer alignment. The core provides no guarantee on the nand_buffers >> pointers, which forces some drivers to allocate their own buffers >> and pass the NAND_OWN_BUFFERS flag. >> >> Rework the nand_buffers allocation logic to allocate each buffer >> independently. This should make most NAND controllers/DMA engine >> happy, and allow us to get rid of these custom buf allocation in >> NAND controller drivers. >> >> Signed-off-by: Masahiro Yamada >> --- >> >> Changes in v3: >> - Reword git-log >> >> Changes in v2: >> - Newly added >> >> drivers/mtd/nand/nand_base.c | 34 +++++++++++++++++++++++++++------- >> 1 file changed, 27 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c >> index f828ad7..e9d3195 100644 >> --- a/drivers/mtd/nand/nand_base.c >> +++ b/drivers/mtd/nand/nand_base.c >> @@ -4613,13 +4613,25 @@ int nand_scan_tail(struct mtd_info *mtd) >> } >> >> if (!(chip->options & NAND_OWN_BUFFERS)) { >> - nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize >> - + mtd->oobsize * 3, GFP_KERNEL); >> + nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); >> if (!nbuf) >> return -ENOMEM; >> - nbuf->ecccalc = (uint8_t *)(nbuf + 1); >> - nbuf->ecccode = nbuf->ecccalc + mtd->oobsize; >> - nbuf->databuf = nbuf->ecccode + mtd->oobsize; >> + nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); >> + if (!nbuf->ecccalc) { >> + ret = -EINVAL; >> + goto err_free; > > You have a memory leak here, because chip->buffers = nbuf is only done > after all allocations have succeeded. Indeed. >> + } >> + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); >> + if (!nbuf->ecccode) { >> + ret = -EINVAL; > > ret = -ENOMEM; > > I have the following fixup patch, let me know if you're okay with it > and I'll squash it in the original commit. Thank you for your fixup patch. The code-diff looks all good. Please squash this. Sorry for my many mistakes. -- Best Regards Masahiro Yamada