linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Device-mapper submission 2/7
@ 2002-10-15 17:44 Joe Thornber
  0 siblings, 0 replies; only message in thread
From: Joe Thornber @ 2002-10-15 17:44 UTC (permalink / raw)
  To: Linux Mailing List, Linus Torvalds, Dave Jones

[vmalloc]
Introduce vcalloc, I only really want it to automate the size overflow
check when allocating arrays.

--- a/include/linux/vmalloc.h	Tue Oct 15 18:24:33 2002
+++ b/include/linux/vmalloc.h	Tue Oct 15 18:24:33 2002
@@ -24,6 +24,7 @@
 extern void *vmalloc(unsigned long size);
 extern void *vmalloc_32(unsigned long size);
 extern void *__vmalloc(unsigned long size, int gfp_mask, pgprot_t prot);
+extern void *vcalloc(unsigned long nmemb, unsigned long elem_size);
 extern void vfree(void *addr);
 
 extern void *vmap(struct page **pages, unsigned int count);
--- a/kernel/ksyms.c	Tue Oct 15 18:24:33 2002
+++ b/kernel/ksyms.c	Tue Oct 15 18:24:33 2002
@@ -108,6 +108,7 @@
 EXPORT_SYMBOL(kfree);
 EXPORT_SYMBOL(vfree);
 EXPORT_SYMBOL(__vmalloc);
+EXPORT_SYMBOL(vcalloc);
 EXPORT_SYMBOL(vmalloc);
 EXPORT_SYMBOL(vmalloc_32);
 EXPORT_SYMBOL(vmap);
--- a/mm/vmalloc.c	Tue Oct 15 18:24:33 2002
+++ b/mm/vmalloc.c	Tue Oct 15 18:24:33 2002
@@ -520,3 +520,22 @@
 	read_unlock(&vmlist_lock);
 	return buf - buf_start;
 }
+
+void *vcalloc(unsigned long nmemb, unsigned long elem_size)
+{
+	unsigned long size;
+	void *addr;
+
+	/*
+	 * Check that we're not going to overflow.
+	 */
+	if (nmemb > (ULONG_MAX / elem_size))
+		return NULL;
+
+	size = nmemb * elem_size;
+	addr = vmalloc(size);
+	if (addr)
+		memset(addr, 0, size);
+
+	return addr;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-15 17:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 17:44 [PATCH] Device-mapper submission 2/7 Joe Thornber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).