From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753955AbdDGGtm (ORCPT ); Fri, 7 Apr 2017 02:49:42 -0400 Received: from conssluserg-05.nifty.com ([210.131.2.90]:38120 "EHLO conssluserg-05.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752775AbdDGGtc (ORCPT ); Fri, 7 Apr 2017 02:49:32 -0400 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com v376nOqB018290 X-Nifty-SrcIP: [209.85.213.171] MIME-Version: 1.0 In-Reply-To: <1491487722.4829.11.camel@nxp.com> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> <1491487722.4829.11.camel@nxp.com> From: Masahiro Yamada Date: Fri, 7 Apr 2017 15:49:23 +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: Leonard Crestez Cc: linux-mtd@lists.infradead.org, Linux Kernel Mailing List , Boris Brezillon , David Woodhouse , Marek Vasut , Dinh Nguyen , Artem Bityutskiy , Graham Moore , Enrico Jorns , Chuanxiao Dong , Masami Hiramatsu , Jassi Brar , Stephen Rothwell , Octavian Purdila Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Leonard, 2017-04-06 23:08 GMT+09:00 Leonard Crestez : > On Thu, Mar 30, 2017 at 11:15 AM, 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 > >> @@ -4914,8 +4930,12 @@ void nand_cleanup(struct nand_chip *chip) >> > /* Free bad block table memory */ >> kfree(chip->bbt); >> - if (!(chip->options & NAND_OWN_BUFFERS)) >> + if (!(chip->options & NAND_OWN_BUFFERS)) { >> + kfree(chip->buffers->databuf); >> + kfree(chip->buffers->ecccode); >> + kfree(chip->buffers->ecccalc); >> kfree(chip->buffers); >> + } > > It seems that chip->buffers might not be allocated at this point, for > example if nand_cleanup is called during a failed probe. You should > check if (chip->buffers != NULL) before freeing stuff inside it. You are right. The failure path in NAND drivers is messy. :-( nand_cleanup() may be called before nand_scan_tail() finishes successfully... I will send a fixup patch. Thanks! -- Best Regards Masahiro Yamada