Skip to content

Commit 06d5e03

Browse files
sonicztorvalds
authored andcommitted
include/asm-generic/page.h: calculate virt_to_page and page_to_virt via predefined macro
On NOMMU architectures, if physical memory doesn't start from 0, ARCH_PFN_OFFSET is defined to generate page index in mem_map array. Because virtual address is equal to physical address, PAGE_OFFSET is always 0. virt_to_page and page_to_virt should not index page by PAGE_OFFSET directly. Signed-off-by: Sonic Zhang <sonic.zhang@analog.com> Cc: Greg Ungerer <gerg@snapgear.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 37a1c49 commit 06d5e03

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎include/asm-generic/page.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ extern unsigned long memory_end;
7979
#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
8080
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
8181

82-
#define virt_to_page(addr) (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
83-
#define page_to_virt(page) ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
82+
#define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr))
83+
#define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
8484

8585
#ifndef page_to_phys
8686
#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)

0 commit comments

Comments
 (0)