aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/rawmidi.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r--sound/core/rawmidi.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index cbbed0db9e5..849a0ed9505 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -92,16 +92,12 @@ static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substre
92 (!substream->append || runtime->avail >= count); 92 (!substream->append || runtime->avail >= count);
93} 93}
94 94
95static void snd_rawmidi_input_event_tasklet(unsigned long data) 95static void snd_rawmidi_input_event_work(struct work_struct *work)
96{ 96{
97 struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data; 97 struct snd_rawmidi_runtime *runtime =
98 substream->runtime->event(substream); 98 container_of(work, struct snd_rawmidi_runtime, event_work);
99} 99 if (runtime->event)
100 100 runtime->event(runtime->substream);
101static void snd_rawmidi_output_trigger_tasklet(unsigned long data)
102{
103 struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data;
104 substream->ops->trigger(substream, 1);
105} 101}
106 102
107static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream) 103static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
@@ -110,16 +106,10 @@ static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
110 106
111 if ((runtime = kzalloc(sizeof(*runtime), GFP_KERNEL)) == NULL) 107 if ((runtime = kzalloc(sizeof(*runtime), GFP_KERNEL)) == NULL)
112 return -ENOMEM; 108 return -ENOMEM;
109 runtime->substream = substream;
113 spin_lock_init(&runtime->lock); 110 spin_lock_init(&runtime->lock);
114 init_waitqueue_head(&runtime->sleep); 111 init_waitqueue_head(&runtime->sleep);
115 if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT) 112 INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work);
116 tasklet_init(&runtime->tasklet,
117 snd_rawmidi_input_event_tasklet,
118 (unsigned long)substream);
119 else
120 tasklet_init(&runtime->tasklet,
121 snd_rawmidi_output_trigger_tasklet,
122 (unsigned long)substream);
123 runtime->event = NULL; 113 runtime->event = NULL;
124 runtime->buffer_size = PAGE_SIZE; 114 runtime->buffer_size = PAGE_SIZE;
125 runtime->avail_min = 1; 115 runtime->avail_min = 1;
@@ -150,12 +140,7 @@ static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *subs
150{ 140{
151 if (!substream->opened) 141 if (!substream->opened)
152 return; 142 return;
153 if (up) { 143 substream->ops->trigger(substream, up);
154 tasklet_schedule(&substream->runtime->tasklet);
155 } else {
156 tasklet_kill(&substream->runtime->tasklet);
157 substream->ops->trigger(substream, 0);
158 }
159} 144}
160 145
161static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up) 146static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
@@ -163,8 +148,8 @@ static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, i
163 if (!substream->opened) 148 if (!substream->opened)
164 return; 149 return;
165 substream->ops->trigger(substream, up); 150 substream->ops->trigger(substream, up);
166 if (!up && substream->runtime->event) 151 if (!up)
167 tasklet_kill(&substream->runtime->tasklet); 152 cancel_work_sync(&substream->runtime->event_work);
168} 153}
169 154
170int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream) 155int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
@@ -641,10 +626,10 @@ int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
641 return -EINVAL; 626 return -EINVAL;
642 } 627 }
643 if (params->buffer_size != runtime->buffer_size) { 628 if (params->buffer_size != runtime->buffer_size) {
644 newbuf = kmalloc(params->buffer_size, GFP_KERNEL); 629 newbuf = krealloc(runtime->buffer, params->buffer_size,
630 GFP_KERNEL);
645 if (!newbuf) 631 if (!newbuf)
646 return -ENOMEM; 632 return -ENOMEM;
647 kfree(runtime->buffer);
648 runtime->buffer = newbuf; 633 runtime->buffer = newbuf;
649 runtime->buffer_size = params->buffer_size; 634 runtime->buffer_size = params->buffer_size;
650 runtime->avail = runtime->buffer_size; 635 runtime->avail = runtime->buffer_size;
@@ -668,10 +653,10 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
668 return -EINVAL; 653 return -EINVAL;
669 } 654 }
670 if (params->buffer_size != runtime->buffer_size) { 655 if (params->buffer_size != runtime->buffer_size) {
671 newbuf = kmalloc(params->buffer_size, GFP_KERNEL); 656 newbuf = krealloc(runtime->buffer, params->buffer_size,
657 GFP_KERNEL);
672 if (!newbuf) 658 if (!newbuf)
673 return -ENOMEM; 659 return -ENOMEM;
674 kfree(runtime->buffer);
675 runtime->buffer = newbuf; 660 runtime->buffer = newbuf;
676 runtime->buffer_size = params->buffer_size; 661 runtime->buffer_size = params->buffer_size;
677 } 662 }
@@ -926,7 +911,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
926 } 911 }
927 if (result > 0) { 912 if (result > 0) {
928 if (runtime->event) 913 if (runtime->event)
929 tasklet_schedule(&runtime->tasklet); 914 schedule_work(&runtime->event_work);
930 else if (snd_rawmidi_ready(substream)) 915 else if (snd_rawmidi_ready(substream))
931 wake_up(&runtime->sleep); 916 wake_up(&runtime->sleep);
932 } 917 }