unsigned long __phys_addr(unsigned long x) { unsigned long phys_addr = x - PAGE_OFFSET; /* VMALLOC_* aren't constants */ VIRTUAL_BUG_ON(x < PAGE_OFFSET); VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x)); /* max_low_pfn is set early, but not _that_ early */ if (max_low_pfn) { VIRTUAL_BUG_ON((phys_addr >> PAGE_SHIFT) > max_low_pfn); BUG_ON(slow_virt_to_phys((void *)x) != phys_addr); } return phys_addr; }
/* * Wrapper for slow_virt_to_phys() that handles NULL addresses. */ static inline phys_addr_t virt_to_phys_or_null_size(void *va, unsigned long size) { bool bad_size; if (!va) return 0; if (virt_addr_valid(va)) return virt_to_phys(va); /* * A fully aligned variable on the stack is guaranteed not to * cross a page bounary. Try to catch strings on the stack by * checking that 'size' is a power of two. */ bad_size = size > PAGE_SIZE || !is_power_of_2(size); WARN_ON(!IS_ALIGNED((unsigned long)va, size) || bad_size); return slow_virt_to_phys(va); }