aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ctxfi/ctvmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/ctxfi/ctvmem.c')
-rw-r--r--sound/pci/ctxfi/ctvmem.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c
index cecf77e3ee86..363b67e3a9e7 100644
--- a/sound/pci/ctxfi/ctvmem.c
+++ b/sound/pci/ctxfi/ctvmem.c
@@ -35,25 +35,27 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
35 struct ct_vm_block *block = NULL, *entry = NULL; 35 struct ct_vm_block *block = NULL, *entry = NULL;
36 struct list_head *pos = NULL; 36 struct list_head *pos = NULL;
37 37
38 mutex_lock(&vm->lock);
38 list_for_each(pos, &vm->unused) { 39 list_for_each(pos, &vm->unused) {
39 entry = list_entry(pos, struct ct_vm_block, list); 40 entry = list_entry(pos, struct ct_vm_block, list);
40 if (entry->size >= size) 41 if (entry->size >= size)
41 break; /* found a block that is big enough */ 42 break; /* found a block that is big enough */
42 } 43 }
43 if (pos == &vm->unused) 44 if (pos == &vm->unused)
44 return NULL; 45 goto out;
45 46
46 if (entry->size == size) { 47 if (entry->size == size) {
47 /* Move the vm node from unused list to used list directly */ 48 /* Move the vm node from unused list to used list directly */
48 list_del(&entry->list); 49 list_del(&entry->list);
49 list_add(&entry->list, &vm->used); 50 list_add(&entry->list, &vm->used);
50 vm->size -= size; 51 vm->size -= size;
51 return entry; 52 block = entry;
53 goto out;
52 } 54 }
53 55
54 block = kzalloc(sizeof(*block), GFP_KERNEL); 56 block = kzalloc(sizeof(*block), GFP_KERNEL);
55 if (NULL == block) 57 if (NULL == block)
56 return NULL; 58 goto out;
57 59
58 block->addr = entry->addr; 60 block->addr = entry->addr;
59 block->size = size; 61 block->size = size;
@@ -62,6 +64,8 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
62 entry->size -= size; 64 entry->size -= size;
63 vm->size -= size; 65 vm->size -= size;
64 66
67 out:
68 mutex_unlock(&vm->lock);
65 return block; 69 return block;
66} 70}
67 71
@@ -70,6 +74,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
70 struct ct_vm_block *entry = NULL, *pre_ent = NULL; 74 struct ct_vm_block *entry = NULL, *pre_ent = NULL;
71 struct list_head *pos = NULL, *pre = NULL; 75 struct list_head *pos = NULL, *pre = NULL;
72 76
77 mutex_lock(&vm->lock);
73 list_del(&block->list); 78 list_del(&block->list);
74 vm->size += block->size; 79 vm->size += block->size;
75 80
@@ -106,6 +111,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
106 pos = pre; 111 pos = pre;
107 pre = pos->prev; 112 pre = pos->prev;
108 } 113 }
114 mutex_unlock(&vm->lock);
109} 115}
110 116
111/* Map host addr (kmalloced/vmalloced) to device logical addr. */ 117/* Map host addr (kmalloced/vmalloced) to device logical addr. */
@@ -191,6 +197,8 @@ int ct_vm_create(struct ct_vm **rvm)
191 if (NULL == vm) 197 if (NULL == vm)
192 return -ENOMEM; 198 return -ENOMEM;
193 199
200 mutex_init(&vm->lock);
201
194 /* Allocate page table pages */ 202 /* Allocate page table pages */
195 for (i = 0; i < CT_PTP_NUM; i++) { 203 for (i = 0; i < CT_PTP_NUM; i++) {
196 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL); 204 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL);