diff options
| author | Christoph Lameter <clameter@sgi.com> | 2008-02-05 01:28:34 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:14 -0500 |
| commit | 9e2779fa281cfda13ac060753d674bbcaa23367e (patch) | |
| tree | e2af17d69b71e0f8b3f00fe949cb8abfba4298ed | |
| parent | 0b7a96114bd5991d355a1f1c1d3d9c0c9d9c1cfc (diff) | |
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>
| -rw-r--r-- | drivers/net/cxgb3/cxgb3_offload.c | 4 | ||||
| -rw-r--r-- | fs/ntfs/malloc.h | 3 | ||||
| -rw-r--r-- | fs/proc/kcore.c | 2 | ||||
| -rw-r--r-- | fs/xfs/linux-2.6/kmem.c | 3 | ||||
| -rw-r--r-- | fs/xfs/linux-2.6/xfs_buf.c | 3 | ||||
| -rw-r--r-- | include/linux/mm.h | 8 | ||||
| -rw-r--r-- | mm/sparse.c | 10 |
7 files changed, 14 insertions, 19 deletions
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c index d48c396bdabb..901c824bfe6d 100644 --- a/drivers/net/cxgb3/cxgb3_offload.c +++ b/drivers/net/cxgb3/cxgb3_offload.c | |||
| @@ -1070,9 +1070,7 @@ void *cxgb_alloc_mem(unsigned long size) | |||
| 1070 | */ | 1070 | */ |
| 1071 | void cxgb_free_mem(void *addr) | 1071 | void cxgb_free_mem(void *addr) |
| 1072 | { | 1072 | { |
| 1073 | unsigned long p = (unsigned long)addr; | 1073 | if (is_vmalloc_addr(addr)) |
| 1074 | |||
| 1075 | if (p >= VMALLOC_START && p < VMALLOC_END) | ||
| 1076 | vfree(addr); | 1074 | vfree(addr); |
| 1077 | else | 1075 | else |
| 1078 | kfree(addr); | 1076 | kfree(addr); |
diff --git a/fs/ntfs/malloc.h b/fs/ntfs/malloc.h index e38e402e4103..cd0be3f5c3cd 100644 --- a/fs/ntfs/malloc.h +++ b/fs/ntfs/malloc.h | |||
| @@ -85,8 +85,7 @@ static inline void *ntfs_malloc_nofs_nofail(unsigned long size) | |||
| 85 | 85 | ||
| 86 | static inline void ntfs_free(void *addr) | 86 | static inline void ntfs_free(void *addr) |
| 87 | { | 87 | { |
| 88 | if (likely(((unsigned long)addr < VMALLOC_START) || | 88 | if (!is_vmalloc_addr(addr)) { |
| 89 | ((unsigned long)addr >= VMALLOC_END ))) { | ||
| 90 | kfree(addr); | 89 | kfree(addr); |
| 91 | /* free_page((unsigned long)addr); */ | 90 | /* free_page((unsigned long)addr); */ |
| 92 | return; | 91 | return; |
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 1be73082edd3..7dd26e18cbfd 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c | |||
| @@ -325,7 +325,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) | |||
| 325 | if (m == NULL) { | 325 | if (m == NULL) { |
| 326 | if (clear_user(buffer, tsz)) | 326 | if (clear_user(buffer, tsz)) |
| 327 | return -EFAULT; | 327 | return -EFAULT; |
| 328 | } else if ((start >= VMALLOC_START) && (start < VMALLOC_END)) { | 328 | } else if (is_vmalloc_addr((void *)start)) { |
| 329 | char * elf_buf; | 329 | char * elf_buf; |
| 330 | struct vm_struct *m; | 330 | struct vm_struct *m; |
| 331 | unsigned long curstart = start; | 331 | unsigned long curstart = start; |
diff --git a/fs/xfs/linux-2.6/kmem.c b/fs/xfs/linux-2.6/kmem.c index ed2b16dff914..e040f1ce1b6a 100644 --- a/fs/xfs/linux-2.6/kmem.c +++ b/fs/xfs/linux-2.6/kmem.c | |||
| @@ -92,8 +92,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize, | |||
| 92 | void | 92 | void |
| 93 | kmem_free(void *ptr, size_t size) | 93 | kmem_free(void *ptr, size_t size) |
| 94 | { | 94 | { |
| 95 | if (((unsigned long)ptr < VMALLOC_START) || | 95 | if (!is_vmalloc_addr(ptr)) { |
| 96 | ((unsigned long)ptr >= VMALLOC_END)) { | ||
| 97 | kfree(ptr); | 96 | kfree(ptr); |
| 98 | } else { | 97 | } else { |
| 99 | vfree(ptr); | 98 | vfree(ptr); |
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index a49dd8d4b069..0382c19d6523 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
| @@ -709,8 +709,7 @@ static inline struct page * | |||
| 709 | mem_to_page( | 709 | mem_to_page( |
| 710 | void *addr) | 710 | void *addr) |
| 711 | { | 711 | { |
| 712 | if (((unsigned long)addr < VMALLOC_START) || | 712 | if ((!is_vmalloc_addr(addr))) { |
| 713 | ((unsigned long)addr >= VMALLOC_END)) { | ||
| 714 | return virt_to_page(addr); | 713 | return virt_to_page(addr); |
| 715 | } else { | 714 | } else { |
| 716 | return vmalloc_to_page(addr); | 715 | return vmalloc_to_page(addr); |
diff --git a/include/linux/mm.h b/include/linux/mm.h index a862a96952e0..f28a0338574f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
| @@ -235,6 +235,14 @@ static inline int get_page_unless_zero(struct page *page) | |||
| 235 | struct page *vmalloc_to_page(const void *addr); | 235 | struct page *vmalloc_to_page(const void *addr); |
| 236 | unsigned long vmalloc_to_pfn(const void *addr); | 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 | static inline struct page *compound_head(struct page *page) | 246 | static inline struct page *compound_head(struct page *page) |
| 239 | { | 247 | { |
| 240 | if (unlikely(PageTail(page))) | 248 | if (unlikely(PageTail(page))) |
diff --git a/mm/sparse.c b/mm/sparse.c index a2183cb5d524..7859c8083334 100644 --- a/mm/sparse.c +++ b/mm/sparse.c | |||
| @@ -353,17 +353,9 @@ static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, | |||
| 353 | return __kmalloc_section_memmap(nr_pages); | 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 | static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) | 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 | vfree(memmap); | 359 | vfree(memmap); |
| 368 | else | 360 | else |
| 369 | free_pages((unsigned long)memmap, | 361 | free_pages((unsigned long)memmap, |
