From: Marin Mitov <mitov@issp.bas.bg>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [BUG][PATCH]dma-coherent.c: error path bug
Date: Mon, 7 Jun 2010 07:43:19 +0300 [thread overview]
Message-ID: <201006070743.20226.mitov@issp.bas.bg> (raw)
In-Reply-To: <20100607132631W.fujita.tomonori@lab.ntt.co.jp>
On Monday, June 07, 2010 07:27:49 am FUJITA Tomonori wrote:
> On Mon, 7 Jun 2010 07:08:56 +0300
> Marin Mitov <mitov@issp.bas.bg> wrote:
>
> > On Monday, June 07, 2010 05:30:48 am FUJITA Tomonori wrote:
> > > On Sun, 6 Jun 2010 13:53:04 +0300
> > > Marin Mitov <mitov@issp.bas.bg> wrote:
> > >
> > > > Hi all,
> > > >
> > > > The error path in dma_declare_coherent_memory() leaves
> > > > the pointer dev->dma_mem non completely initialized.
> > > >
> > > > If allocation of dev->dma_mem succeeds,
> > > > but allocation of dev->dma_mem->bitmap fails
> > > > dev->dma_mem is freed, but left non NULL
> > > > and non completely initialized.
> > > >
> > > > Either zero it after being freed (one liner patch), or assign to
> > > > dev->dma_mem only completely initialized structure (patch included).
> > > >
> > > > Comments welcome.
> > > >
> > > > Marin Mitov
> > > >
> > > > Signed-off-by: Marin Mitov <mitov@issp.bas.bg>
> > >
> > > Hmm, if dma_declare_coherent_memory() fails, the driver doesn't use
> > > dev->dma_mem. So even if dev->dma_mem points to a freed memory, I'm
> > > not sure that it causes a real problem. We could call this patch a
> > > cleanup though.
> > >
> > My understanding of dma_alloc_coherent() is that we first try to allocate from
> > per-device coherent memory and we do it using dma_alloc_from_coherent()
> > (in drivers/base/dma-coherent.c) if dev->dma_mem is not NULL (and we have
> > left it not NULL, here is the problem). If allocation of dev->dma_mem->bitmap
> > fails dev->dma_mem must be NULL.
>
> But are there any driver that can continue when dma_declare_coherent_memory() fails?
>
I do not know if such a real driver exists.
My understanding of drivers' use of dma_declare_coherent_memory() is to
declare some (may be on board) memory as coherent, so when they call
dma_alloc_coherent() the request is satisfied first from this area and when
it is exhausted fall back to other pools of coherent memory. As far as a fall back
exists the driver may continue even if dma_declare_coherent_memory() fails.
Marin Mitov
next prev parent reply other threads:[~2010-06-07 4:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-06 10:53 [BUG][PATCH]dma-coherent.c: error path bug Marin Mitov
2010-06-07 2:30 ` FUJITA Tomonori
2010-06-07 4:08 ` Marin Mitov
2010-06-07 4:27 ` FUJITA Tomonori
2010-06-07 4:43 ` Marin Mitov [this message]
2010-06-07 4:59 ` FUJITA Tomonori
2010-06-07 6:27 ` Paul Mundt
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=201006070743.20226.mitov@issp.bas.bg \
--to=mitov@issp.bas.bg \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-kernel@vger.kernel.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