lkml.org 
[lkml]   [2019]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 1/2] dma-direct: check for overflows on 32 bit DMA addresses
From
Date
On Wed, 2019-10-30 at 14:41 -0700, Christoph Hellwig wrote:
> On Fri, Oct 18, 2019 at 01:00:43PM +0200, Nicolas Saenz Julienne wrote:
> > +#ifndef CONFIG_ARCH_DMA_ADDR_T_64BIT
> > + /* Check if DMA address overflowed */
> > + if (min(addr, addr + size - 1) <
> > + __phys_to_dma(dev, (phys_addr_t)(min_low_pfn << PAGE_SHIFT)))
> > + return false;
> > +#endif
>
> Would be nice to use IS_ENABLED and PFN_PHYS here, and I also think we
> need to use phys_to_dma to take care of the encryption bit. If you then
> also introduce an end variable we can make the whole thing actually look
> nice:
>
> static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t
> size)
> {
> dma_addr_t end = addr + size - 1;
>
> if (!dev->dma_mask)
> return false;
>
> if (!IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
> min(addr, end) < phys_to_dma(dev, PFN_PHYS(min_low_pfn)))
> return false;
>
> return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
> }
>
> Otherwise this looks sensible to me.

Thanks, noted.

[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2019-10-31 11:46    [W:0.084 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site