]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 5.4
authorSasha Levin <sashal@kernel.org>
Fri, 14 Jul 2023 20:53:36 +0000 (16:53 -0400)
committerSasha Levin <sashal@kernel.org>
Fri, 14 Jul 2023 20:53:36 +0000 (16:53 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
queue-5.4/alsa-jack-fix-mutex-call-in-snd_jack_report.patch [new file with mode: 0644]
queue-5.4/series

diff --git a/queue-5.4/alsa-jack-fix-mutex-call-in-snd_jack_report.patch b/queue-5.4/alsa-jack-fix-mutex-call-in-snd_jack_report.patch
new file mode 100644 (file)
index 0000000..72aacbb
--- /dev/null
@@ -0,0 +1,91 @@
+From eb557ccd93d143675ff7af6f82cb0a75150dc7f9 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Thu, 6 Jul 2023 17:53:57 +0200
+Subject: ALSA: jack: Fix mutex call in snd_jack_report()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Takashi Iwai <tiwai@suse.de>
+
+[ Upstream commit 89dbb335cb6a627a4067bc42caa09c8bc3326d40 ]
+
+snd_jack_report() is supposed to be callable from an IRQ context, too,
+and it's indeed used in that way from virtsnd driver.  The fix for
+input_dev race in commit 1b6a6fc5280e ("ALSA: jack: Access input_dev
+under mutex"), however, introduced a mutex lock in snd_jack_report(),
+and this resulted in a potential sleep-in-atomic.
+
+For addressing that problem, this patch changes the relevant code to
+use the object get/put and removes the mutex usage.  That is,
+snd_jack_report(), it takes input_get_device() and leaves with
+input_put_device() for assuring the input_dev being assigned.
+
+Although the whole mutex could be reduced, we keep it because it can
+be still a protection for potential races between creation and
+deletion.
+
+Fixes: 1b6a6fc5280e ("ALSA: jack: Access input_dev under mutex")
+Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
+Closes: https://lore.kernel.org/r/cf95f7fe-a748-4990-8378-000491b40329@moroto.mountain
+Tested-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
+Cc: <stable@vger.kernel.org>
+Link: https://lore.kernel.org/r/20230706155357.3470-1-tiwai@suse.de
+Signed-off-by: Takashi Iwai <tiwai@suse.de>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ sound/core/jack.c | 15 +++++++--------
+ 1 file changed, 7 insertions(+), 8 deletions(-)
+
+diff --git a/sound/core/jack.c b/sound/core/jack.c
+index e7ac82d468216..c2022b13fddc9 100644
+--- a/sound/core/jack.c
++++ b/sound/core/jack.c
+@@ -364,6 +364,7 @@ void snd_jack_report(struct snd_jack *jack, int status)
+ {
+       struct snd_jack_kctl *jack_kctl;
+ #ifdef CONFIG_SND_JACK_INPUT_DEV
++      struct input_dev *idev;
+       int i;
+ #endif
+@@ -375,30 +376,28 @@ void snd_jack_report(struct snd_jack *jack, int status)
+                                           status & jack_kctl->mask_bits);
+ #ifdef CONFIG_SND_JACK_INPUT_DEV
+-      mutex_lock(&jack->input_dev_lock);
+-      if (!jack->input_dev) {
+-              mutex_unlock(&jack->input_dev_lock);
++      idev = input_get_device(jack->input_dev);
++      if (!idev)
+               return;
+-      }
+       for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
+               int testbit = SND_JACK_BTN_0 >> i;
+               if (jack->type & testbit)
+-                      input_report_key(jack->input_dev, jack->key[i],
++                      input_report_key(idev, jack->key[i],
+                                        status & testbit);
+       }
+       for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) {
+               int testbit = 1 << i;
+               if (jack->type & testbit)
+-                      input_report_switch(jack->input_dev,
++                      input_report_switch(idev,
+                                           jack_switch_types[i],
+                                           status & testbit);
+       }
+-      input_sync(jack->input_dev);
+-      mutex_unlock(&jack->input_dev_lock);
++      input_sync(idev);
++      input_put_device(idev);
+ #endif /* CONFIG_SND_JACK_INPUT_DEV */
+ }
+ EXPORT_SYMBOL(snd_jack_report);
+-- 
+2.39.2
+
index 28988d6df8e108ca168b7d6b3dea7303f55e5667..b61187703324db6ad09b2378ef931d47c77f4264 100644 (file)
@@ -161,3 +161,4 @@ net-dsa-tag_sja1105-fix-mac-da-patching-from-meta-fr.patch
 sh-dma-fix-dma-channel-offset-calculation.patch
 i2c-xiic-defer-xiic_wakeup-and-__xiic_start_xfer-in-.patch
 i2c-xiic-don-t-try-to-handle-more-interrupt-events-a.patch
+alsa-jack-fix-mutex-call-in-snd_jack_report.patch