Re: [PATCH] ALSA: Remove subsystem-specific malloc (1/8)

From: Pekka Enberg
Date: Wed Jun 09 2004 - 15:12:00 EST


On Wed, 2004-06-09 at 21:34, Chris Wright wrote:
> This looks more like the kzalloc() that pops up every now and then.
> Wouldn't it make more sense to give kcalloc() a true calloc() style
> interface?

I can go either way. Takashi, do you want me to update the ALSA patches
to use this version?

Pekka

diff -urN linux-2.6.6/include/linux/slab.h kcalloc-2.6.6/include/linux/slab.h
--- linux-2.6.6/include/linux/slab.h 2004-06-09 22:56:11.874249056 +0300
+++ kcalloc-2.6.6/include/linux/slab.h 2004-06-09 23:03:10.597593432 +0300
@@ -95,6 +95,7 @@
return __kmalloc(size, flags);
}

+extern void *kcalloc(size_t, size_t, int);
extern void kfree(const void *);
extern unsigned int ksize(const void *);

diff -urN linux-2.6.6/mm/slab.c kcalloc-2.6.6/mm/slab.c
--- linux-2.6.6/mm/slab.c 2004-06-09 22:59:13.081701336 +0300
+++ kcalloc-2.6.6/mm/slab.c 2004-06-09 23:07:51.262925816 +0300
@@ -2332,6 +2332,22 @@
EXPORT_SYMBOL(kmem_cache_free);

/**
+ * kcalloc - allocate memory for an array. The memory is set to zero.
+ * @n: number of elements.
+ * @size: element size.
+ * @flags: the type of memory to allocate.
+ */
+void *kcalloc(size_t n, size_t size, int flags)
+{
+ void *ret = kmalloc(n * size, flags);
+ if (ret)
+ memset(ret, 0, n * size);
+ return ret;
+}
+
+EXPORT_SYMBOL(kcalloc);
+
+/**
* kfree - free previously allocated memory
* @objp: pointer returned by kmalloc.
*


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/