hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/sound/core/seq/seq_memory.c
....@@ -1,30 +1,16 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ALSA sequencer Memory Manager
34 * Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
45 * Jaroslav Kysela <perex@perex.cz>
56 * 2000 by Takashi Iwai <tiwai@suse.de>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
- *
217 */
228
239 #include <linux/init.h>
2410 #include <linux/export.h>
2511 #include <linux/slab.h>
2612 #include <linux/sched/signal.h>
27
-#include <linux/vmalloc.h>
13
+#include <linux/mm.h>
2814 #include <sound/core.h>
2915
3016 #include <sound/seq_kernel.h>
....@@ -126,15 +112,19 @@
126112 * expand the variable length event to linear buffer space.
127113 */
128114
129
-static int seq_copy_in_kernel(char **bufptr, const void *src, int size)
115
+static int seq_copy_in_kernel(void *ptr, void *src, int size)
130116 {
117
+ char **bufptr = ptr;
118
+
131119 memcpy(*bufptr, src, size);
132120 *bufptr += size;
133121 return 0;
134122 }
135123
136
-static int seq_copy_in_user(char __user **bufptr, const void *src, int size)
124
+static int seq_copy_in_user(void *ptr, void *src, int size)
137125 {
126
+ char __user **bufptr = ptr;
127
+
138128 if (copy_to_user(*bufptr, src, size))
139129 return -EFAULT;
140130 *bufptr += size;
....@@ -163,8 +153,7 @@
163153 return newlen;
164154 }
165155 err = snd_seq_dump_var_event(event,
166
- in_kernel ? (snd_seq_dump_func_t)seq_copy_in_kernel :
167
- (snd_seq_dump_func_t)seq_copy_in_user,
156
+ in_kernel ? seq_copy_in_kernel : seq_copy_in_user,
168157 &buf);
169158 return err < 0 ? err : newlen;
170159 }
....@@ -244,13 +233,13 @@
244233
245234 set_current_state(TASK_INTERRUPTIBLE);
246235 add_wait_queue(&pool->output_sleep, &wait);
247
- spin_unlock_irq(&pool->lock);
236
+ spin_unlock_irqrestore(&pool->lock, flags);
248237 if (mutexp)
249238 mutex_unlock(mutexp);
250239 schedule();
251240 if (mutexp)
252241 mutex_lock(mutexp);
253
- spin_lock_irq(&pool->lock);
242
+ spin_lock_irqsave(&pool->lock, flags);
254243 remove_wait_queue(&pool->output_sleep, &wait);
255244 /* interrupted? */
256245 if (signal_pending(current)) {
....@@ -384,21 +373,20 @@
384373 {
385374 int cell;
386375 struct snd_seq_event_cell *cellptr;
387
- unsigned long flags;
388376
389377 if (snd_BUG_ON(!pool))
390378 return -EINVAL;
391379
392
- cellptr = vmalloc(array_size(sizeof(struct snd_seq_event_cell),
393
- pool->size));
380
+ cellptr = kvmalloc_array(sizeof(struct snd_seq_event_cell), pool->size,
381
+ GFP_KERNEL);
394382 if (!cellptr)
395383 return -ENOMEM;
396384
397385 /* add new cells to the free cell list */
398
- spin_lock_irqsave(&pool->lock, flags);
386
+ spin_lock_irq(&pool->lock);
399387 if (pool->ptr) {
400
- spin_unlock_irqrestore(&pool->lock, flags);
401
- vfree(cellptr);
388
+ spin_unlock_irq(&pool->lock);
389
+ kvfree(cellptr);
402390 return 0;
403391 }
404392
....@@ -416,7 +404,7 @@
416404 /* init statistics */
417405 pool->max_used = 0;
418406 pool->total_elements = pool->size;
419
- spin_unlock_irqrestore(&pool->lock, flags);
407
+ spin_unlock_irq(&pool->lock);
420408 return 0;
421409 }
422410
....@@ -435,7 +423,6 @@
435423 /* remove events */
436424 int snd_seq_pool_done(struct snd_seq_pool *pool)
437425 {
438
- unsigned long flags;
439426 struct snd_seq_event_cell *ptr;
440427
441428 if (snd_BUG_ON(!pool))
....@@ -449,18 +436,18 @@
449436 schedule_timeout_uninterruptible(1);
450437
451438 /* release all resources */
452
- spin_lock_irqsave(&pool->lock, flags);
439
+ spin_lock_irq(&pool->lock);
453440 ptr = pool->ptr;
454441 pool->ptr = NULL;
455442 pool->free = NULL;
456443 pool->total_elements = 0;
457
- spin_unlock_irqrestore(&pool->lock, flags);
444
+ spin_unlock_irq(&pool->lock);
458445
459
- vfree(ptr);
446
+ kvfree(ptr);
460447
461
- spin_lock_irqsave(&pool->lock, flags);
448
+ spin_lock_irq(&pool->lock);
462449 pool->closing = 0;
463
- spin_unlock_irqrestore(&pool->lock, flags);
450
+ spin_unlock_irq(&pool->lock);
464451
465452 return 0;
466453 }