lkml.org 
[lkml]   [2009]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] dma: fix up broken comparison in dma_alloc_from_coherent
On Tue, Jan 27, 2009 at 01:48:31PM -0800, Andrew Morton wrote:
> On Wed, 21 Jan 2009 17:11:19 +0900
> Paul Mundt <lethal@linux-sh.org> wrote:
>
> > @@ -118,31 +118,32 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t size,
> > mem = dev->dma_mem;
> > if (!mem)
> > return 0;
> > - if (unlikely(size > mem->size))
> > - return 0;
> > +
> > + *ret = NULL;
> > +
> > + if (unlikely(size > (mem->size << PAGE_SHIFT)))
> > + goto err;
>
> Looks a bit broken on 64-bit.
>
> `size' is ssize_t (long).
>
> `mem->size' is `int'.
>
> The left shift can overflow and cause badnesses.
>
> > + *dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
> > + *ret = mem->virt_base + (pageno << PAGE_SHIFT);
>
> Ditto.
>
>
> Maybe it's a can't-happen (why?), but...

It is probably worth adding casts to avoid the potential for overflow,
but it's not likely that this would ever be a problem in practice.
Someone would need a pretty big per-device memory area for this to ever
overflow anyways, and if the device has that much memory, people are
probably going to want to do something else with it besides designating
all of it for DMA buffer usage ;-)


\
 
 \ /
  Last update: 2009-01-28 00:01    [W:0.129 / U:0.952 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site