The purpose of this section of code is to map that memory into userspace, and the code before this patch would incorrectly calculate the pfn required to do so. This patch simply changes it to use the correct function to do so rather than doing it from scratch. On Mon, Aug 5, 2019 at 4:37 AM David Laight <David.Laight@xxxxxxxxxx> wrote: > > From: gavinli@xxxxxxxxxxxxxx > > Sent: 01 August 2019 23:02 > > > > On architectures that are not (or are optionally) DMA coherent, > > dma_alloc_coherent() returns an address into the vmalloc space, > > and calling virt_to_phys() on this address returns an unusable > > physical address. > > So? what is the code trying to use the return value of virt_to_phys() for? > > The 'cpu physical address' isn't (usually) a very interesting number. > The value you normally want is the address the hardware should use > in order to access the memory - this isn't (in general) the same value. > (It might be different for different devices.) > > ISTR that dma_alloc_coherent() returns this value to the caller. > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) >