summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Grund <flamefire89@gmail.com>2023-11-05 11:26:39 +0100
committerAlexander Grund <flamefire89@gmail.com>2023-11-09 19:17:24 +0100
commit05145446909ee777a4dd20600a5074a0031c3f3f (patch)
treece954915d136c776c2e0503896082b2327b469b9
parent5d83531b26c159ebd3b2d689c941b3f6ebcd0eb2 (diff)
Revert "ALSA: rawmidi: Fix racy buffer resize under concurrent accesses"
This reverts commit 718eede1eeb602531e09191d3107eb849bbe64eb. Remove the remaining parts of that commit as we use `realloc_mutex` instead to protect the buffer and `buffer_ref` is effectively unused. Change-Id: If0cf319ca5ab097751bc5e6753f61bd626d9e601
-rw-r--r--include/sound/rawmidi.h1
-rw-r--r--sound/core/rawmidi.c28
2 files changed, 6 insertions, 23 deletions
diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index afffa756357a..3e0171ea47f3 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -76,7 +76,6 @@ struct snd_rawmidi_runtime {
size_t avail_min; /* min avail for wakeup */
size_t avail; /* max used buffer for wakeup */
size_t xruns; /* over/underruns counter */
- int buffer_ref; /* buffer reference count */
/* misc */
spinlock_t lock;
struct mutex realloc_mutex;
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 108c75e35b39..a7a1b1c4cad9 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -108,17 +108,6 @@ static void snd_rawmidi_input_event_work(struct work_struct *work)
runtime->event(runtime->substream);
}
-/* buffer refcount management: call with runtime->lock held */
-static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime)
-{
- runtime->buffer_ref++;
-}
-
-static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime)
-{
- runtime->buffer_ref--;
-}
-
static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
{
struct snd_rawmidi_runtime *runtime;
@@ -990,12 +979,10 @@ static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
long result = 0, count1;
struct snd_rawmidi_runtime *runtime = substream->runtime;
unsigned long appl_ptr;
- int err = 0;
if (userbuf)
mutex_lock(&runtime->realloc_mutex);
spin_lock_irqsave(&runtime->lock, flags);
- snd_rawmidi_buffer_ref(runtime);
while (count > 0 && runtime->avail) {
count1 = runtime->buffer_size - runtime->appl_ptr;
if (count1 > count)
@@ -1014,21 +1001,20 @@ static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
if (userbuf) {
spin_unlock_irqrestore(&runtime->lock, flags);
if (copy_to_user(userbuf + result,
- runtime->buffer + appl_ptr, count1))
- err = -EFAULT;
+ runtime->buffer + appl_ptr, count1)) {
+ mutex_unlock(&runtime->realloc_mutex);
+ return result > 0 ? result : -EFAULT;
+ }
+
spin_lock_irqsave(&runtime->lock, flags);
- if (err)
- goto out;
}
result += count1;
count -= count1;
}
- out:
- snd_rawmidi_buffer_unref(runtime);
spin_unlock_irqrestore(&runtime->lock, flags);
if (userbuf)
mutex_unlock(&runtime->realloc_mutex);
- return result > 0 ? result : err;
+ return result;
}
long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
@@ -1303,7 +1289,6 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
return -EAGAIN;
}
}
- snd_rawmidi_buffer_ref(runtime);
while (count > 0 && runtime->avail > 0) {
count1 = runtime->buffer_size - runtime->appl_ptr;
if (count1 > count)
@@ -1335,7 +1320,6 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
}
__end:
count1 = runtime->avail < runtime->buffer_size;
- snd_rawmidi_buffer_unref(runtime);
spin_unlock_irqrestore(&runtime->lock, flags);
if (userbuf)
mutex_unlock(&runtime->realloc_mutex);