public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Leonard Crestez <leonard.crestez@nxp.com>,
	linux-mtd@lists.infradead.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	David Woodhouse <dwmw2@infradead.org>,
	Marek Vasut <marek.vasut@gmail.com>,
	Dinh Nguyen <dinguyen@kernel.org>,
	Artem Bityutskiy <artem.bityutskiy@linux.intel.com>,
	Graham Moore <grmoore@opensource.altera.com>,
	Enrico Jorns <ejo@pengutronix.de>,
	Chuanxiao Dong <chuanxiao.dong@intel.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Jassi Brar <jaswinder.singh@linaro.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Octavian Purdila <octavian.purdila@nxp.com>
Subject: Re: [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset
Date: Sun, 9 Apr 2017 09:33:23 +0200	[thread overview]
Message-ID: <20170409093323.4b122af1@bbrezillon> (raw)
In-Reply-To: <CAK7LNAQiO0Jx-qp=-pGWeknAbcTsf9VBPDdR65BP-5f3c4hXEA@mail.gmail.com>

On Fri, 7 Apr 2017 15:49:23 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> Hi Leonard,
> 
> 2017-04-06 23:08 GMT+09:00 Leonard Crestez <leonard.crestez@nxp.com>:
> > On Thu, Mar 30, 2017 at 11:15 AM, Masahiro Yamada <yamada.masahiro@socionext.com> 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 <yamada.masahiro@socionext.com>  
> >  
> >> @@ -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.   :-(

Totally agree, and that's partly because of the complex/non-trivial
NAND APIs :-/.

> nand_cleanup() may be called before nand_scan_tail()
> finishes successfully...

Actually, I think the real bug is in the GPMI driver which is not using
nand_release() appropriately. nand_release() is supposed to be called
on a registered NAND device, so it's wrong to call it before
mtd_register() has been called and returned 0.

Note that nand_cleanup() can only be called after nand_scan_tail() has
returned 0 (which unfortunately is not obvious :-/).

I still plan to take Masahiro's fixup patch because the more
precautions we take the better it is, but I still think the real bug is
in the GPMI driver.

One last comment: a bug still exists in the GPMI driver when
nand_scan_ident() fails after NAND buffers allocation because it never
sets chip->buffers back to NULL (see [1]).

[1]http://lxr.free-electrons.com/source/drivers/mtd/nand/nand_base.c#L4834

  reply	other threads:[~2017-04-09  7:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-30  8:15 [PATCH v3 31/37] mtd: nand: denali: fix raw and oob accessors for syndrome page layout Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 32/37] mtd: nand: denali: support hardware-assisted erased page detection Masahiro Yamada
2017-03-30 16:30   ` Boris Brezillon
2017-06-06  2:04     ` Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset Masahiro Yamada
2017-04-06 14:08   ` Leonard Crestez
2017-04-07  6:49     ` Masahiro Yamada
2017-04-09  7:33       ` Boris Brezillon [this message]
2017-04-09 14:17   ` Boris Brezillon
2017-04-10  0:20     ` Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 34/37] mtd: nand: allow drivers to request minimum alignment for passed buffer Masahiro Yamada
2017-03-31  4:01   ` Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 35/37] mtd: nand: denali: skip driver internal bounce buffer when possible Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 36/37] mtd: nand: denali: use non-managed kmalloc() for DMA buffer Masahiro Yamada
2017-03-30  8:15 ` [PATCH v3 37/37] mtd: nand: denali: enable bad block table scan Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170409093323.4b122af1@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=chuanxiao.dong@intel.com \
    --cc=dinguyen@kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=ejo@pengutronix.de \
    --cc=grmoore@opensource.altera.com \
    --cc=jaswinder.singh@linaro.org \
    --cc=leonard.crestez@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=octavian.purdila@nxp.com \
    --cc=sfr@canb.auug.org.au \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox