Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1115655rdb; Wed, 6 Dec 2023 09:01:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IE19V9G4d6xALm5c2TjWZovPI5CZGUzPxJ/Xl0uI5iDJbWJjlsLdZLowwperne9lszA6hI8 X-Received: by 2002:a05:6a20:12c8:b0:18f:97c:9776 with SMTP id v8-20020a056a2012c800b0018f097c9776mr1348762pzg.94.1701882065313; Wed, 06 Dec 2023 09:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701882065; cv=none; d=google.com; s=arc-20160816; b=COVNNBTBbVp8uvFgFszw/25SEXJPyd6Py9UMceMr3QgXmanCuntEMfSSdoHBNkgwJZ kv38HX5Q5816xOSNiHzHi2+67BEuRIn+m4vqrVexU3b9+4MIdQ9/FMgkHMDu9KDmtL3x 87tsd/1FLZriJoZ73WQb1DQ+be8ZyLAE72ohmexIiaCRtJzmnlMJ1okvPDpnCseiolKq aeRKOZy/y6gKJIPoWajBKDNUMXgkRd37+X4sbGgx2wAmVf62FOUkn7A75K5/lgx+krtk Afnzd4XIytOLLYoWUBk4G68Sl3zv6B/CJDv6tnw1pSt10mlsrzIyO7Ksq+BETBh0ENpp OVKg== 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; bh=6B5N+sq95zGa7Rn/fVmepxqhNdihWRdmOtyjRqPbaDw=; fh=e/ZsPtzEweRMqYIUPUIOJAzY1n6SBCZ3g7deVzL5cxA=; b=xU0nCd1mTzwiqVlKhSQXY7aektA2MIt7UTppIcwgbAv/kRcEq6PHTNs8QDoSFgJWif krk/MHKxZ3BQz6dpVXE4/LzDGCzcbrUo4QAKwHcJ5Simed17m5tu/Oeg72mBhCv8q1dT wuC7mQy5Y5OEou9YKLUbPW/f9YdAXWuyEFVGWLdWqIoHOpHgJcAOdNBA2+T07t4rZBUN LLrtflco5TjpsavEpAOyfEbAVjdJNTpENghr1OQ1562W0Hm285TGCwZBx3ttIc3o/EWD g8Lidxkt9oSUDLbw4wmltad3Mpk1nEaqwnwL8Rb6iAH8STKqNmHEKvYQqQKqPTPJvvGr Ejyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cd23-20020a056a02079700b005c66404de05si175246pgb.413.2023.12.06.09.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:01:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EFEDF809C393; Wed, 6 Dec 2023 09:00:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378508AbjLFQ7w (ORCPT + 99 others); Wed, 6 Dec 2023 11:59:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjLFQ7u (ORCPT ); Wed, 6 Dec 2023 11:59:50 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFFE1D3; Wed, 6 Dec 2023 08:59:56 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 688321FCEC; Wed, 6 Dec 2023 16:59:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 32AAA136CD; Wed, 6 Dec 2023 16:59:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id lGvfCouocGUfbgAAD6G6ig (envelope-from ); Wed, 06 Dec 2023 16:59:55 +0000 Date: Wed, 06 Dec 2023 17:59:54 +0100 Message-ID: <871qbz2rn9.wl-tiwai@suse.de> From: Takashi Iwai To: Ivan Orlov Cc: tiwai@suse.com, perex@perex.cz, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] ALSA: pcmtest: stop timer in the hw_free callback In-Reply-To: <20231206151046.25773-1-ivan.orlov0322@gmail.com> References: <20231206151046.25773-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-Spamd-Bar: +++++++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of tiwai@suse.de) smtp.mailfrom=tiwai@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [15.23 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; R_SPF_SOFTFAIL(4.60)[~all]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(2.47)[0.824]; NEURAL_SPAM_LONG(3.47)[0.992]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 15.23 X-Rspamd-Queue-Id: 688321FCEC X-Spam: Yes X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 09:00:26 -0800 (PST) On Wed, 06 Dec 2023 16:10:46 +0100, Ivan Orlov wrote: > > Stop timer in the 'hw_free' callback instead of the 'close' callback > since we want the timer to be stopped before the DMA buffer is released. > Otherwise, it could trigger a kernel panic in some circumstances, for > instance when the DMA buffer is already released but the timer callback > is still running. You can't call timer_shutdown_sync() at hw_free. The PCM stream is still there and you can re-setup via hw_params without closing. But, after timer_shutdown_sync(), the timer instance must not be used any longer. A more proper way would be to call timer_delete() (no sync) at trigger STOP, then call timer_delete_sync() at sync_stop op in addition. This assures the immediate stop and the sync before changing to another PCM state. timer_shutdown_sync() can be kept at the close op to be sure. thanks, Takashi > > Signed-off-by: Ivan Orlov > --- > V1 -> V2: > - Remove useless NULLing of v_iter->substream. It will be released in > 'close' callback. > > sound/drivers/pcmtest.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c > index b59b78a09224..8a78fa56106f 100644 > --- a/sound/drivers/pcmtest.c > +++ b/sound/drivers/pcmtest.c > @@ -396,8 +396,6 @@ static int snd_pcmtst_pcm_close(struct snd_pcm_substream *substream) > { > struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; > > - timer_shutdown_sync(&v_iter->timer_instance); > - v_iter->substream = NULL; > playback_capture_test = !v_iter->is_buf_corrupted; > kfree(v_iter); > return 0; > @@ -499,6 +497,10 @@ static int snd_pcmtst_pcm_hw_params(struct snd_pcm_substream *substream, > > static int snd_pcmtst_pcm_hw_free(struct snd_pcm_substream *substream) > { > + struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; > + > + timer_shutdown_sync(&v_iter->timer_instance); > + > return 0; > } > > -- > 2.34.1 >