From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796181725; b=4eI8Xz//9HSqCxXdOkfWx2p4D5qvK62wM9atbQlyhgjxOdZigSQoXzWIGTjHNb4I1QC0 k4DdmGZZLv1rZp07UlZ5rqQanzbUAD33cbF+S0kvhKHEZwZ6WwxE3xhiL3vPdwa/mnZ+P UjL/5+vdZpGSEW2Z4Ie7tBQMYOmbtp7MPZR8zd7f6C9s1juLqY5qqDyxypmeQv50WB8o9 48ErzPf+kKffuD9m6ePNcadDOSDkrQITuPJD6B/7Fg3XJoUSKW9ksxq0WO5Evnx8c20Sq qWRRpRO0K9hj2P44LTzAjwGN/mMXYIUsbl8AlrmENl5cBlBR9sB/JpSq8TuYJ1qoLNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181725; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vCH7uGJw8nc2VLtiFjyLDYoeecbwzZFJAgx/THUaHXs=; b=TlKpV+MVXw3skJVEf+CpCArkIcSclrAND6hCbKmztA1Mn9kyCSZOjiaiVByYQVc6fTNo w3sOyt97dz1dEsVWTCGS+OcShDpzcJclzbL9SmbJ+0cHRETPzmivu43U4Y/9QJ/C+O6P0 AFIAbJqKx+848tzjIPIYi76Sii6PlhK0/syusH+bNi1OaHB4i/1+PHqHvT4U8v0+ml0OR urUrWmVFIf0loZftu742INqsEmah0ab3ittky5M1C5jTi/JU8D3LZkXXHkr14KfLqQQ6x TmF6fOJpip4ULCmOSbuHiHjxxKTpQBRaWwn9vNw6KSBVFc3oPSK/VqYhsUcihVMeuMQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QkV1FDeR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C55B2606A32D for ; Wed, 2 Dec 2026 03:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QkV1FDeR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D0341F00896; Wed, 2 Dec 2026 03:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181725; bh=vCH7uGJw8nc2VLtiFjyLDYoeecbwzZFJAgx/THUaHXs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QkV1FDeRA37TFgEY1YQdLa2aRkWpR/G9PS/f0SzfsC3W4eDdpFif75ar3pTsNUuNZ tztWfrHi7+UadxgrzVXIMtAFB/nwWVmFVzxQMdNUHq5GweM8Ku0bKLxsUbMUpxpSrv Vs+/5ssMMQPUlp5aM5jooCmIqKyMgggpJHmeHLcI4CocdS0P6Y4Gmo8HGoK58Q5bKC UKQDO0AjuQc6tmNGlU17h0NR+lb38wxOSNSWKz37b9GoIyhSKskNq1MOvJSKZVD8NU iAhNbwkneEC6VHQl7kR76xS9Yd3d6UkQYEmM69SjqwqfEMbhYsWkUfg8w/rz1WHicH GS2l6l7cnaBtQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: emu8000: shut down the pcm timer before freeing snd_emu8k_pcm Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202103300.4-1-xuhx@hust.edu.cn> References: <20261202103300.4-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:22:04 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ALSA: emu8000: incomplete timer stop sync in emu8k_pcm_timer_func() and close -- commit 82fbf8abf709cff25e215ab2626ead1e43756cea Author: Hanxiang Xu ALSA: emu8000: shut down the pcm timer before freeing snd_emu8k_pcm This commit checks rec->timer_running before re-arming the PCM timer in emu8k_pcm_timer_func() and calls timer_shutdown_sync() in emu8k_pcm_close() before freeing struct snd_emu8k_pcm. > diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c > index d2ca70aad1621..360e0d05a5fd6 100644 > --- a/sound/isa/sb/emu8000_pcm.c > +++ b/sound/isa/sb/emu8000_pcm.c > @@ -197,7 +197,8 @@ static void emu8k_pcm_timer_func(struct timer_list *t) > rec->last_ptr =3D ptr; > =20 > /* reprogram timer */ > - mod_timer(&rec->timer, jiffies + 1); > + if (rec->timer_running) > + mod_timer(&rec->timer, jiffies + 1); > =20 > /* update period */ > if (rec->period_pos >=3D (int)rec->period_size) { > @@ -246,6 +247,8 @@ static int emu8k_pcm_open(struct snd_pcm_substream *s= ubs) > static int emu8k_pcm_close(struct snd_pcm_substream *subs) > { > struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; > + > + timer_shutdown_sync(&rec->timer); > kfree(rec); > subs->runtime->private_data =3D NULL; > return 0; [Severity: Medium] Can an already-dequeued emu8k_pcm_timer_func() callback still race with stream teardown or re-preparation before emu8k_pcm_close() is reached? CPU0 CPU1 stop_voice() spin_lock(&rec->timer_lock) timer_delete(&rec->timer) rec->timer_running =3D 0 spin_unlock(&rec->timer_lock) emu8k_pcm_timer_func() emu8k_pcm_hw_free() spin_lock(&rec->timer_lock) emu8k_close_dram(rec->emu) ptr =3D emu8k_get_curpos(rec, 0) snd_util_mem_free(...) ... snd_pcm_period_elapsed(...) <-- runs on stopped/freed hw Because rec->timer_running is only checked around mod_timer(), a callback that was already dequeued when stop_voice() ran still reads hardware registers, updates rec->period_pos and rec->last_ptr, and calls snd_pcm_period_elapsed() after the stream has stopped. In addition, synchronizing the timer only in emu8k_pcm_close() is too late for snd_pcm_release_substream(), which runs do_hw_free() -> emu8k_pcm_hw_free() before substream->ops->close(), as well as for SNDRV_PCM_IOCTL_HW_FREE and SNDRV_PCM_IOCTL_PREPARE on an open substream (where emu8k_pcm_prepare() resets rec->last_ptr, rec->period_pos, rec->buf_size, and rec->period_size without holding rec->timer_lock). Checking !rec->timer_running at the start of the rec->timer_lock scope in emu8k_pcm_timer_func() and wiring up a snd_pcm_ops.sync_stop callback that calls timer_delete_sync(&rec->timer) would ensure the timer is quiescent before hw_free and prepare as well as close. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202103300.4-1-= xuhx@hust.edu.cn?part=3D1