]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ALSA: hdsp: Break infinite MIDI input flush loop
authorTakashi Iwai <tiwai@suse.de>
Thu, 8 Aug 2024 09:15:12 +0000 (11:15 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:08:13 +0000 (15:08 +0200)
[ 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 <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/pci/rme9652/hdsp.c
sound/pci/rme9652/hdspm.c

index 95434742450044a43a54d02fa81ab5a1fbdbfb87..f592eb7a5d1be17d4fe136fb454962e3f0980790 100644 (file)
@@ -1303,8 +1303,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)
index 51c3c6a08a1c5f03d069ff6b82486a43512eab81..04f9d92af46c1f3067e9ef3fbce22a1cf1e522cd 100644 (file)
@@ -1839,8 +1839,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)