Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcm: use snd_pcm_get_state() in remaining ioctl checks
@ 2026-05-07  1:19 Cen Zhang
  2026-05-07 10:55 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Cen Zhang @ 2026-05-07  1:19 UTC (permalink / raw)
  To: perex, tiwai; +Cc: gregkh, linux-sound, linux-kernel, baijiaju1990, Cen Zhang

The recent OSS runtime->state locking cleanup converted the OSS I/O
paths to use snd_pcm_get_state(), but a few ioctl-side checks in
pcm_native.c still sample runtime->state directly: the prepare
pre-checks, the early drain open-state check, and the common
snd_pcm_kernel_ioctl() disconnected check.

Use snd_pcm_get_state() for those remaining samples. In
snd_pcm_pre_prepare(), keep a single state snapshot and reuse it for
both the OPEN/DISCONNECTED check and the running-state test.

Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
 sound/core/pcm_native.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index a541bb2..50da38b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1973,13 +1973,15 @@ static int snd_pcm_reset(struct snd_pcm_substream *substream)
 static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream,
 			       snd_pcm_state_t state)
 {
-	struct snd_pcm_runtime *runtime = substream->runtime;
+	snd_pcm_state_t cur_state = snd_pcm_get_state(substream);
 	int f_flags = (__force int)state;
 
-	if (runtime->state == SNDRV_PCM_STATE_OPEN ||
-	    runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
+	if (cur_state == SNDRV_PCM_STATE_OPEN ||
+	    cur_state == SNDRV_PCM_STATE_DISCONNECTED)
 		return -EBADFD;
-	if (snd_pcm_running(substream))
+	if (cur_state == SNDRV_PCM_STATE_RUNNING ||
+	    (cur_state == SNDRV_PCM_STATE_DRAINING &&
+	     substream->stream == SNDRV_PCM_STREAM_PLAYBACK))
 		return -EBUSY;
 	substream->f_flags = f_flags;
 	return 0;
@@ -2139,7 +2141,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
 	card = substream->pcm->card;
 	runtime = substream->runtime;
 
-	if (runtime->state == SNDRV_PCM_STATE_OPEN)
+	if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
 
 	if (file) {
@@ -3524,7 +3526,7 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
 	snd_pcm_uframes_t *frames = arg;
 	snd_pcm_sframes_t result;
 	
-	if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
+	if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_DISCONNECTED)
 		return -EBADFD;
 
 	switch (cmd) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: pcm: use snd_pcm_get_state() in remaining ioctl checks
  2026-05-07  1:19 [PATCH] ALSA: pcm: use snd_pcm_get_state() in remaining ioctl checks Cen Zhang
@ 2026-05-07 10:55 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-05-07 10:55 UTC (permalink / raw)
  To: Cen Zhang; +Cc: perex, tiwai, gregkh, linux-sound, linux-kernel, baijiaju1990

On Thu, 07 May 2026 03:19:44 +0200,
Cen Zhang wrote:
> 
> The recent OSS runtime->state locking cleanup converted the OSS I/O
> paths to use snd_pcm_get_state(), but a few ioctl-side checks in
> pcm_native.c still sample runtime->state directly: the prepare
> pre-checks, the early drain open-state check, and the common
> snd_pcm_kernel_ioctl() disconnected check.
> 
> Use snd_pcm_get_state() for those remaining samples. In
> snd_pcm_pre_prepare(), keep a single state snapshot and reuse it for
> both the OPEN/DISCONNECTED check and the running-state test.
> 
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-07 10:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07  1:19 [PATCH] ALSA: pcm: use snd_pcm_get_state() in remaining ioctl checks Cen Zhang
2026-05-07 10:55 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox