* [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers
@ 2026-11-18 13:55 Takashi Iwai
2026-11-18 13:55 ` [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access Takashi Iwai
2026-11-18 14:05 ` [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers sashiko-bot
0 siblings, 2 replies; 4+ messages in thread
From: Takashi Iwai @ 2026-11-18 13:55 UTC (permalink / raw)
To: linux-sound
There are a few places to grant the PCM buffer access with the gate
using runtime->buffer_accessing. They are paired like below in each
place:
if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
return -EBUSY;
....
atomic_dec(&runtime->buffer_accessing);
which is not really intuitive and error-prone, as being open-coded.
This patch introduces helper macros to replace the code like the above
with auto-cleanup. With the new helper, the above will become
SND_PCM_BUFFER_ACQUIRE(runtime, lock);
if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
return -EBUSY;
....
and the counter-part (atomic_dec()) is dropped as it's automagically
done by the auto-cleanup.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/core/pcm_lib.c | 7 +++---
sound/core/pcm_local.h | 26 +++++++++++++++++++++++
sound/core/pcm_native.c | 47 ++++++++++++++++-------------------------
3 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index bb16738bb591..3b66677c037a 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2377,10 +2377,9 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
err = -EINVAL;
goto _end_unlock;
}
- if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) {
- err = -EBUSY;
+ err = snd_pcm_buffer_access_get(runtime);
+ if (err < 0)
goto _end_unlock;
- }
snd_pcm_stream_unlock_irq(substream);
if (!is_playback)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU);
@@ -2389,7 +2388,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
if (is_playback)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
snd_pcm_stream_lock_irq(substream);
- atomic_dec(&runtime->buffer_accessing);
+ snd_pcm_buffer_access_put(runtime);
if (err < 0)
goto _end_unlock;
err = pcm_accessible_state(substream);
diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h
index 4b134d435c24..7762c89e0f9f 100644
--- a/sound/core/pcm_local.h
+++ b/sound/core/pcm_local.h
@@ -86,4 +86,30 @@ static inline void snd_pcm_dma_buffer_sync(struct snd_pcm_substream *substream,
#define is_oss_stream(substream) false
#endif
+/*
+ * helpers for restricting hw_params / hw_refine changes
+ */
+static inline int snd_pcm_buffer_access_get(struct snd_pcm_runtime *runtime)
+{
+ if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ return -EBUSY;
+ return 0;
+}
+
+static inline void snd_pcm_buffer_access_put(struct snd_pcm_runtime *runtime)
+{
+ atomic_dec(&runtime->buffer_accessing);
+}
+
+/* auto-cleanup macros */
+DEFINE_GUARD(snd_pcm_buffer_access, struct snd_pcm_runtime *,
+ snd_pcm_buffer_access_get(_T), snd_pcm_buffer_access_put(_T));
+DEFINE_GUARD_COND(snd_pcm_buffer_access, _try,
+ snd_pcm_buffer_access_get(_T), _RET == 0);
+
+#define SND_PCM_BUFFER_ACQUIRE(runtime, var) \
+ ACQUIRE(snd_pcm_buffer_access_try, var)(runtime)
+#define SND_PCM_BUFFER_ACQUIRE_ERR(var) \
+ ACQUIRE_ERR(snd_pcm_buffer_access_try, &(var))
+
#endif /* __SOUND_CORE_PCM_LOCAL_H */
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 5d80b56449e2..f58d9be2ad44 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3128,7 +3128,8 @@ static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream,
return 0;
/* Keep the DMA buffer alive through the sync below. */
- if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
return -EBUSY;
scoped_guard(pcm_stream_lock_irq, substream) {
ret = do_pcm_hwsync(substream);
@@ -3138,7 +3139,6 @@ static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream,
}
if (ret >= 0)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
- atomic_dec(&runtime->buffer_accessing);
return ret;
}
@@ -3152,7 +3152,8 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
return 0;
/* Keep the DMA buffer alive through the sync below. */
- if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
return -EBUSY;
scoped_guard(pcm_stream_lock_irq, substream) {
ret = do_pcm_hwsync(substream);
@@ -3162,7 +3163,6 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
}
if (ret >= 0)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
- atomic_dec(&runtime->buffer_accessing);
return ret;
}
@@ -3173,7 +3173,8 @@ static int snd_pcm_delay(struct snd_pcm_substream *substream,
int err;
/* Keep the DMA buffer alive through the sync below. */
- if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
return -EBUSY;
scoped_guard(pcm_stream_lock_irq, substream) {
err = do_pcm_hwsync(substream);
@@ -3181,7 +3182,6 @@ static int snd_pcm_delay(struct snd_pcm_substream *substream,
*delay = snd_pcm_calc_delay(substream);
}
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU);
- atomic_dec(&runtime->buffer_accessing);
return err;
}
@@ -4085,32 +4085,23 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
}
runtime = substream->runtime;
/* don't race with buffer reallocation in hw_params/hw_free */
- if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
return -EBUSY;
- if (runtime->state == SNDRV_PCM_STATE_OPEN) {
- err = -EBADFD;
- goto out;
- }
- if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) {
- err = -ENXIO;
- goto out;
- }
+ if (runtime->state == SNDRV_PCM_STATE_OPEN)
+ return -EBADFD;
+ if (!(runtime->info & SNDRV_PCM_INFO_MMAP))
+ return -ENXIO;
if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
- runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
- err = -EINVAL;
- goto out;
- }
+ runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
+ return -EINVAL;
size = area->vm_end - area->vm_start;
offset = area->vm_pgoff << PAGE_SHIFT;
dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
- if ((size_t)size > dma_bytes) {
- err = -EINVAL;
- goto out;
- }
- if (offset > dma_bytes - size) {
- err = -EINVAL;
- goto out;
- }
+ if ((size_t)size > dma_bytes)
+ return -EINVAL;
+ if (offset > dma_bytes - size)
+ return -EINVAL;
area->vm_ops = &snd_pcm_vm_ops_data;
area->vm_private_data = substream;
@@ -4120,8 +4111,6 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
err = snd_pcm_lib_default_mmap(substream, area);
if (!err)
atomic_inc(&substream->mmap_count);
-out:
- atomic_dec(&runtime->buffer_accessing);
return err;
}
EXPORT_SYMBOL(snd_pcm_mmap_data);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access
2026-11-18 13:55 [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers Takashi Iwai
@ 2026-11-18 13:55 ` Takashi Iwai
2026-11-18 14:29 ` sashiko-bot
2026-11-18 14:05 ` [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2026-11-18 13:55 UTC (permalink / raw)
To: linux-sound
While we've already protected the concurrent hw_params or hw_free
changes during the PCM streaming in snd_pcm_lib_read*() and
snd_pcm_lib_write*(), those entry points aren't covered by the buffer
access gate yet, hence the associated PCM runtime instance may still
change concurrently. This can lead to the inconsistency, e.g. in
snd_pcm_xfern_frames_ioctl() or other places that refers to the
runtime attribute like runtime->channel; since the concurrent
hw_params may change the runtime->channel afterwards, this can result
in OOB access for the array allocated for a different size with the
former runtime->channels.
For avoiding such races, let's take the buffer access gate at those
ioctls and read/write ops from the beginning.
Reported-by: on Sim <tlatkdgus1@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/core/pcm_compat.c | 3 +++
sound/core/pcm_native.c | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index c54cb07304ad..0321d4241ec5 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -341,6 +341,9 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
+ SND_PCM_BUFFER_ACQUIRE(substream->runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
ch = substream->runtime->channels;
if (ch > 128)
return -EINVAL;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index f58d9be2ad44..6d29b2d10a5b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3424,6 +3424,9 @@ static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (runtime->channels > 128)
return -EINVAL;
if (put_user(0, &_xfern->result))
@@ -3663,6 +3666,9 @@ static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count,
runtime = substream->runtime;
if (snd_pcm_state_open_or_disconnected(substream))
return -EBADFD;
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (!frame_aligned(runtime, count))
return -EINVAL;
count = bytes_to_frames(runtime, count);
@@ -3687,6 +3693,9 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf,
runtime = substream->runtime;
if (snd_pcm_state_open_or_disconnected(substream))
return -EBADFD;
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (!frame_aligned(runtime, count))
return -EINVAL;
count = bytes_to_frames(runtime, count);
@@ -3715,6 +3724,9 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to)
return -EBADFD;
if (!user_backed_iter(to))
return -EINVAL;
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (to->nr_segs > 1024 || to->nr_segs != runtime->channels)
return -EINVAL;
if (!frame_aligned(runtime, iov->iov_len))
@@ -3754,6 +3766,9 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from)
return -EBADFD;
if (!user_backed_iter(from))
return -EINVAL;
+ SND_PCM_BUFFER_ACQUIRE(runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (from->nr_segs > 128 || from->nr_segs != runtime->channels ||
!frame_aligned(runtime, iov->iov_len))
return -EINVAL;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers
2026-11-18 13:55 [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers Takashi Iwai
2026-11-18 13:55 ` [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access Takashi Iwai
@ 2026-11-18 14:05 ` sashiko-bot
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-18 14:05 UTC (permalink / raw)
To: Takashi Iwai, linux-sound
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] ALSA: pcm: ABBA buffer_mutex deadlock in snd_pcm_action_group()
[1]
--
commit d0980124f5997cb84d7f6bc11cd87fe287a3f5a9
Author: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers
This commit introduces helper functions and auto-cleanup macros for the
runtime->buffer_accessing gate and replaces open-coded
atomic_inc_unless_negative() and atomic_dec() pairs with them.
> diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h
> index 4b134d435c24f..7762c89e0f9ff 100644
> --- a/sound/core/pcm_local.h
> +++ b/sound/core/pcm_local.h
> @@ -86,4 +86,30 @@ static inline void snd_pcm_dma_buffer_sync(struct snd_pcm_substream *substream,
> #define is_oss_stream(substream) false
> #endif
>
> +/*
> + * helpers for restricting hw_params / hw_refine changes
> + */
> +static inline int snd_pcm_buffer_access_get(struct snd_pcm_runtime *runtime)
> +{
> + if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
> + return -EBUSY;
> + return 0;
> +}
[Severity: High]
This problem wasn't introduced by this patch, but on the paired writer side
[1] can concurrent non-atomic group actions on two substreams in the
same linked group cause an ABBA deadlock on runtime->buffer_mutex, while
leaving runtime->buffer_accessing open on the other linked substreams?
sound/core/pcm_native.c:snd_pcm_action_nonatomic() {
guard(rwsem_read)(&snd_pcm_link_rwsem);
res = snd_pcm_buffer_access_lock(substream->runtime);
if (res < 0)
return res;
if (snd_pcm_stream_linked(substream))
res = snd_pcm_action_group(ops, substream, state, false);
...
}
sound/core/pcm_native.c:snd_pcm_action_group() {
snd_pcm_group_for_each_entry(s, substream) {
if (s != substream) {
if (!stream_lock)
mutex_lock_nested(&s->runtime->buffer_mutex, depth);
...
}
snd_pcm_action_nonatomic() only takes a read lock on snd_pcm_link_rwsem,
locks the caller's own runtime->buffer_mutex first via
snd_pcm_buffer_access_lock(), and then locks the remaining group members in
snd_pcm_action_group():
CPU0 CPU1
---- ----
down_read(&snd_pcm_link_rwsem)
down_read(&snd_pcm_link_rwsem)
lock(&A->runtime->buffer_mutex)
lock(&B->runtime->buffer_mutex)
lock(&B->runtime->buffer_mutex)
lock(&A->runtime->buffer_mutex)
*** DEADLOCK ***
CPU0: snd_pcm_prepare(A) -> snd_pcm_action_nonatomic() -> snd_pcm_action_group()
CPU1: snd_pcm_prepare(B) -> snd_pcm_action_nonatomic() -> snd_pcm_action_group()
Because both deadlocked tasks hold snd_pcm_link_rwsem for reading, any
later attempt to link, unlink, or close a linked PCM stream across the
system also hangs waiting for the write lock.
In addition, snd_pcm_action_group() only takes s->runtime->buffer_mutex on
the other linked substreams instead of calling
snd_pcm_buffer_access_lock(), leaving s->runtime->buffer_accessing unset on
those substreams during prepare or reset.
[1] https://sashiko.dev/#/bug/linux-a75ec171-40b4-4d70-8ffc-fddd01a5c9ca
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118135558.1928160-1-tiwai@suse.de?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access
2026-11-18 13:55 ` [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access Takashi Iwai
@ 2026-11-18 14:29 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-18 14:29 UTC (permalink / raw)
To: Takashi Iwai, linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: pcm: state check before SND_PCM_BUFFER_ACQUIRE() races
with hw_free
--
commit 307843a70c44558cff1055cb6881e2bf43f018d0
Author: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access
This commit acquires the PCM buffer access gate at the start of PCM read,
write, readv, writev, and xfern ioctl paths to prevent concurrent
hw_params or hw_free calls from changing runtime attributes mid-operation.
> diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
> index c54cb07304ad4..0321d4241ec5b 100644
> --- a/sound/core/pcm_compat.c
> +++ b/sound/core/pcm_compat.c
> @@ -341,6 +341,9 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
> if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
> return -EBADFD;
>
> + SND_PCM_BUFFER_ACQUIRE(substream->runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
> ch = substream->runtime->channels;
> if (ch > 128)
> return -EINVAL;
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 61bd4f4af81a4..22cf138981c30 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -3417,6 +3417,9 @@ static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
>
> if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
> return -EBADFD;
> + SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
> if (runtime->channels > 128)
> return -EINVAL;
> if (put_user(0, &_xfern->result))
> @@ -3656,6 +3659,9 @@ static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count,
> runtime = substream->runtime;
> if (snd_pcm_state_open_or_disconnected(substream))
> return -EBADFD;
> + SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
> if (!frame_aligned(runtime, count))
> return -EINVAL;
> count = bytes_to_frames(runtime, count);
> @@ -3680,6 +3686,9 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf,
> runtime = substream->runtime;
> if (snd_pcm_state_open_or_disconnected(substream))
> return -EBADFD;
> + SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
> if (!frame_aligned(runtime, count))
> return -EINVAL;
> count = bytes_to_frames(runtime, count);
> @@ -3708,6 +3717,9 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to)
> return -EBADFD;
> if (!user_backed_iter(to))
> return -EINVAL;
> + SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
> if (to->nr_segs > 1024 || to->nr_segs != runtime->channels)
> return -EINVAL;
> if (!frame_aligned(runtime, iov->iov_len))
> @@ -3747,6 +3759,9 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from)
> return -EBADFD;
> if (!user_backed_iter(from))
> return -EINVAL;
> + SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> + if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> + return -EBUSY;
[Severity: Medium]
Can snd_pcm_hw_free() run between the state check and
SND_PCM_BUFFER_ACQUIRE() in these six paths?
CPU0 CPU1
snd_pcm_write()
snd_pcm_state_open_or_disconnected()
(passes in STATE_SETUP)
snd_pcm_hw_free()
snd_pcm_buffer_access_lock(runtime)
do_hw_free()
runtime->dma_area = NULL
runtime->state = SNDRV_PCM_STATE_OPEN
snd_pcm_buffer_access_unlock(runtime)
SND_PCM_BUFFER_ACQUIRE(runtime, lock)
snd_pcm_lib_write()
__snd_pcm_lib_xfer()
pcm_sanity_check() <-- hits snd_BUG_ON()
Because pcm_sanity_check() evaluates snd_BUG_ON(!substream->ops->copy &&
!runtime->dma_area) before checking whether runtime->state is
SNDRV_PCM_STATE_OPEN:
sound/core/pcm_lib.c:pcm_sanity_check() {
...
if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area))
return -EINVAL;
if (runtime->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
...
}
losing this race triggers a kernel warning (when CONFIG_SND_DEBUG is
enabled) and returns -EINVAL instead of -EBADFD. Acquiring
SND_PCM_BUFFER_ACQUIRE() before checking the substream state, as
snd_pcm_mmap_data() does, would prevent transitions into
SNDRV_PCM_STATE_OPEN after the check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118135558.1928160-1-tiwai@suse.de?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 14:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:55 [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers Takashi Iwai
2026-11-18 13:55 ` [PATCH 2/2] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access Takashi Iwai
2026-11-18 14:29 ` sashiko-bot
2026-11-18 14:05 ` [PATCH 1/2] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox