util_mem.c (c1f3ee120bb61045b1c0a3ead620d1d65af47130) util_mem.c (5e246b850df563224be26f1d409cf66fd6c968df)
1/*
2 * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
3 *
4 * Generic memory management routines for soundcard memory allocation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 41 unchanged lines hidden (view full) ---

50
51/*
52 * free a memory manager
53 */
54void snd_util_memhdr_free(struct snd_util_memhdr *hdr)
55{
56 struct list_head *p;
57
1/*
2 * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
3 *
4 * Generic memory management routines for soundcard memory allocation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 41 unchanged lines hidden (view full) ---

50
51/*
52 * free a memory manager
53 */
54void snd_util_memhdr_free(struct snd_util_memhdr *hdr)
55{
56 struct list_head *p;
57
58 snd_assert(hdr != NULL, return);
58 if (!hdr)
59 return;
59 /* release all blocks */
60 while ((p = hdr->block.next) != &hdr->block) {
61 list_del(p);
62 kfree(get_memblk(p));
63 }
64 kfree(hdr);
65}
66
67/*
68 * allocate a memory block (without mutex)
69 */
70struct snd_util_memblk *
71__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size)
72{
73 struct snd_util_memblk *blk;
74 unsigned int units, prev_offset;
75 struct list_head *p;
76
60 /* release all blocks */
61 while ((p = hdr->block.next) != &hdr->block) {
62 list_del(p);
63 kfree(get_memblk(p));
64 }
65 kfree(hdr);
66}
67
68/*
69 * allocate a memory block (without mutex)
70 */
71struct snd_util_memblk *
72__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size)
73{
74 struct snd_util_memblk *blk;
75 unsigned int units, prev_offset;
76 struct list_head *p;
77
77 snd_assert(hdr != NULL, return NULL);
78 snd_assert(size > 0, return NULL);
78 if (snd_BUG_ON(!hdr || size <= 0))
79 return NULL;
79
80 /* word alignment */
81 units = size;
82 if (units & 1)
83 units++;
84 if (units > hdr->size)
85 return NULL;
86

--- 69 unchanged lines hidden (view full) ---

156 kfree(blk);
157}
158
159/*
160 * free a memory block (with mutex)
161 */
162int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
163{
80
81 /* word alignment */
82 units = size;
83 if (units & 1)
84 units++;
85 if (units > hdr->size)
86 return NULL;
87

--- 69 unchanged lines hidden (view full) ---

157 kfree(blk);
158}
159
160/*
161 * free a memory block (with mutex)
162 */
163int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
164{
164 snd_assert(hdr && blk, return -EINVAL);
165 if (snd_BUG_ON(!hdr || !blk))
166 return -EINVAL;
165
166 mutex_lock(&hdr->block_mutex);
167 __snd_util_mem_free(hdr, blk);
168 mutex_unlock(&hdr->block_mutex);
169 return 0;
170}
171
172/*

--- 36 unchanged lines hidden ---
167
168 mutex_lock(&hdr->block_mutex);
169 __snd_util_mem_free(hdr, blk);
170 mutex_unlock(&hdr->block_mutex);
171 return 0;
172}
173
174/*

--- 36 unchanged lines hidden ---