ALSA: usb-audio: Move autoresume call at the end of open

... so that we can avoid the extra goto lines.
Also beautify the code to follow the standard codex.

No functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2018-05-27 15:09:15 +02:00
Родитель 6fddc79787
Коммит e92be8146c
1 изменённых файлов: 36 добавлений и 35 удалений

Просмотреть файл

@ -76,10 +76,9 @@ snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
*/ */
static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
{ {
struct snd_usb_substream *subs; struct snd_usb_substream *subs = substream->runtime->private_data;
unsigned int hwptr_done; unsigned int hwptr_done;
subs = (struct snd_usb_substream *)substream->runtime->private_data;
if (atomic_read(&subs->stream->chip->shutdown)) if (atomic_read(&subs->stream->chip->shutdown))
return SNDRV_PCM_POS_XRUN; return SNDRV_PCM_POS_XRUN;
spin_lock(&subs->lock); spin_lock(&subs->lock);
@ -1172,9 +1171,6 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
pt = 125 * (1 << fp->datainterval); pt = 125 * (1 << fp->datainterval);
ptmin = min(ptmin, pt); ptmin = min(ptmin, pt);
} }
err = snd_usb_autoresume(subs->stream->chip);
if (err < 0)
return err;
param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME; param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME;
if (subs->speed == USB_SPEED_FULL) if (subs->speed == USB_SPEED_FULL)
@ -1183,30 +1179,37 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
if (ptmin == 1000) if (ptmin == 1000)
/* if period time doesn't go below 1 ms, no rules needed */ /* if period time doesn't go below 1 ms, no rules needed */
param_period_time_if_needed = -1; param_period_time_if_needed = -1;
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
ptmin, UINT_MAX);
if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, err = snd_pcm_hw_constraint_minmax(runtime,
hw_rule_rate, subs, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
SNDRV_PCM_HW_PARAM_FORMAT, ptmin, UINT_MAX);
SNDRV_PCM_HW_PARAM_CHANNELS, if (err < 0)
param_period_time_if_needed, return err;
-1)) < 0)
goto rep_err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, hw_rule_rate, subs,
hw_rule_channels, subs, SNDRV_PCM_HW_PARAM_FORMAT,
SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
SNDRV_PCM_HW_PARAM_RATE, param_period_time_if_needed,
param_period_time_if_needed, -1);
-1)) < 0) if (err < 0)
goto rep_err; return err;
if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
hw_rule_format, subs, hw_rule_channels, subs,
SNDRV_PCM_HW_PARAM_RATE, SNDRV_PCM_HW_PARAM_FORMAT,
SNDRV_PCM_HW_PARAM_CHANNELS, SNDRV_PCM_HW_PARAM_RATE,
param_period_time_if_needed, param_period_time_if_needed,
-1)) < 0) -1);
goto rep_err; if (err < 0)
return err;
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
hw_rule_format, subs,
SNDRV_PCM_HW_PARAM_RATE,
SNDRV_PCM_HW_PARAM_CHANNELS,
param_period_time_if_needed,
-1);
if (err < 0)
return err;
if (param_period_time_if_needed >= 0) { if (param_period_time_if_needed >= 0) {
err = snd_pcm_hw_rule_add(runtime, 0, err = snd_pcm_hw_rule_add(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
@ -1216,15 +1219,13 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
SNDRV_PCM_HW_PARAM_RATE, SNDRV_PCM_HW_PARAM_RATE,
-1); -1);
if (err < 0) if (err < 0)
goto rep_err; return err;
} }
if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0) err = snd_usb_pcm_check_knot(runtime, subs);
goto rep_err; if (err < 0)
return 0; return err;
rep_err: return snd_usb_autoresume(subs->stream->chip);
snd_usb_autosuspend(subs->stream->chip);
return err;
} }
static int snd_usb_pcm_open(struct snd_pcm_substream *substream) static int snd_usb_pcm_open(struct snd_pcm_substream *substream)