aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-10-10 05:56:31 -0400
committerJaroslav Kysela <perex@suse.cz>2005-11-04 07:18:00 -0500
commitb1d5776d865951c213a1caaab5d8bf5de7615dbd (patch)
treef999dca30f6e2d03a9176b86c613ae8f4531a6d6 /sound/core
parent93f2e37840a9a7c3693ca6961fe6ad46b250f3b9 (diff)
[ALSA] Remove vmalloc wrapper, kfree_nocheck()
- Remove vmalloc wrapper - Add release_and_free_resource() to remove kfree_nocheck() from each driver and simplify the code Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/memory.c53
-rw-r--r--sound/core/misc.c9
-rw-r--r--sound/core/sound.c5
-rw-r--r--sound/core/wrappers.c10
4 files changed, 10 insertions, 67 deletions
diff --git a/sound/core/memory.c b/sound/core/memory.c
index 7d8e2eebba51..b99343616f81 100644
--- a/sound/core/memory.c
+++ b/sound/core/memory.c
@@ -47,19 +47,14 @@ struct snd_alloc_track {
47#define snd_alloc_track_entry(obj) (struct snd_alloc_track *)((char*)obj - (unsigned long)((struct snd_alloc_track *)0)->data) 47#define snd_alloc_track_entry(obj) (struct snd_alloc_track *)((char*)obj - (unsigned long)((struct snd_alloc_track *)0)->data)
48 48
49static long snd_alloc_kmalloc; 49static long snd_alloc_kmalloc;
50static long snd_alloc_vmalloc;
51static LIST_HEAD(snd_alloc_kmalloc_list); 50static LIST_HEAD(snd_alloc_kmalloc_list);
52static LIST_HEAD(snd_alloc_vmalloc_list);
53static DEFINE_SPINLOCK(snd_alloc_kmalloc_lock); 51static DEFINE_SPINLOCK(snd_alloc_kmalloc_lock);
54static DEFINE_SPINLOCK(snd_alloc_vmalloc_lock);
55#define KMALLOC_MAGIC 0x87654321 52#define KMALLOC_MAGIC 0x87654321
56#define VMALLOC_MAGIC 0x87654320
57static snd_info_entry_t *snd_memory_info_entry; 53static snd_info_entry_t *snd_memory_info_entry;
58 54
59void __init snd_memory_init(void) 55void __init snd_memory_init(void)
60{ 56{
61 snd_alloc_kmalloc = 0; 57 snd_alloc_kmalloc = 0;
62 snd_alloc_vmalloc = 0;
63} 58}
64 59
65void snd_memory_done(void) 60void snd_memory_done(void)
@@ -69,8 +64,6 @@ void snd_memory_done(void)
69 64
70 if (snd_alloc_kmalloc > 0) 65 if (snd_alloc_kmalloc > 0)
71 snd_printk(KERN_ERR "Not freed snd_alloc_kmalloc = %li\n", snd_alloc_kmalloc); 66 snd_printk(KERN_ERR "Not freed snd_alloc_kmalloc = %li\n", snd_alloc_kmalloc);
72 if (snd_alloc_vmalloc > 0)
73 snd_printk(KERN_ERR "Not freed snd_alloc_vmalloc = %li\n", snd_alloc_vmalloc);
74 list_for_each_prev(head, &snd_alloc_kmalloc_list) { 67 list_for_each_prev(head, &snd_alloc_kmalloc_list) {
75 t = list_entry(head, struct snd_alloc_track, list); 68 t = list_entry(head, struct snd_alloc_track, list);
76 if (t->magic != KMALLOC_MAGIC) { 69 if (t->magic != KMALLOC_MAGIC) {
@@ -79,14 +72,6 @@ void snd_memory_done(void)
79 } 72 }
80 snd_printk(KERN_ERR "kmalloc(%ld) from %p not freed\n", (long) t->size, t->caller); 73 snd_printk(KERN_ERR "kmalloc(%ld) from %p not freed\n", (long) t->size, t->caller);
81 } 74 }
82 list_for_each_prev(head, &snd_alloc_vmalloc_list) {
83 t = list_entry(head, struct snd_alloc_track, list);
84 if (t->magic != VMALLOC_MAGIC) {
85 snd_printk(KERN_ERR "Corrupted vmalloc\n");
86 break;
87 }
88 snd_printk(KERN_ERR "vmalloc(%ld) from %p not freed\n", (long) t->size, t->caller);
89 }
90} 75}
91 76
92static void *__snd_kmalloc(size_t size, gfp_t flags, void *caller) 77static void *__snd_kmalloc(size_t size, gfp_t flags, void *caller)
@@ -153,43 +138,6 @@ void snd_hidden_kfree(const void *obj)
153 snd_wrapper_kfree(obj); 138 snd_wrapper_kfree(obj);
154} 139}
155 140
156void *snd_hidden_vmalloc(unsigned long size)
157{
158 void *ptr;
159 ptr = snd_wrapper_vmalloc(size + sizeof(struct snd_alloc_track));
160 if (ptr) {
161 struct snd_alloc_track *t = (struct snd_alloc_track *)ptr;
162 t->magic = VMALLOC_MAGIC;
163 t->caller = __builtin_return_address(0);
164 spin_lock(&snd_alloc_vmalloc_lock);
165 list_add_tail(&t->list, &snd_alloc_vmalloc_list);
166 spin_unlock(&snd_alloc_vmalloc_lock);
167 t->size = size;
168 snd_alloc_vmalloc += size;
169 ptr = t->data;
170 }
171 return ptr;
172}
173
174void snd_hidden_vfree(void *obj)
175{
176 struct snd_alloc_track *t;
177 if (obj == NULL)
178 return;
179 t = snd_alloc_track_entry(obj);
180 if (t->magic != VMALLOC_MAGIC) {
181 snd_printk(KERN_ERR "bad vfree (called from %p)\n", __builtin_return_address(0));
182 return;
183 }
184 spin_lock(&snd_alloc_vmalloc_lock);
185 list_del(&t->list);
186 spin_unlock(&snd_alloc_vmalloc_lock);
187 t->magic = 0;
188 snd_alloc_vmalloc -= t->size;
189 obj = t;
190 snd_wrapper_vfree(obj);
191}
192
193char *snd_hidden_kstrdup(const char *s, gfp_t flags) 141char *snd_hidden_kstrdup(const char *s, gfp_t flags)
194{ 142{
195 int len; 143 int len;
@@ -207,7 +155,6 @@ char *snd_hidden_kstrdup(const char *s, gfp_t flags)
207static void snd_memory_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) 155static void snd_memory_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
208{ 156{
209 snd_iprintf(buffer, "kmalloc: %li bytes\n", snd_alloc_kmalloc); 157 snd_iprintf(buffer, "kmalloc: %li bytes\n", snd_alloc_kmalloc);
210 snd_iprintf(buffer, "vmalloc: %li bytes\n", snd_alloc_vmalloc);
211} 158}
212 159
213int __init snd_memory_info_init(void) 160int __init snd_memory_info_init(void)
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 11a7675b719b..3eddfdede9f3 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -23,8 +23,17 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/sched.h> 24#include <linux/sched.h>
25#include <linux/time.h> 25#include <linux/time.h>
26#include <linux/ioport.h>
26#include <sound/core.h> 27#include <sound/core.h>
27 28
29void release_and_free_resource(struct resource *res)
30{
31 if (res) {
32 release_resource(res);
33 kfree_nocheck(res);
34 }
35}
36
28#ifdef CONFIG_SND_VERBOSE_PRINTK 37#ifdef CONFIG_SND_VERBOSE_PRINTK
29void snd_verbose_printk(const char *file, int line, const char *format, ...) 38void snd_verbose_printk(const char *file, int line, const char *format, ...)
30{ 39{
diff --git a/sound/core/sound.c b/sound/core/sound.c
index bc8ad0017984..e94eebd8ad6f 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -407,8 +407,6 @@ EXPORT_SYMBOL(snd_unregister_oss_device);
407EXPORT_SYMBOL(snd_hidden_kmalloc); 407EXPORT_SYMBOL(snd_hidden_kmalloc);
408EXPORT_SYMBOL(snd_hidden_kcalloc); 408EXPORT_SYMBOL(snd_hidden_kcalloc);
409EXPORT_SYMBOL(snd_hidden_kfree); 409EXPORT_SYMBOL(snd_hidden_kfree);
410EXPORT_SYMBOL(snd_hidden_vmalloc);
411EXPORT_SYMBOL(snd_hidden_vfree);
412EXPORT_SYMBOL(snd_hidden_kstrdup); 410EXPORT_SYMBOL(snd_hidden_kstrdup);
413#endif 411#endif
414EXPORT_SYMBOL(copy_to_user_fromio); 412EXPORT_SYMBOL(copy_to_user_fromio);
@@ -487,6 +485,7 @@ EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat);
487EXPORT_SYMBOL(snd_ctl_elem_read); 485EXPORT_SYMBOL(snd_ctl_elem_read);
488EXPORT_SYMBOL(snd_ctl_elem_write); 486EXPORT_SYMBOL(snd_ctl_elem_write);
489 /* misc.c */ 487 /* misc.c */
488EXPORT_SYMBOL(release_and_free_resource);
490#ifdef CONFIG_SND_VERBOSE_PRINTK 489#ifdef CONFIG_SND_VERBOSE_PRINTK
491EXPORT_SYMBOL(snd_verbose_printk); 490EXPORT_SYMBOL(snd_verbose_printk);
492#endif 491#endif
@@ -497,6 +496,4 @@ EXPORT_SYMBOL(snd_verbose_printd);
497#ifdef CONFIG_SND_DEBUG_MEMORY 496#ifdef CONFIG_SND_DEBUG_MEMORY
498EXPORT_SYMBOL(snd_wrapper_kmalloc); 497EXPORT_SYMBOL(snd_wrapper_kmalloc);
499EXPORT_SYMBOL(snd_wrapper_kfree); 498EXPORT_SYMBOL(snd_wrapper_kfree);
500EXPORT_SYMBOL(snd_wrapper_vmalloc);
501EXPORT_SYMBOL(snd_wrapper_vfree);
502#endif 499#endif
diff --git a/sound/core/wrappers.c b/sound/core/wrappers.c
index 296b716f1376..19e899089cb3 100644
--- a/sound/core/wrappers.c
+++ b/sound/core/wrappers.c
@@ -36,15 +36,5 @@ void snd_wrapper_kfree(const void *obj)
36{ 36{
37 kfree(obj); 37 kfree(obj);
38} 38}
39
40void *snd_wrapper_vmalloc(unsigned long size)
41{
42 return vmalloc(size);
43}
44
45void snd_wrapper_vfree(void *obj)
46{
47 vfree(obj);
48}
49#endif 39#endif
50 40