Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp345764pxb; Thu, 25 Feb 2021 04:16:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGt/5CdULpsAaGcpuLaXV/89xjYZjYr0s6cRwnJ0C7kaUXrJR8CWTyMbBHosIq+X/Kg6DM X-Received: by 2002:a17:906:a1c2:: with SMTP id bx2mr2452015ejb.138.1614255409315; Thu, 25 Feb 2021 04:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614255409; cv=none; d=google.com; s=arc-20160816; b=SgL64UoMmn0q0cjjau18XusPUr7WfkzMxCWU/342Zbd6ebH3Kl2Vr+9P+2/5nvyDpP arKmDZ37HCTeKrH15xp4QA6hau8JxJOFaX5NVOONRu3XXDUzbVG8AXwySBR3kzNFxKur 2MElnHVcWbz8zbX6bdycPBMUoukNoYyq88BYvaCo3x8vaDLuTNw7gLt1PAow9FAFLmv2 aOsgd0PXoCJGUnsVYdSKYCDrPjmevxxnSNVMaX+iPfXcs5cLGmOL4K+vf385M4s1sitE U09HYYYZUEDiXUHyWgbvuuaJBxL+M9Qw7C0LjD/rj8WRBHuJZFExW/GjQRfIMfThxSpq g3vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:date:message-id:from:references:cc:to :subject:dkim-signature; bh=tsvHDlnqSzD6yifbwIkb7LBXJuGwyXOyWV+yVzi4100=; b=ivk9DB8uFDzTFNofua8aEVLmkyhm6jglnmc6gH0fvJ7Xk2+iSPdWUDEz3gku9qL/aE xP2Ti308j886xkXpxifpuUCAVDQFDMho9wK2DnQ2VMbEJ5YvWgoiRsLkMlsZGT6vHVb6 t9c3sDyaFfmnNktLm+z2XfRR2iqNqRPyA4NTQjX42kVtKabQbPpgLKgLj6pGey11VkAv 3Eu3dioccU3ht1xFSzhZvOBlQDRjyCyiNAIAue/nw8zbm0dUegWCfB7rq5679NfnJO2l Z+qLwUqnqVU7teIaiQIIGF3jWatG1Bi2paijULAgQY9ehB+BCQRLoOovLQBBrkMzzpGA hUlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=G84w91d1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l9si3295432ejx.515.2021.02.25.04.16.25; Thu, 25 Feb 2021 04:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=G84w91d1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbhBYMP0 (ORCPT + 99 others); Thu, 25 Feb 2021 07:15:26 -0500 Received: from mx1.opensynergy.com ([217.66.60.4]:57795 "EHLO mx1.opensynergy.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232137AbhBYMPV (ORCPT ); Thu, 25 Feb 2021 07:15:21 -0500 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 44471A06F5; Thu, 25 Feb 2021 13:14:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=tsvHDlnqSzD6 yifbwIkb7LBXJuGwyXOyWV+yVzi4100=; b=G84w91d1T9lH3djLLcOGRc4cIZ4v djJeKodpta0rHWo8XqOqFYCrvJR/pbd+e/0qggFRXzKFvmv7AmJ9z/AnGR4832KL kzz1FeygLg0MA0XYDyZanT+CZ+tjorlXscycxAN176GW4aDD20q3pC7VMvRic6mR ESw3CoT1Fa4X4oanD6fgCGeTu5LCc2kd5hcSCnTeLTqpFE+1PQNieX829jtJ6uRB 3Hlf6df6K1Bfqt1UykpiGlc/Gh/nrHTKfxKI0f3G2KLP80afENBYh/hlHgb4ut0+ LNrWQyz1HiaBbzUl+UEQ0fPOpmJzckdPtwEAcoslNZBKfokyPCftiDPs2w== Subject: Re: [PATCH v5 6/9] ALSA: virtio: PCM substream operators To: Takashi Iwai CC: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , References: <20210222153444.348390-1-anton.yakovlev@opensynergy.com> <20210222153444.348390-7-anton.yakovlev@opensynergy.com> From: Anton Yakovlev Message-ID: Date: Thu, 25 Feb 2021 13:14:37 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.02.2021 11:55, Takashi Iwai wrote: > On Mon, 22 Feb 2021 16:34:41 +0100, > Anton Yakovlev wrote: >> +static int virtsnd_pcm_open(struct snd_pcm_substream *substream) >> +{ >> + struct virtio_pcm *vpcm = snd_pcm_substream_chip(substream); >> + struct virtio_pcm_substream *vss = NULL; >> + >> + if (vpcm) { >> + switch (substream->stream) { >> + case SNDRV_PCM_STREAM_PLAYBACK: >> + case SNDRV_PCM_STREAM_CAPTURE: { > > The switch() here looks superfluous. The substream->stream must be a > good value in the callback. If any, you can put WARN_ON() there, but > I don't think it worth. At least it doesn't do any harm. If something really went wrong, we can check it right in the open callback, which is called the very first. >> +static int virtsnd_pcm_hw_params(struct snd_pcm_substream *substream, >> + struct snd_pcm_hw_params *hw_params) >> +{ > .... >> + return virtsnd_pcm_msg_alloc(vss, periods, period_bytes); > > We have the allocation, but... > >> +static int virtsnd_pcm_hw_free(struct snd_pcm_substream *substream) >> +{ >> + return 0; > > ... no release at hw_free()? > I know that the free is present in the allocator, but it's only for > re-allocation case, I suppose. When the substream stops, sync_ptr waits until the device has completed all pending messages. This wait can be interrupted either by a signal or due to a timeout. In this case, the device can still access messages even after calling hw_free(). It can also issue an interrupt, and the interrupt handler will also try to access message structures. Therefore, freeing of already allocated messages occurs either in hw_params() or in dev->release(), since there it is 100% safe. > thanks, > > Takashi > -- Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin