diff options
author | Paulo Marques <pmarques@grupopie.com> | 2005-06-23 03:09:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-23 12:45:18 -0400 |
commit | 543537bd922692bc978e2e356fcd8bfc9c2ee7d5 (patch) | |
tree | 0089e3907e7d6c17c01cffc6ea4a8962ed053079 /sound/core | |
parent | 991114c6fa6a21d1fa4d544abe78592352860c82 (diff) |
[PATCH] create a kstrdup library function
This patch creates a new kstrdup library function and changes the "local"
implementations in several places to use this function.
Most of the changes come from the sound and net subsystems. The sound part
had already been acknowledged by Takashi Iwai and the net part by David S.
Miller.
I left UML alone for now because I would need more time to read the code
carefully before making changes there.
Signed-off-by: Paulo Marques <pmarques@grupopie.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/info.c | 3 | ||||
-rw-r--r-- | sound/core/info_oss.c | 3 | ||||
-rw-r--r-- | sound/core/memory.c | 41 | ||||
-rw-r--r-- | sound/core/oss/mixer_oss.c | 3 | ||||
-rw-r--r-- | sound/core/oss/pcm_oss.c | 3 | ||||
-rw-r--r-- | sound/core/sound.c | 2 | ||||
-rw-r--r-- | sound/core/timer.c | 3 |
7 files changed, 25 insertions, 33 deletions
diff --git a/sound/core/info.c b/sound/core/info.c index 31faffe01cb0..5e122bbe7c92 100644 --- a/sound/core/info.c +++ b/sound/core/info.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/vmalloc.h> | 24 | #include <linux/vmalloc.h> |
25 | #include <linux/time.h> | 25 | #include <linux/time.h> |
26 | #include <linux/smp_lock.h> | 26 | #include <linux/smp_lock.h> |
27 | #include <linux/string.h> | ||
27 | #include <sound/core.h> | 28 | #include <sound/core.h> |
28 | #include <sound/minors.h> | 29 | #include <sound/minors.h> |
29 | #include <sound/info.h> | 30 | #include <sound/info.h> |
@@ -754,7 +755,7 @@ static snd_info_entry_t *snd_info_create_entry(const char *name) | |||
754 | entry = kcalloc(1, sizeof(*entry), GFP_KERNEL); | 755 | entry = kcalloc(1, sizeof(*entry), GFP_KERNEL); |
755 | if (entry == NULL) | 756 | if (entry == NULL) |
756 | return NULL; | 757 | return NULL; |
757 | entry->name = snd_kmalloc_strdup(name, GFP_KERNEL); | 758 | entry->name = kstrdup(name, GFP_KERNEL); |
758 | if (entry->name == NULL) { | 759 | if (entry->name == NULL) { |
759 | kfree(entry); | 760 | kfree(entry); |
760 | return NULL; | 761 | return NULL; |
diff --git a/sound/core/info_oss.c b/sound/core/info_oss.c index f9e4ce443454..12107968d402 100644 --- a/sound/core/info_oss.c +++ b/sound/core/info_oss.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <sound/driver.h> | 22 | #include <sound/driver.h> |
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/time.h> | 24 | #include <linux/time.h> |
25 | #include <linux/string.h> | ||
25 | #include <sound/core.h> | 26 | #include <sound/core.h> |
26 | #include <sound/minors.h> | 27 | #include <sound/minors.h> |
27 | #include <sound/info.h> | 28 | #include <sound/info.h> |
@@ -51,7 +52,7 @@ int snd_oss_info_register(int dev, int num, char *string) | |||
51 | x = NULL; | 52 | x = NULL; |
52 | } | 53 | } |
53 | } else { | 54 | } else { |
54 | x = snd_kmalloc_strdup(string, GFP_KERNEL); | 55 | x = kstrdup(string, GFP_KERNEL); |
55 | if (x == NULL) { | 56 | if (x == NULL) { |
56 | up(&strings); | 57 | up(&strings); |
57 | return -ENOMEM; | 58 | return -ENOMEM; |
diff --git a/sound/core/memory.c b/sound/core/memory.c index 20860fec9364..c1fb28e84330 100644 --- a/sound/core/memory.c +++ b/sound/core/memory.c | |||
@@ -184,6 +184,20 @@ void snd_hidden_vfree(void *obj) | |||
184 | snd_wrapper_vfree(obj); | 184 | snd_wrapper_vfree(obj); |
185 | } | 185 | } |
186 | 186 | ||
187 | char *snd_hidden_kstrdup(const char *s, int flags) | ||
188 | { | ||
189 | int len; | ||
190 | char *buf; | ||
191 | |||
192 | if (!s) return NULL; | ||
193 | |||
194 | len = strlen(s) + 1; | ||
195 | buf = _snd_kmalloc(len, flags); | ||
196 | if (buf) | ||
197 | memcpy(buf, s, len); | ||
198 | return buf; | ||
199 | } | ||
200 | |||
187 | static void snd_memory_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) | 201 | static void snd_memory_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) |
188 | { | 202 | { |
189 | snd_iprintf(buffer, "kmalloc: %li bytes\n", snd_alloc_kmalloc); | 203 | snd_iprintf(buffer, "kmalloc: %li bytes\n", snd_alloc_kmalloc); |
@@ -214,36 +228,9 @@ int __exit snd_memory_info_done(void) | |||
214 | return 0; | 228 | return 0; |
215 | } | 229 | } |
216 | 230 | ||
217 | #else | ||
218 | |||
219 | #define _snd_kmalloc kmalloc | ||
220 | |||
221 | #endif /* CONFIG_SND_DEBUG_MEMORY */ | 231 | #endif /* CONFIG_SND_DEBUG_MEMORY */ |
222 | 232 | ||
223 | /** | 233 | /** |
224 | * snd_kmalloc_strdup - copy the string | ||
225 | * @string: the original string | ||
226 | * @flags: allocation conditions, GFP_XXX | ||
227 | * | ||
228 | * Allocates a memory chunk via kmalloc() and copies the string to it. | ||
229 | * | ||
230 | * Returns the pointer, or NULL if no enoguh memory. | ||
231 | */ | ||
232 | char *snd_kmalloc_strdup(const char *string, int flags) | ||
233 | { | ||
234 | size_t len; | ||
235 | char *ptr; | ||
236 | |||
237 | if (!string) | ||
238 | return NULL; | ||
239 | len = strlen(string) + 1; | ||
240 | ptr = _snd_kmalloc(len, flags); | ||
241 | if (ptr) | ||
242 | memcpy(ptr, string, len); | ||
243 | return ptr; | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * copy_to_user_fromio - copy data from mmio-space to user-space | 234 | * copy_to_user_fromio - copy data from mmio-space to user-space |
248 | * @dst: the destination pointer on user-space | 235 | * @dst: the destination pointer on user-space |
249 | * @src: the source pointer on mmio | 236 | * @src: the source pointer on mmio |
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index 98ed9a9f0da6..98fc0766f885 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/smp_lock.h> | 24 | #include <linux/smp_lock.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/time.h> | 26 | #include <linux/time.h> |
27 | #include <linux/string.h> | ||
27 | #include <sound/core.h> | 28 | #include <sound/core.h> |
28 | #include <sound/minors.h> | 29 | #include <sound/minors.h> |
29 | #include <sound/control.h> | 30 | #include <sound/control.h> |
@@ -1137,7 +1138,7 @@ static void snd_mixer_oss_proc_write(snd_info_entry_t *entry, | |||
1137 | goto __unlock; | 1138 | goto __unlock; |
1138 | } | 1139 | } |
1139 | tbl->oss_id = ch; | 1140 | tbl->oss_id = ch; |
1140 | tbl->name = snd_kmalloc_strdup(str, GFP_KERNEL); | 1141 | tbl->name = kstrdup(str, GFP_KERNEL); |
1141 | if (! tbl->name) { | 1142 | if (! tbl->name) { |
1142 | kfree(tbl); | 1143 | kfree(tbl); |
1143 | goto __unlock; | 1144 | goto __unlock; |
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c index cab30977e7c0..de7444c586f9 100644 --- a/sound/core/oss/pcm_oss.c +++ b/sound/core/oss/pcm_oss.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/time.h> | 33 | #include <linux/time.h> |
34 | #include <linux/vmalloc.h> | 34 | #include <linux/vmalloc.h> |
35 | #include <linux/moduleparam.h> | 35 | #include <linux/moduleparam.h> |
36 | #include <linux/string.h> | ||
36 | #include <sound/core.h> | 37 | #include <sound/core.h> |
37 | #include <sound/minors.h> | 38 | #include <sound/minors.h> |
38 | #include <sound/pcm.h> | 39 | #include <sound/pcm.h> |
@@ -2360,7 +2361,7 @@ static void snd_pcm_oss_proc_write(snd_info_entry_t *entry, | |||
2360 | for (setup1 = pstr->oss.setup_list; setup1->next; setup1 = setup1->next); | 2361 | for (setup1 = pstr->oss.setup_list; setup1->next; setup1 = setup1->next); |
2361 | setup1->next = setup; | 2362 | setup1->next = setup; |
2362 | } | 2363 | } |
2363 | template.task_name = snd_kmalloc_strdup(task_name, GFP_KERNEL); | 2364 | template.task_name = kstrdup(task_name, GFP_KERNEL); |
2364 | } else { | 2365 | } else { |
2365 | buffer->error = -ENOMEM; | 2366 | buffer->error = -ENOMEM; |
2366 | } | 2367 | } |
diff --git a/sound/core/sound.c b/sound/core/sound.c index 0815fadeb3ec..7612884f530b 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c | |||
@@ -399,8 +399,8 @@ EXPORT_SYMBOL(snd_hidden_kcalloc); | |||
399 | EXPORT_SYMBOL(snd_hidden_kfree); | 399 | EXPORT_SYMBOL(snd_hidden_kfree); |
400 | EXPORT_SYMBOL(snd_hidden_vmalloc); | 400 | EXPORT_SYMBOL(snd_hidden_vmalloc); |
401 | EXPORT_SYMBOL(snd_hidden_vfree); | 401 | EXPORT_SYMBOL(snd_hidden_vfree); |
402 | EXPORT_SYMBOL(snd_hidden_kstrdup); | ||
402 | #endif | 403 | #endif |
403 | EXPORT_SYMBOL(snd_kmalloc_strdup); | ||
404 | EXPORT_SYMBOL(copy_to_user_fromio); | 404 | EXPORT_SYMBOL(copy_to_user_fromio); |
405 | EXPORT_SYMBOL(copy_from_user_toio); | 405 | EXPORT_SYMBOL(copy_from_user_toio); |
406 | /* init.c */ | 406 | /* init.c */ |
diff --git a/sound/core/timer.c b/sound/core/timer.c index b498e5482d77..cfaccd415b3b 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/time.h> | 27 | #include <linux/time.h> |
28 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <linux/string.h> | ||
29 | #include <sound/core.h> | 30 | #include <sound/core.h> |
30 | #include <sound/timer.h> | 31 | #include <sound/timer.h> |
31 | #include <sound/control.h> | 32 | #include <sound/control.h> |
@@ -100,7 +101,7 @@ static snd_timer_instance_t *snd_timer_instance_new(char *owner, snd_timer_t *ti | |||
100 | timeri = kcalloc(1, sizeof(*timeri), GFP_KERNEL); | 101 | timeri = kcalloc(1, sizeof(*timeri), GFP_KERNEL); |
101 | if (timeri == NULL) | 102 | if (timeri == NULL) |
102 | return NULL; | 103 | return NULL; |
103 | timeri->owner = snd_kmalloc_strdup(owner, GFP_KERNEL); | 104 | timeri->owner = kstrdup(owner, GFP_KERNEL); |
104 | if (! timeri->owner) { | 105 | if (! timeri->owner) { |
105 | kfree(timeri); | 106 | kfree(timeri); |
106 | return NULL; | 107 | return NULL; |