aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ctxfi/ctvmem.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-06-02 02:40:51 -0400
committerTakashi Iwai <tiwai@suse.de>2009-06-02 02:40:51 -0400
commit8a4259bf89d23bfd58d87e275ef6da29cea6b3c5 (patch)
treeee96ea01ae32a828f1446f52bd2534783e0c8dfd /sound/pci/ctxfi/ctvmem.c
parentaae80dc24aeddec4e2b6e182a43491942f8667d3 (diff)
ALSA: ctxfi - Fix Oops at mmapping
Replace a spinlock with a mutex protecting the vm block list at mmap / munmap calls, which caused Oops like below: BUG: sleeping function called from invalid context at mm/slub.c:1599 in_atomic(): 0, irqs_disabled(): 1, pid: 32065, name: xine Pid: 32065, comm: xine Tainted: P 2.6.29.4-75.fc10.x86_64 #1 Call Trace: [<ffffffff81040685>] __might_sleep+0x105/0x10a [<ffffffff810c9fae>] kmem_cache_alloc+0x32/0xe2 [<ffffffffa08e3110>] ct_vm_map+0xfa/0x19e [snd_ctxfi] [<ffffffffa08e1a07>] ct_map_audio_buffer+0x4c/0x76 [snd_ctxfi] [<ffffffffa08e2aa5>] atc_pcm_playback_prepare+0x1d7/0x2a8 [snd_ctxfi] [<ffffffff8105ef3f>] ? up_read+0x9/0xb [<ffffffff81186b61>] ? __up_read+0x7c/0x87 [<ffffffffa08e36a6>] ct_pcm_playback_prepare+0x39/0x60 [snd_ctxfi] [<ffffffffa0886bcb>] snd_pcm_do_prepare+0x16/0x28 [snd_pcm] [<ffffffffa08867c7>] snd_pcm_action_single+0x2d/0x5b [snd_pcm] [<ffffffffa08881f3>] snd_pcm_action_nonatomic+0x52/0x6a [snd_pcm] [<ffffffffa088a723>] snd_pcm_common_ioctl1+0x404/0xc79 [snd_pcm] [<ffffffff810c52c8>] ? alloc_pages_current+0xb9/0xc2 [<ffffffff810c9402>] ? new_slab+0x1a5/0x1cb [<ffffffff810ab9ea>] ? vma_prio_tree_insert+0x23/0xc1 [<ffffffffa088b411>] snd_pcm_playback_ioctl1+0x213/0x230 [snd_pcm] [<ffffffff810b6c20>] ? mmap_region+0x397/0x4c9 [<ffffffffa088bd9b>] snd_pcm_playback_ioctl+0x2e/0x36 [snd_pcm] [<ffffffff810ddc64>] vfs_ioctl+0x2a/0x78 [<ffffffff810de130>] do_vfs_ioctl+0x462/0x4a2 [<ffffffff81029cef>] ? default_spin_lock_flags+0x9/0xe [<ffffffff81374647>] ? trace_hardirqs_off_thunk+0x3a/0x6c [<ffffffff810de1c5>] sys_ioctl+0x55/0x77 [<ffffffff8101133a>] system_call_fastpath+0x16/0x1b Signed-off-by: Takashi Iwai <tiwai@suse.de>
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);