Skip to content

Commit ad876c8

Browse files
committed
ALSA: pcm: Minor refactoring in snd_pcm_attach_substream()
No functional changes at all. Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 0c8d948 commit ad876c8

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

sound/core/pcm.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
919919

920920
if (snd_BUG_ON(!pcm || !rsubstream))
921921
return -ENXIO;
922+
if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK &&
923+
stream != SNDRV_PCM_STREAM_CAPTURE))
924+
return -EINVAL;
922925
*rsubstream = NULL;
923926
pstr = &pcm->streams[stream];
924927
if (pstr->substream == NULL || pstr->substream_count == 0)
@@ -927,25 +930,14 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
927930
card = pcm->card;
928931
prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM);
929932

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;
945940
}
946-
break;
947-
default:
948-
return -EINVAL;
949941
}
950942

951943
if (file->f_flags & O_APPEND) {
@@ -968,15 +960,12 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
968960
return 0;
969961
}
970962

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))
978967
break;
979-
__ok:
968+
}
980969
if (substream == NULL)
981970
return -EAGAIN;
982971

0 commit comments

Comments
 (0)