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.

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to