Skip to content

Commit 9e2779f

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
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>
1 parent 0b7a961 commit 9e2779f

7 files changed

Lines changed: 14 additions & 19 deletions

File tree

‎drivers/net/cxgb3/cxgb3_offload.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,7 @@ void *cxgb_alloc_mem(unsigned long size)
10701070
*/
10711071
void cxgb_free_mem(void *addr)
10721072
{
1073-
unsigned long p = (unsigned long)addr;
1074-
1075-
if (p >= VMALLOC_START && p < VMALLOC_END)
1073+
if (is_vmalloc_addr(addr))
10761074
vfree(addr);
10771075
else
10781076
kfree(addr);

‎fs/ntfs/malloc.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static inline void *ntfs_malloc_nofs_nofail(unsigned long size)
8585

8686
static inline void ntfs_free(void *addr)
8787
{
88-
if (likely(((unsigned long)addr < VMALLOC_START) ||
89-
((unsigned long)addr >= VMALLOC_END ))) {
88+
if (!is_vmalloc_addr(addr)) {
9089
kfree(addr);
9190
/* free_page((unsigned long)addr); */
9291
return;

‎fs/proc/kcore.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
325325
if (m == NULL) {
326326
if (clear_user(buffer, tsz))
327327
return -EFAULT;
328-
} else if ((start >= VMALLOC_START) && (start < VMALLOC_END)) {
328+
} else if (is_vmalloc_addr((void *)start)) {
329329
char * elf_buf;
330330
struct vm_struct *m;
331331
unsigned long curstart = start;

‎fs/xfs/linux-2.6/kmem.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize,
9292
void
9393
kmem_free(void *ptr, size_t size)
9494
{
95-
if (((unsigned long)ptr < VMALLOC_START) ||
96-
((unsigned long)ptr >= VMALLOC_END)) {
95+
if (!is_vmalloc_addr(ptr)) {
9796
kfree(ptr);
9897
} else {
9998
vfree(ptr);

‎fs/xfs/linux-2.6/xfs_buf.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,7 @@ static inline struct page *
709709
mem_to_page(
710710
void *addr)
711711
{
712-
if (((unsigned long)addr < VMALLOC_START) ||
713-
((unsigned long)addr >= VMALLOC_END)) {
712+
if ((!is_vmalloc_addr(addr))) {
714713
return virt_to_page(addr);
715714
} else {
716715
return vmalloc_to_page(addr);

‎include/linux/mm.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ static inline int get_page_unless_zero(struct page *page)
235235
struct page *vmalloc_to_page(const void *addr);
236236
unsigned long vmalloc_to_pfn(const void *addr);
237237

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+
238246
static inline struct page *compound_head(struct page *page)
239247
{
240248
if (unlikely(PageTail(page)))

‎mm/sparse.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,9 @@ static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid,
353353
return __kmalloc_section_memmap(nr_pages);
354354
}
355355

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-
364356
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
365357
{
366-
if (vaddr_in_vmalloc_area(memmap))
358+
if (is_vmalloc_addr(memmap))
367359
vfree(memmap);
368360
else
369361
free_pages((unsigned long)memmap,

0 commit comments

Comments
 (0)