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/memory.c | |
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/memory.c')
-rw-r--r-- | sound/core/memory.c | 41 |
1 files changed, 14 insertions, 27 deletions
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 |