summaryrefslogtreecommitdiff
path: root/mm/util.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2010-04-16 15:20:06 +0200
committerTakashi Iwai <tiwai@suse.de>2010-04-16 15:20:06 +0200
commitcf0dbba515415bb19b11f9323d5f7bebd7f24fd6 (patch)
tree375bbc1ade1a92acd6493d224dd701fd7f209014 /mm/util.c
parent1cff399ecd9125d8e6a634a1957be1aeb3195a12 (diff)
parent0340c7dccd80d8706c636e030a6ebbddbddca690 (diff)
Merge remote branch 'alsa/devel' into topic/misc
Diffstat (limited to 'mm/util.c')
-rw-r--r--mm/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/mm/util.c b/mm/util.c
index 834db7be240f..f5712e8964be 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -186,6 +186,27 @@ void kzfree(const void *p)
}
EXPORT_SYMBOL(kzfree);
+int kern_ptr_validate(const void *ptr, unsigned long size)
+{
+ unsigned long addr = (unsigned long)ptr;
+ unsigned long min_addr = PAGE_OFFSET;
+ unsigned long align_mask = sizeof(void *) - 1;
+
+ if (unlikely(addr < min_addr))
+ goto out;
+ if (unlikely(addr > (unsigned long)high_memory - size))
+ goto out;
+ if (unlikely(addr & align_mask))
+ goto out;
+ if (unlikely(!kern_addr_valid(addr)))
+ goto out;
+ if (unlikely(!kern_addr_valid(addr + size - 1)))
+ goto out;
+ return 1;
+out:
+ return 0;
+}
+
/*
* strndup_user - duplicate an existing string from user space
* @s: The string to duplicate