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=1795038341; b=W8juFlVOnityGf04bLhv8ET3JwMANHFE26b5cHHSj1yEzKRLGjzX15bb8oBwubdOAe1U M+edWtIB0tCAAtljrpz0fBFxcsAZZPG6Rbj6UkQFdy0U34aN3OHZlhBFFRQnCNOvtq9tI KLmYgNfjEmxlO3KXik9gRhT+fkcguEOloY1Cp9E+Cd/HYr8ri08MDOovXQD5sLRpD5R6M GZT+iuqVT0hQKDc3X63sfJXXJn53rHrg6LI9HyjuzcURIsBY4l9dCRgvTap1RBSrpFPcg bARafjRH0cBlB9aTRqIJOMND2WIqBEjklTOUxCCbSyEDHXTiRz6QWH6jDawNGqhlBhQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795038341; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EAa3rUd99OHu3mSnMMqvsu5fmqe1I9HS0uD5EDAd3AA=; b=mNXRfRIPGNHOmdpQJCo4oMLDfRoEoFjFR6W8ZrJUwr5x9BrLbJmEGDtP5v6ika62ILB/ H0YYb37wr5SWDiJl/xPNzPRrVSlCsdC6e6Efx6Q+0WsTLusMC+e2E1PuXh3UlcoyHowaR Xp0TMDztHrimPDoITkrD+xKWAiiuzLPoQs196u7HJp5TG2tF7FKO93E4ZdP2nYcU2QfU9 iyMn8Vs/LXXi6Cha5CsU+gUAsjWcL+sRIpt1TuCEpemD8DI86Rd2rM5BmWLBIHXekkGpO yA/UabTmSt86V4nVUi0MdMzdAms46RNkJbAOtxcCadJUCZqNLYmqH6tHhk2r04ykwvg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VDW4WLY7; 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 A6BEC606A325; Wed, 18 Nov 2026 21:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VDW4WLY7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 029291F000C4; Wed, 18 Nov 2026 21:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795038341; bh=EAa3rUd99OHu3mSnMMqvsu5fmqe1I9HS0uD5EDAd3AA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VDW4WLY7Tr9UYloF608uaWzg90p1E4pdRCVMHJXabJe/G7mY2JffX6Ibi4aTHIk3G 0NjF0ZMOJcIYZHqc2up/YvcNDEzCdhb1VvUbtBuDkggZ1uALPafGN6DO33p32/l/H0 yEf2hKWyzq5W494e7dNfuhh2Q2amEmc7JAB1JYi8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Runyu Xiao , Takashi Iwai , Sasha Levin Subject: [PATCH 6.6 1711/3318] ALSA: mpu401: shut down timer before freeing MPU Date: Wed, 18 Nov 2026 15:38:53 +0100 Message-ID: <20261118150413.197475847@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Runyu Xiao [ Upstream commit 9332af5220d42341bb1446a62c545c0518e990ef ] When an MPU401 interface has no usable IRQ, the driver polls raw-MIDI input and output with a timer. During raw-MIDI teardown, the timer callback can already be running when snd_mpu401_uart_remove_timer() clears the last mode bit and calls timer_delete(). That API neither waits for a running callback nor prevents it from rearming the timer, and free_irq() does not synchronize timer callbacks. snd_mpu401_uart_free() can therefore release mpu while the timer callback still uses it. Initialize the timer once when the MPU object is created and only rearm it while a timer mode is active. Shut it down synchronously after freeing the IRQ so an in-flight callback completes before mpu and its resources are released. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Runyu Xiao Link: https://patch.msgid.link/20260927093809.681726-1-runyu.xiao@seu.edu.cn Signed-off-by: Takashi Iwai [ sashal: adjusted locking context for explicit spin_lock_irqsave()/spin_unlock_irqrestore() calls instead of scoped guards ] Signed-off-by: Sasha Levin --- sound/drivers/mpu401/mpu401_uart.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index f435b9b4ae241..e920a290ba1b6 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -161,14 +161,15 @@ static void snd_mpu401_uart_timer(struct timer_list *t) spin_lock_irqsave(&mpu->timer_lock, flags); /*mpu->mode |= MPU401_MODE_TIMER;*/ - mod_timer(&mpu->timer, 1 + jiffies); + if (mpu->timer_invoked) + mod_timer(&mpu->timer, 1 + jiffies); spin_unlock_irqrestore(&mpu->timer_lock, flags); if (mpu->rmidi) _snd_mpu401_uart_interrupt(mpu); } /* - * initialize the timer callback if not programmed yet + * arm the timer if it is not already active */ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input) { @@ -176,7 +177,6 @@ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input) spin_lock_irqsave (&mpu->timer_lock, flags); if (mpu->timer_invoked == 0) { - timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0); mod_timer(&mpu->timer, 1 + jiffies); } mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER : @@ -490,6 +490,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) struct snd_mpu401 *mpu = rmidi->private_data; if (mpu->irq >= 0) free_irq(mpu->irq, (void *) mpu); + timer_shutdown_sync(&mpu->timer); release_and_free_resource(mpu->res); kfree(mpu); } @@ -544,6 +545,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device, spin_lock_init(&mpu->input_lock); spin_lock_init(&mpu->output_lock); spin_lock_init(&mpu->timer_lock); + timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0); mpu->hardware = hardware; mpu->irq = -1; if (! (info_flags & MPU401_INFO_INTEGRATED)) { -- 2.53.0