Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

is_vmalloc_addr(): Check if an address is within the vmalloc boundaries

Checking if an address is a vmalloc address is done in a couple of places.
Define a common version in mm.h and replace the other checks.

Again the include structures suck. The definition of VMALLOC_START and
VMALLOC_END is not available in vmalloc.h since highmem.c cannot be included
there.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Christoph Lameter and committed by
Linus Torvalds
9e2779fa 0b7a9611

+14 -19
+1 -3
drivers/net/cxgb3/cxgb3_offload.c
··· 1070 1070 */ 1071 1071 void cxgb_free_mem(void *addr) 1072 1072 { 1073 - unsigned long p = (unsigned long)addr; 1074 - 1075 - if (p >= VMALLOC_START && p < VMALLOC_END) 1073 + if (is_vmalloc_addr(addr)) 1076 1074 vfree(addr); 1077 1075 else 1078 1076 kfree(addr);
+1 -2
fs/ntfs/malloc.h
··· 85 85 86 86 static inline void ntfs_free(void *addr) 87 87 { 88 - if (likely(((unsigned long)addr < VMALLOC_START) || 89 - ((unsigned long)addr >= VMALLOC_END ))) { 88 + if (!is_vmalloc_addr(addr)) { 90 89 kfree(addr); 91 90 /* free_page((unsigned long)addr); */ 92 91 return;
+1 -1
fs/proc/kcore.c
··· 325 325 if (m == NULL) { 326 326 if (clear_user(buffer, tsz)) 327 327 return -EFAULT; 328 - } else if ((start >= VMALLOC_START) && (start < VMALLOC_END)) { 328 + } else if (is_vmalloc_addr((void *)start)) { 329 329 char * elf_buf; 330 330 struct vm_struct *m; 331 331 unsigned long curstart = start;
+1 -2
fs/xfs/linux-2.6/kmem.c
··· 92 92 void 93 93 kmem_free(void *ptr, size_t size) 94 94 { 95 - if (((unsigned long)ptr < VMALLOC_START) || 96 - ((unsigned long)ptr >= VMALLOC_END)) { 95 + if (!is_vmalloc_addr(ptr)) { 97 96 kfree(ptr); 98 97 } else { 99 98 vfree(ptr);
+1 -2
fs/xfs/linux-2.6/xfs_buf.c
··· 709 709 mem_to_page( 710 710 void *addr) 711 711 { 712 - if (((unsigned long)addr < VMALLOC_START) || 713 - ((unsigned long)addr >= VMALLOC_END)) { 712 + if ((!is_vmalloc_addr(addr))) { 714 713 return virt_to_page(addr); 715 714 } else { 716 715 return vmalloc_to_page(addr);
+8
include/linux/mm.h
··· 235 235 struct page *vmalloc_to_page(const void *addr); 236 236 unsigned long vmalloc_to_pfn(const void *addr); 237 237 238 + /* Determine if an address is within the vmalloc range */ 239 + static inline int is_vmalloc_addr(const void *x) 240 + { 241 + unsigned long addr = (unsigned long)x; 242 + 243 + return addr >= VMALLOC_START && addr < VMALLOC_END; 244 + } 245 + 238 246 static inline struct page *compound_head(struct page *page) 239 247 { 240 248 if (unlikely(PageTail(page)))
+1 -9
mm/sparse.c
··· 353 353 return __kmalloc_section_memmap(nr_pages); 354 354 } 355 355 356 - static int vaddr_in_vmalloc_area(void *addr) 357 - { 358 - if (addr >= (void *)VMALLOC_START && 359 - addr < (void *)VMALLOC_END) 360 - return 1; 361 - return 0; 362 - } 363 - 364 356 static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) 365 357 { 366 - if (vaddr_in_vmalloc_area(memmap)) 358 + if (is_vmalloc_addr(memmap)) 367 359 vfree(memmap); 368 360 else 369 361 free_pages((unsigned long)memmap,