Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC47FC433EF for ; Thu, 14 Oct 2021 14:54:27 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF1BB610D1 for ; Thu, 14 Oct 2021 14:54:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EF1BB610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C9F5682C; Thu, 14 Oct 2021 16:53:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C9F5682C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1634223264; bh=mrGQ1FueGh348kN1BPYD+wjwk05DbiIX8BY/7p4RCgI=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=cfjiP9mSGJwgX6zJzZTwcU4F15carsL2riuSaut0kyGa++dDZpFXzdwGUKR4GU00f z/36Qg4QtZkosFwRB9IKxsR+34zeGz15SuMhyQG6KOonqe0/nUUMQugN2JZNaAz5OT 7rylkan4rFSBTd5VYa0ZvFCpxWMMJ4Djv+Ppz640= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4F4B5F801D5; Thu, 14 Oct 2021 16:53:34 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 07DC4F80212; Thu, 14 Oct 2021 16:53:33 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DEA41F801D5 for ; Thu, 14 Oct 2021 16:53:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DEA41F801D5 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Xk+WXdCq"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZjcAZnU/" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B1E4821A88 for ; Thu, 14 Oct 2021 14:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634223204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=tKnPGt352QjWovmOa8bLCRx8xrhGVxrO3cSS8544cmA=; b=Xk+WXdCqBc1sZLEDCs6UPUekNjfh2ZwlEF/A5gcX/hXfelJb7vPPk9NHRE9CdL2vsAJfC2 B9GcYfqIt+emOf6JUNoYqXTtic+4B5m6JWeB1ZstooeAqSzkhhuVxr2pNZQGgJ4xh9A7/1 XAqLqioEQ762WfT6xXz9ZTfCT2I3lv4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634223204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=tKnPGt352QjWovmOa8bLCRx8xrhGVxrO3cSS8544cmA=; b=ZjcAZnU/7fAQMjD9U+zgb7nmyljjljRTjDzSyaQt8okE/CjshpnHpBSFDXj9JG7EIazMCE +sU+pHRuLpJu9qCw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id A1738A3B85; Thu, 14 Oct 2021 14:53:24 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH] ALSA: pcm: Unify snd_pcm_delay() and snd_pcm_hwsync() Date: Thu, 14 Oct 2021 16:53:23 +0200 Message-Id: <20211014145323.26506-1-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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. Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 46c643db18eb..627b201b6084 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2932,32 +2932,24 @@ 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) -{ - int err; - - snd_pcm_stream_lock_irq(substream); - err = do_pcm_hwsync(substream); - snd_pcm_stream_unlock_irq(substream); - return err; -} - static int snd_pcm_delay(struct snd_pcm_substream *substream, snd_pcm_sframes_t *delay) { 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); + if (delay && !err) + *delay = snd_pcm_calc_delay(substream); snd_pcm_stream_unlock_irq(substream); - if (!err) - *delay = n; return err; } +static inline int snd_pcm_hwsync(struct snd_pcm_substream *substream) +{ + return snd_pcm_delay(substream, NULL); +} + static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr __user *_sync_ptr) { @@ -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; -- 2.31.1