All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Prabhakar Lad <prabhakar.csengg@gmail.com>
Cc: Sachin Kamat <sachin.kamat@linaro.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Nicolin Chen <b42378@freescale.com>,
	Joe Perches <joe@perches.com>,
	LKML <linux-kernel@vger.kernel.org>,
	DLOS <davinci-linux-open-source@linux.davincidsp.com>
Subject: Re: [PATCH] lib/genalloc.c: add check gen_pool_dma_alloc() if dma pointer is not NULL
Date: Thu, 23 Jan 2014 13:23:25 -0800	[thread overview]
Message-ID: <20140123132325.cada6dca726c2cdd1173ad91@linux-foundation.org> (raw)
In-Reply-To: <CA+V-a8vN2VBCjuAMGootU=t+PbjK7wVDQeYZgV03Wa5070WwFw@mail.gmail.com>

On Thu, 23 Jan 2014 15:51:31 +0530 Prabhakar Lad <prabhakar.csengg@gmail.com> wrote:

> Hi Sachin,
> 
> On Thu, Jan 23, 2014 at 3:38 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> > Hi Prabhakar,
> >
> > On 23 January 2014 15:26, Prabhakar Lad <prabhakar.csengg@gmail.com> wrote:
> >> From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
> >>
> >> In the gen_pool_dma_alloc() the dma pointer can be NULL
> >> and while assigning gen_pool_virt_to_phys(pool, vaddr) to
> >> dma caused the following crash on da850 evm,
> >>
> > [snip]
> >>
> >> Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
> >> ---
> >>  lib/genalloc.c |    3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/genalloc.c b/lib/genalloc.c
> >> index dda3116..f48163f 100644
> >> --- a/lib/genalloc.c
> >> +++ b/lib/genalloc.c
> >> @@ -334,7 +334,8 @@ void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
> >>         if (!vaddr)
> >>                 return NULL;
> >>
> >> -       *dma = gen_pool_virt_to_phys(pool, vaddr);
> >> +       if (dma)
> >> +               *dma = gen_pool_virt_to_phys(pool, vaddr);
> >
> > Wouldn't it be better to return (with error/message) if dma is NULL
> > rather than silently ignore it?
> >
> I am not sure if returning here with error is OK,
> may be just adding a warning message could be OK ?

The patch look OK as-is to me.  `dma' is a second return value from
gen_pool_dma_alloc() and this patch extends the gen_pool_dma_alloc()
interface by making that return value optional.  That's good for
callers who don't want the physical address, and they can call
gen_pool_virt_to_phys() at a later time to get the physical address
anyway.

>From my reading, 3.13.x kernels will need this patch.

I suppose we should document the API change:

--- a/lib/genalloc.c~lib-genallocc-add-check-gen_pool_dma_alloc-if-dma-pointer-is-not-null-fix
+++ a/lib/genalloc.c
@@ -316,7 +316,7 @@ EXPORT_SYMBOL(gen_pool_alloc);
  * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
  * @pool: pool to allocate from
  * @size: number of bytes to allocate from the pool
- * @dma: dma-view physical address
+ * @dma: dma-view physical address return value.  Use NULL if unneeded.
  *
  * Allocate the requested number of bytes from the specified pool.
  * Uses the pool allocation function (with first-fit algorithm by default).
_


  reply	other threads:[~2014-01-23 21:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23  9:56 [PATCH] lib/genalloc.c: add check gen_pool_dma_alloc() if dma pointer is not NULL Prabhakar Lad
2014-01-23 10:08 ` Sachin Kamat
2014-01-23 10:21   ` Prabhakar Lad
2014-01-23 21:23     ` Andrew Morton [this message]
2014-01-24  3:10       ` Sachin Kamat

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=20140123132325.cada6dca726c2cdd1173ad91@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=b42378@freescale.com \
    --cc=davinci-linux-open-source@linux.davincidsp.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=prabhakar.csengg@gmail.com \
    --cc=sachin.kamat@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.