vserver 1.9.3
[linux-2.6.git] / sound / core / memory.c
index cf4f75c..21f76c2 100644 (file)
@@ -71,8 +71,7 @@ void snd_memory_done(void)
                snd_printk(KERN_ERR "Not freed snd_alloc_kmalloc = %li\n", snd_alloc_kmalloc);
        if (snd_alloc_vmalloc > 0)
                snd_printk(KERN_ERR "Not freed snd_alloc_vmalloc = %li\n", snd_alloc_vmalloc);
-       for (head = snd_alloc_kmalloc_list.prev;
-            head != &snd_alloc_kmalloc_list; head = head->prev) {
+       list_for_each_prev(head, &snd_alloc_kmalloc_list) {
                t = list_entry(head, struct snd_alloc_track, list);
                if (t->magic != KMALLOC_MAGIC) {
                        snd_printk(KERN_ERR "Corrupted kmalloc\n");
@@ -80,8 +79,7 @@ void snd_memory_done(void)
                }
                snd_printk(KERN_ERR "kmalloc(%ld) from %p not freed\n", (long) t->size, t->caller);
        }
-       for (head = snd_alloc_vmalloc_list.prev;
-            head != &snd_alloc_vmalloc_list; head = head->prev) {
+       list_for_each_prev(head, &snd_alloc_vmalloc_list) {
                t = list_entry(head, struct snd_alloc_track, list);
                if (t->magic != VMALLOC_MAGIC) {
                        snd_printk(KERN_ERR "Corrupted vmalloc\n");
@@ -118,6 +116,17 @@ void *snd_hidden_kmalloc(size_t size, int flags)
        return _snd_kmalloc(size, flags);
 }
 
+void *snd_hidden_kcalloc(size_t n, size_t size, int flags)
+{
+       void *ret = NULL;
+       if (n != 0 && size > INT_MAX / n)
+               return ret;
+       ret = _snd_kmalloc(n * size, flags);
+       if (ret)
+               memset(ret, 0, n * size);
+       return ret;
+}
+
 void snd_hidden_kfree(const void *obj)
 {
        unsigned long flags;
@@ -140,46 +149,6 @@ void snd_hidden_kfree(const void *obj)
        snd_wrapper_kfree(obj);
 }
 
-void *_snd_magic_kcalloc(unsigned long magic, size_t size, int flags)
-{
-       unsigned long *ptr;
-       ptr = _snd_kmalloc(size + sizeof(unsigned long), flags);
-       if (ptr) {
-               *ptr++ = magic;
-               memset(ptr, 0, size);
-       }
-       return ptr;
-}
-
-void *_snd_magic_kmalloc(unsigned long magic, size_t size, int flags)
-{
-       unsigned long *ptr;
-       ptr = _snd_kmalloc(size + sizeof(unsigned long), flags);
-       if (ptr)
-               *ptr++ = magic;
-       return ptr;
-}
-
-void snd_magic_kfree(void *_ptr)
-{
-       unsigned long *ptr = _ptr;
-       if (ptr == NULL) {
-               snd_printk(KERN_WARNING "null snd_magic_kfree (called from %p)\n", __builtin_return_address(0));
-               return;
-       }
-       *--ptr = 0;
-       {
-               struct snd_alloc_track *t;
-               t = snd_alloc_track_entry(ptr);
-               if (t->magic != KMALLOC_MAGIC) {
-                       snd_printk(KERN_ERR "bad snd_magic_kfree (called from %p)\n", __builtin_return_address(0));
-                       return;
-               }
-       }
-       snd_hidden_kfree(ptr);
-       return;
-}
-
 void *snd_hidden_vmalloc(unsigned long size)
 {
        void *ptr;
@@ -255,25 +224,6 @@ int __exit snd_memory_info_done(void)
 
 #endif /* CONFIG_SND_DEBUG_MEMORY */
 
-/**
- * snd_kcalloc - memory allocation and zero-clear
- * @size: the size to allocate in bytes
- * @flags: allocation conditions, GFP_XXX
- *
- * Allocates a memory chunk via kmalloc() and initializes it to zero.
- *
- * Returns the pointer, or NULL if no enoguh memory.
- */
-void *snd_kcalloc(size_t size, int flags)
-{
-       void *ptr;
-       
-       ptr = _snd_kmalloc(size, flags);
-       if (ptr)
-               memset(ptr, 0, size);
-       return ptr;
-}
-
 /**
  * snd_kmalloc_strdup - copy the string
  * @string: the original string