Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3523105rwo; Fri, 4 Aug 2023 06:17:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvA1Nx1lEvLy6iqUpK0AuUUYEswp1xy2KwxtDExfTGxkIQ7l12W6NaqkLJIGwBtuSV5JKO X-Received: by 2002:a05:6a20:42a0:b0:13f:7ffe:855e with SMTP id o32-20020a056a2042a000b0013f7ffe855emr1756241pzj.45.1691155056718; Fri, 04 Aug 2023 06:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691155056; cv=none; d=google.com; s=arc-20160816; b=feJ3pCqdjpJdVcJtoswDWH1xjViXNb130igc6pfJDenNZJW25ilD/+wYWJZc28T54x N91WaiFATIM7W9SDQ9FVdDesJWztVhIgecjCIN6gZNQxyOw59WmVTnxqEWzU3AWU1eRd xLOuCAuhBnTkHF03Tbi9TBFYolTcTC4Px/z2fgOotxLDiTYhomOWNHv6s6yEtHlB5hA4 tjWNJ/SRsCscC75rz9Jff8G0b1WXzpqmEfMngXlwT1Me3F6sYpypxgjzP94NHRzaPgHk nYC+v5J4+N5/p9aIhQqsVwJV/HmUgskPmeuKs6QOPAkwuLilc/i2PAbK3VRpbhNQ8BU/ IN1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=d+RCvu64k2tkk7w/weX6gTH8M7RTUJSIekejqVZef5Q=; fh=S4URyNAad87Yxi2/a+HeVWcF+2cFa+H0Sd7mMFfPnYk=; b=brO4XNenYlUWJsR1HuDhq37WAP5m+PByAhnOeKOVmGmhEx0aO6ZrwpxyIGF5CMaAqE GEExE9AhFsZU7rgM3o3KmgbU358R6wb/Zv1YjEkOiPd5nJckWH0lXkcMJjLbOL+w1+8S vZPod/hFpJ+zHPKKA+h37uie5U+ghky+UNw+K478GJ8vrTdz/7m/Xqi+93wc7Cbl807z ZtywK11ba0N72t6pIfUWGM3Ud9PKzEK/+cuNE8xvjDxu1/WNjxpLG2z8y0exWjPWeX6s kGlBRToOIHqQIxkrIdZTnPiaAxNJW2blnp58nFWoTuf78seOZfCzw7leBIXI9NExz7Ji 5S0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="NLEQYOJ/"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 16-20020a630a10000000b0055c8f4a56d5si1698683pgk.600.2023.08.04.06.17.24; Fri, 04 Aug 2023 06:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="NLEQYOJ/"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbjHDKuF (ORCPT + 99 others); Fri, 4 Aug 2023 06:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjHDKtK (ORCPT ); Fri, 4 Aug 2023 06:49:10 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B071A4C3E for ; Fri, 4 Aug 2023 03:47:44 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F0F2421860; Fri, 4 Aug 2023 10:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691146011; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=d+RCvu64k2tkk7w/weX6gTH8M7RTUJSIekejqVZef5Q=; b=NLEQYOJ/t8VyF9gY23NkCvXsqhwrRWkh1Pv18sXNYlDkvOwxGPutG2CDJy2u7FmLwqiKE8 4c1T0Rt1Av5EsrNY0qNqdhTJu0tVJ5CCC7V4mFopq+7YiuX2kf0To8+g2hgSWSDWd28sS7 qBJw14vRQziH2MJlEGOsuMdBSxOM6po= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691146011; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=d+RCvu64k2tkk7w/weX6gTH8M7RTUJSIekejqVZef5Q=; b=EqO4X27A48oKleqeso9rMvDzRqIJibaLjF0M1+htAgddFEP7VYz/kbbEruDJTBq+54OMPP /iP1awYKRHGtqaCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C3F98133B5; Fri, 4 Aug 2023 10:46:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DsKbLhvXzGRUPgAAMHmgww (envelope-from ); Fri, 04 Aug 2023 10:46:51 +0000 Date: Fri, 04 Aug 2023 12:46:51 +0200 Message-ID: <87msz79jac.wl-tiwai@suse.de> From: Takashi Iwai To: Ivan Orlov Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: pcmtest: Move buffer iterator initialization to prepare callback In-Reply-To: <20230803152824.7531-1-ivan.orlov0322@gmail.com> References: <20230803152824.7531-1-ivan.orlov0322@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,T_SPF_TEMPERROR,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 03 Aug 2023 17:28:24 +0200, Ivan Orlov wrote: > > Trigger callback is not the best place for buffer iterator > initialization, so move it out to the prepare callback, where it > have to be. > > Minor enhancement: remove redundant definitions and blank line. A blank line removal is OK, but other changes are too much to fold into. Please split. thanks, Takashi > > Signed-off-by: Ivan Orlov > --- > sound/drivers/pcmtest.c | 41 +++++++++++++++++++---------------------- > 1 file changed, 19 insertions(+), 22 deletions(-) > > diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c > index 08e14b5eb772..7f170429eb8f 100644 > --- a/sound/drivers/pcmtest.c > +++ b/sound/drivers/pcmtest.c > @@ -41,8 +41,6 @@ > #include > #include > > -#define DEVNAME "pcmtestd" > -#define CARD_NAME "pcm-test-card" > #define TIMER_PER_SEC 5 > #define TIMER_INTERVAL (HZ / TIMER_PER_SEC) > #define DELAY_JIFFIES HZ > @@ -74,11 +72,11 @@ static u8 ioctl_reset_test; > static struct dentry *driver_debug_dir; > > module_param(index, int, 0444); > -MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard"); > +MODULE_PARM_DESC(index, "Index value for pcmtest soundcard"); > module_param(id, charp, 0444); > -MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard"); > +MODULE_PARM_DESC(id, "ID string for pcmtest soundcard"); > module_param(enable, bool, 0444); > -MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); > +MODULE_PARM_DESC(enable, "Enable pcmtest soundcard."); > module_param(fill_mode, short, 0600); > MODULE_PARM_DESC(fill_mode, "Buffer fill mode: rand(0) or pattern(1)"); > module_param(inject_delay, int, 0600); > @@ -92,7 +90,6 @@ MODULE_PARM_DESC(inject_trigger_err, "Inject EINVAL error in the 'trigger' callb > module_param(inject_open_err, bool, 0600); > MODULE_PARM_DESC(inject_open_err, "Inject EBUSY error in the 'open' callback"); > > - > struct pcmtst { > struct snd_pcm *pcm; > struct snd_card *card; > @@ -405,25 +402,9 @@ static int snd_pcmtst_pcm_close(struct snd_pcm_substream *substream) > > static int snd_pcmtst_pcm_trigger(struct snd_pcm_substream *substream, int cmd) > { > - struct snd_pcm_runtime *runtime = substream->runtime; > - struct pcmtst_buf_iter *v_iter = runtime->private_data; > - > if (inject_trigger_err) > return -EINVAL; > > - v_iter->sample_bytes = runtime->sample_bits / 8; > - v_iter->period_bytes = frames_to_bytes(runtime, runtime->period_size); > - if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED || > - runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED) { > - v_iter->chan_block = runtime->dma_bytes / runtime->channels; > - v_iter->interleaved = false; > - } else { > - v_iter->interleaved = true; > - } > - // We want to record RATE * ch_cnt samples per sec, it is rate * sample_bytes * ch_cnt bytes > - v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC; > - v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels; > - > return 0; > } > > @@ -454,8 +435,24 @@ static void pcmtst_pdev_release(struct device *dev) > > static int snd_pcmtst_pcm_prepare(struct snd_pcm_substream *substream) > { > + struct snd_pcm_runtime *runtime = substream->runtime; > + struct pcmtst_buf_iter *v_iter = runtime->private_data; > + > if (inject_prepare_err) > return -EINVAL; > + > + v_iter->sample_bytes = samples_to_bytes(runtime, 1); > + v_iter->period_bytes = snd_pcm_lib_period_bytes(substream); > + v_iter->interleaved = true; > + if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED || > + runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED) { > + v_iter->chan_block = snd_pcm_lib_buffer_bytes(substream) / runtime->channels; > + v_iter->interleaved = false; > + } > + // We want to record RATE * ch_cnt samples per sec, it is rate * sample_bytes * ch_cnt bytes > + v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC; > + v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels; > + > return 0; > } > > -- > 2.34.1 >