@@ -369,6 +369,14 @@ static int period_to_usecs(struct snd_pcm_runtime *runtime)
369369 return usecs ;
370370}
371371
372+ static void snd_pcm_set_state (struct snd_pcm_substream * substream , int state )
373+ {
374+ snd_pcm_stream_lock_irq (substream );
375+ if (substream -> runtime -> status -> state != SNDRV_PCM_STATE_DISCONNECTED )
376+ substream -> runtime -> status -> state = state ;
377+ snd_pcm_stream_unlock_irq (substream );
378+ }
379+
372380static int snd_pcm_hw_params (struct snd_pcm_substream * substream ,
373381 struct snd_pcm_hw_params * params )
374382{
@@ -452,7 +460,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
452460 runtime -> boundary *= 2 ;
453461
454462 snd_pcm_timer_resolution_change (substream );
455- runtime -> status -> state = SNDRV_PCM_STATE_SETUP ;
463+ snd_pcm_set_state ( substream , SNDRV_PCM_STATE_SETUP ) ;
456464
457465 if (pm_qos_request_active (& substream -> latency_pm_qos_req ))
458466 pm_qos_remove_request (& substream -> latency_pm_qos_req );
@@ -464,7 +472,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
464472 /* hardware might be unusable from this time,
465473 so we force application to retry to set
466474 the correct hardware parameter settings */
467- runtime -> status -> state = SNDRV_PCM_STATE_OPEN ;
475+ snd_pcm_set_state ( substream , SNDRV_PCM_STATE_OPEN ) ;
468476 if (substream -> ops -> hw_free != NULL )
469477 substream -> ops -> hw_free (substream );
470478 return err ;
@@ -512,7 +520,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
512520 return - EBADFD ;
513521 if (substream -> ops -> hw_free )
514522 result = substream -> ops -> hw_free (substream );
515- runtime -> status -> state = SNDRV_PCM_STATE_OPEN ;
523+ snd_pcm_set_state ( substream , SNDRV_PCM_STATE_OPEN ) ;
516524 pm_qos_remove_request (& substream -> latency_pm_qos_req );
517525 return result ;
518526}
@@ -1320,7 +1328,7 @@ static void snd_pcm_post_prepare(struct snd_pcm_substream *substream, int state)
13201328{
13211329 struct snd_pcm_runtime * runtime = substream -> runtime ;
13221330 runtime -> control -> appl_ptr = runtime -> status -> hw_ptr ;
1323- runtime -> status -> state = SNDRV_PCM_STATE_PREPARED ;
1331+ snd_pcm_set_state ( substream , SNDRV_PCM_STATE_PREPARED ) ;
13241332}
13251333
13261334static struct action_ops snd_pcm_action_prepare = {
0 commit comments