From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E225618C335; Wed, 25 Sep 2024 11:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727264507; cv=none; b=NXSQsgDg2zPJT3TjBpBHWsl4u+9xsyZ2XJQo3em1kPVddCnM0bU3RY+BxrJJuPjIkAEkTOVuqukZdG3n1UTozDG0TqdUwMU+T5wTahhwF9cAYvjMIEb/3rd59TK09o7DOIwcCIXDELSTTLQd1vvkyjS7LytgvuDCVimrxIDMVcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727264507; c=relaxed/simple; bh=7hvrXMe7WuLPXYPFt7npfA5tdlIn08uNZaYmyprZjW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SAn5RplmlO/2DX7Ubk9qD5C/avdrJyC3hA2vlcPNj9KekKOGCSILoGEfFDxac17QAxXTR4qCGc3W0SC9n28V1Qy2MRW7p4KUKfsd9RMJ4fhmfieucgQrlvBwIZAw5/bGDzYjUjgERXEAhp2mekDI1tT0K2hPBpybKwZS39btwe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IQXTkZ0j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IQXTkZ0j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F91AC4CEC7; Wed, 25 Sep 2024 11:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727264506; bh=7hvrXMe7WuLPXYPFt7npfA5tdlIn08uNZaYmyprZjW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQXTkZ0j0M9GToTrB4ZUksE5Wl82ObAUvnumuVMF90Hm8ho0kp4NuXpWJbJUUF2wf I7F+JXYWJTETDYolaCcr+a0AZa6dWDHY1rD5oC+280VlGNuLDYafehbDlSlPuIL4f7 lwgFFswz5Yl9K84XOVBcwWxPTN0+V3MRBGbyCiWna8HaoYWe+xbZXHZ78MRLlz1gXU z86uGaV6m7kbBqBPMYGYv9X8yQmoj5Jw0/8n6BbLW2CAq2oe8p32fL1llXOGgspvM9 PfAO+f71TyRW97nVutuD3GvV5eR6kyZIMwpowj2hi+vM+I/0vvCso/SoznHS/YKf73 Fl6K28nO9xnhg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Sasha Levin , perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org Subject: [PATCH AUTOSEL 6.11 106/244] ALSA: hdsp: Break infinite MIDI input flush loop Date: Wed, 25 Sep 2024 07:25:27 -0400 Message-ID: <20240925113641.1297102-106-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925113641.1297102-1-sashal@kernel.org> References: <20240925113641.1297102-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.11 Content-Transfer-Encoding: 8bit From: Takashi Iwai [ Upstream commit c01f3815453e2d5f699ccd8c8c1f93a5b8669e59 ] The current MIDI input flush on HDSP and HDSPM drivers relies on the hardware reporting the right value. If the hardware doesn't give the proper value but returns -1, it may be stuck at an infinite loop. Add a counter and break if the loop is unexpectedly too long. Link: https://patch.msgid.link/20240808091513.31380-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/rme9652/hdsp.c | 6 ++++-- sound/pci/rme9652/hdspm.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index e7d1b43471a29..713ca262a0e97 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -1298,8 +1298,10 @@ static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id) static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id) { - while (snd_hdsp_midi_input_available (hdsp, id)) - snd_hdsp_midi_read_byte (hdsp, id); + int count = 256; + + while (snd_hdsp_midi_input_available(hdsp, id) && --count) + snd_hdsp_midi_read_byte(hdsp, id); } static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi) diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 267c7848974ae..74215f57f4fc9 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -1838,8 +1838,10 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) { - while (snd_hdspm_midi_input_available (hdspm, id)) - snd_hdspm_midi_read_byte (hdspm, id); + int count = 256; + + while (snd_hdspm_midi_input_available(hdspm, id) && --count) + snd_hdspm_midi_read_byte(hdspm, id); } static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) -- 2.43.0