Commit c18c4966 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: pcm: Unify snd_pcm_delay() and snd_pcm_hwsync()



Both snd_pcm_delay() and snd_pcm_hwsync() do the almost same thing.
The only difference is that the former calculate the delay, so unify
them as a code cleanup, and treat NULL delay argument only for hwsync
operation.

Also, the patch does a slight code refactoring in snd_pcm_delay().
The initialization of the delay value is done in the caller side now.

Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20211014145323.26506-1-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent b96681bd
Loading
Loading
Loading
Loading
+8 −16
Original line number Diff line number Diff line
@@ -2932,30 +2932,22 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
	return ret;
}

static int snd_pcm_hwsync(struct snd_pcm_substream *substream)
static int snd_pcm_delay(struct snd_pcm_substream *substream,
			 snd_pcm_sframes_t *delay)
{
	int err;

	snd_pcm_stream_lock_irq(substream);
	err = do_pcm_hwsync(substream);
	if (delay && !err)
		*delay = snd_pcm_calc_delay(substream);
	snd_pcm_stream_unlock_irq(substream);
	return err;
}
		
static int snd_pcm_delay(struct snd_pcm_substream *substream,
			 snd_pcm_sframes_t *delay)
static inline int snd_pcm_hwsync(struct snd_pcm_substream *substream)
{
	int err;
	snd_pcm_sframes_t n = 0;

	snd_pcm_stream_lock_irq(substream);
	err = do_pcm_hwsync(substream);
	if (!err)
		n = snd_pcm_calc_delay(substream);
	snd_pcm_stream_unlock_irq(substream);
	if (!err)
		*delay = n;
	return err;
	return snd_pcm_delay(substream, NULL);
}

static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
@@ -3275,7 +3267,7 @@ static int snd_pcm_common_ioctl(struct file *file,
		return snd_pcm_hwsync(substream);
	case SNDRV_PCM_IOCTL_DELAY:
	{
		snd_pcm_sframes_t delay;
		snd_pcm_sframes_t delay = 0;
		snd_pcm_sframes_t __user *res = arg;
		int err;