linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: nand: pxa3xx: Use info->use_dma to release DMA resources
Date: Mon, 9 Dec 2013 18:20:39 -0300	[thread overview]
Message-ID: <20131209212038.GD31944@localhost> (raw)
In-Reply-To: <20131206105354.GA2511@localhost>


> Brian,
> 
> On Wed, Nov 27, 2013 at 08:34:05AM -0300, Ezequiel Garcia wrote:
> > On Tue, Nov 26, 2013 at 11:58:19PM -0800, Brian Norris wrote:
> > > On Tue, Nov 26, 2013 at 09:52:24AM -0300, Ezequiel Garcia wrote:
> > > > After the driver allocates all DMA resources, it sets "info->use_dma".
> > > > Therefore, we need to check that variable to decide which resources
> > > > needs to be freed, instead of the global use_dma variable.
> > > > 
> > > > Without this change, when the device probe fails, the driver will try
> > > > to release unallocated DMA resources, with nasty results.
> > > > 
> > > > Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > > > ---
> > > > This is minor fix, but a fix anyway, so it should be queued for stable.
> > > > 
> > > >  drivers/mtd/nand/pxa3xx_nand.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
> > > > index 97c3eb5..8f2104c 100644
> > > > --- a/drivers/mtd/nand/pxa3xx_nand.c
> > > > +++ b/drivers/mtd/nand/pxa3xx_nand.c
> > > > @@ -1288,7 +1288,7 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
> > > >  static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info)
> > > >  {
> > > >  	struct platform_device *pdev = info->pdev;
> > > > -	if (use_dma) {
> > > > +	if (info->use_dma) {
> > > 
> > > With this change, then the 'else' case will be executed and will kfree()
> > > the data buffer that we didn't allocate?
> > > 
> > >   kfree(info->data_buff);
> > > 
> > > Fortunately kfree()'ing a NULL is a no-op.
> > > 
> > 
> > No. The buffer is allocated at a very early stage in DMA and non-DMA modes.
> > It's later reallocated, but in any case when pxa3xx_nand_free_buff()
> > is called, the buffer can never be NULL.
> > 
> > The situation this commit fixes is that when the cleanup is called from
> > the probe(), the DMA resources haven't been allocated yet and so the
> > release must be kfree().
> > 
> > Remember we've recently changed this driver to work in non-DMA mode
> > until the page size is correctly detected. Until then, info->use_dma is
> > false.
> > 
> > > But this highlights some of the strangeness of the error handling in
> > > this driver. It has an atypical style, in which the probe routine calls
> > > the remove routine if it fails. Normally, the probe routine has teardown
> > > carefully planned in stages, whereas the remove routine just does it all
> > > in one go (since it can assume the device was fully initialized). (And
> > > of course, the devm_* functions can help with simplifying some of
> > > this...)
> > > 
> > 
> > Yes, I know. The driver is very very old, and some parts of it need some
> > love. However, the error handling is not so bad. When
> > pxa3xx_nand_remove() is called, all resources are guaranteed to be
> > allocated so it works like a full-fledged release.
> > 
> > I'm actually more annoyed by the fact there's two variables with the
> > same name: use_dma, and info->use_dma.
> > 
> > > But I suppose this patch is correct as-is, and this issue could be
> > > revisited later.
> > > 
> > > For my reference, have you actually seen this bug in practice? I'm not
> > > sure how well this fits in the -stable rules, if it hasn't been observed
> > > and tested appropriately.
> > > 
> > 
> > Yes, I've seen this bug in practice, or otherwise wouldn't notice such small
> > typo :-) The bug was triggered in PXA platforms, when the device cannot
> > be identified (nand_scan fails).
> > 
> > It's a very rare condition, but it's a real bug. Is that enough for -stable?
> 
> Just a gentle ping, in case this one felt through the cracks.
> 

I'm sorry to bother by pinging *again*, but I think this is a fix for v3.13.
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-12-09 21:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-26 12:52 [PATCH] mtd: nand: pxa3xx: Use info->use_dma to release DMA resources Ezequiel Garcia
2013-11-27  7:58 ` Brian Norris
2013-11-27 11:34   ` Ezequiel Garcia
2013-12-06 10:53     ` Ezequiel Garcia
2013-12-09 21:20       ` Ezequiel Garcia [this message]
2013-12-09 21:55     ` Brian Norris
2013-12-09 22:32       ` Ezequiel Garcia
2013-12-09 23:10         ` Brian Norris
2013-12-10 12:59           ` Ezequiel Garcia

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=20131209212038.GD31944@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).