@@ -919,6 +919,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
919
919
920
920
if (snd_BUG_ON (!pcm || !rsubstream ))
921
921
return - ENXIO ;
922
+ if (snd_BUG_ON (stream != SNDRV_PCM_STREAM_PLAYBACK &&
923
+ stream != SNDRV_PCM_STREAM_CAPTURE ))
924
+ return - EINVAL ;
922
925
* rsubstream = NULL ;
923
926
pstr = & pcm -> streams [stream ];
924
927
if (pstr -> substream == NULL || pstr -> substream_count == 0 )
@@ -927,25 +930,14 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
927
930
card = pcm -> card ;
928
931
prefer_subdevice = snd_ctl_get_preferred_subdevice (card , SND_CTL_SUBDEV_PCM );
929
932
930
- switch (stream ) {
931
- case SNDRV_PCM_STREAM_PLAYBACK :
932
- if (pcm -> info_flags & SNDRV_PCM_INFO_HALF_DUPLEX ) {
933
- for (substream = pcm -> streams [SNDRV_PCM_STREAM_CAPTURE ].substream ; substream ; substream = substream -> next ) {
934
- if (SUBSTREAM_BUSY (substream ))
935
- return - EAGAIN ;
936
- }
937
- }
938
- break ;
939
- case SNDRV_PCM_STREAM_CAPTURE :
940
- if (pcm -> info_flags & SNDRV_PCM_INFO_HALF_DUPLEX ) {
941
- for (substream = pcm -> streams [SNDRV_PCM_STREAM_PLAYBACK ].substream ; substream ; substream = substream -> next ) {
942
- if (SUBSTREAM_BUSY (substream ))
943
- return - EAGAIN ;
944
- }
933
+ if (pcm -> info_flags & SNDRV_PCM_INFO_HALF_DUPLEX ) {
934
+ int opposite = !stream ;
935
+
936
+ for (substream = pcm -> streams [opposite ].substream ; substream ;
937
+ substream = substream -> next ) {
938
+ if (SUBSTREAM_BUSY (substream ))
939
+ return - EAGAIN ;
945
940
}
946
- break ;
947
- default :
948
- return - EINVAL ;
949
941
}
950
942
951
943
if (file -> f_flags & O_APPEND ) {
@@ -968,15 +960,12 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
968
960
return 0 ;
969
961
}
970
962
971
- if (prefer_subdevice >= 0 ) {
972
- for (substream = pstr -> substream ; substream ; substream = substream -> next )
973
- if (!SUBSTREAM_BUSY (substream ) && substream -> number == prefer_subdevice )
974
- goto __ok ;
975
- }
976
- for (substream = pstr -> substream ; substream ; substream = substream -> next )
977
- if (!SUBSTREAM_BUSY (substream ))
963
+ for (substream = pstr -> substream ; substream ; substream = substream -> next ) {
964
+ if (!SUBSTREAM_BUSY (substream ) &&
965
+ (prefer_subdevice == -1 ||
966
+ substream -> number == prefer_subdevice ))
978
967
break ;
979
- __ok :
968
+ }
980
969
if (substream == NULL )
981
970
return - EAGAIN ;
982
971
0 commit comments