Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2422036rwo; Thu, 3 Aug 2023 09:07:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlF02a4sb9BmgLHLbnQ0xpC1+GptbZZJl2x8dWsxEADfKxahNmVBN7R5oXcG5ARkEeI5ImG/ X-Received: by 2002:a05:6830:1d7c:b0:6b8:73df:da64 with SMTP id l28-20020a0568301d7c00b006b873dfda64mr17982305oti.7.1691078864385; Thu, 03 Aug 2023 09:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691078864; cv=none; d=google.com; s=arc-20160816; b=PQsmKf/CDIcj2up5E7GUHKlktHr3zOU4JgtgJuTqf99/481rrXfZiu5h1+wKw8/nWA HEIAtnuKTihIjivhUsrgKM0Z8zIFHU1+87IOMqm7DulTzoAeVTOPgt6W7VwPiT7g4CvV +pN/YAKivCm950dn1lxvLjbg9y1AO6+ur7QtFdOjpu5JAthhzTh79yl0d1qW7oFEZ/rG RCi0G3UwSJ/T4z4WIMHx5K+gjRX0yheKA/1HgdD2GPcn9lWs/RekuRm+DSqZ0pY5bUFd 6vSpf6JtIHR7B0IhkHa8ko1bduDbLWwV+aMyY1J4IrX8HQF35Ojgnbtki+KjL28Nrx7x NUyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fv1LCJk+f7RVF8k/ixLAQ0iB0AzU0l/9VwQdVFGXgR8=; fh=Z7A+1BnnO2Wy4WuR/H+yDPDd4ZAQG/u3CNanu81cjOw=; b=hW+HGMhOQHk8q/SOc8YnVqmgOlzI8Zl923zgAVuMrF7sAocNxhADChBvzVFjvX+XiM RHRStQ2ndoZ6Ym7SacgRP+1IM9uS/kpocEEB7ZCpVvWxIVFuVdatkDiZe+TC9FrevOI1 Lv8UoYtyOc9QqHzaHyCeWidtHEflDrEv+q4Zx50hzyZuMKJm31ZYyClkUYTqlLlrxEpX GntOMFv76JekRuY7cBpauyLxENXuJMYUrTxoXci2j4ILWb1mMGUrWQcxAwRLQsDf8hv1 IkU4XelA9LyK4TcVO22VkAyPJ1zLBH9A/G71d8/1iWZ1k4Oj6YR6l3DAFxjJ92l7tjFz PtWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="MnDCwmQ/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a632302000000b00564274c2947si82234pgj.637.2023.08.03.09.07.26; Thu, 03 Aug 2023 09:07:44 -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=@gmail.com header.s=20221208 header.b="MnDCwmQ/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237121AbjHCP2q (ORCPT + 99 others); Thu, 3 Aug 2023 11:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237117AbjHCP2o (ORCPT ); Thu, 3 Aug 2023 11:28:44 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C16BE6E for ; Thu, 3 Aug 2023 08:28:43 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b9e8d7c6cbso1834361fa.1 for ; Thu, 03 Aug 2023 08:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691076521; x=1691681321; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fv1LCJk+f7RVF8k/ixLAQ0iB0AzU0l/9VwQdVFGXgR8=; b=MnDCwmQ/dByCs/tojD4nKtp/RjoX793JDmx/Fzbo1WQVxl0M1xtoQsEIM/VaV9a+BD r1XxSYLb0h7ULkYpFKtX93xDcs1B11R9AZH+MW+mBm+T9RCjHse3ImhTqOzDu1mG4WNz f6bkEZ8kXrWmG7t22bXhWkgN+ZwyiVat7+cupd/GeGWOkAo2+cO0s0ePNEV7Upz7CROP koP+HjuaDobs81LngADNHkHYgO02MRjnamX0P22G1i3HH+ObcNlPVr/po4UVplDm5MQv Gg3wVklxRDpBUEc564EKnogGcbmGUkpMgRVg1PtmXFKZ0HSsyzqjmSk+J4zQannNiuk0 0TKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691076521; x=1691681321; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fv1LCJk+f7RVF8k/ixLAQ0iB0AzU0l/9VwQdVFGXgR8=; b=Amu6Lk6iUxBNsA2ewwivIP0sE3YWpwjtQPIB3e48Kj/lU+RCpDEs+qkW0zGI/zkZEO IrlIR/PBwo6IAlmajM7zfLeasPCBzuiFJvJZWPXwZiU3f1d9GOfblohLXmegFpyCCfao UiOtzk/TxN+KUHymU1xrFgyFa3EEzYdkSSDEANQE2ZhwLWgxzSDRbV8WSRIblzgcdH/O bpl9LdIQZdekdZcQKQg6hrF3daB8UvTpOnu5GYz7TIkt5aJK+BnvVBeQUUHsT239LloP KjR86Si7esTvwgTXrLwQAomZKXsN5viPz7+Xq4H5ul5tCsUkLKgBbh1phdqTltcUtbX1 odZg== X-Gm-Message-State: ABy/qLaNW/XxfxwiLH3aSXIDK5Hc3th2KHwytPnWhwXPHTJVVghPtdia rfQNW8RrVLYZnLih7LSWijXSXGiddtTloEbF X-Received: by 2002:a05:651c:31a:b0:2b7:34c0:a03a with SMTP id a26-20020a05651c031a00b002b734c0a03amr9667022ljp.3.1691076520920; Thu, 03 Aug 2023 08:28:40 -0700 (PDT) Received: from ivan-HLYL-WXX9.. ([141.136.93.39]) by smtp.gmail.com with ESMTPSA id e3-20020a17090681c300b00997d76981e0sm10617559ejx.208.2023.08.03.08.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 08:28:40 -0700 (PDT) From: Ivan Orlov To: perex@perex.cz, tiwai@suse.com Cc: Ivan Orlov , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ALSA: pcmtest: Move buffer iterator initialization to prepare callback Date: Thu, 3 Aug 2023 19:28:24 +0400 Message-Id: <20230803152824.7531-1-ivan.orlov0322@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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. 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