From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 06/11] ALSA: caiaq: Fix races at MIDI URB and trigger accesses
Date: Thu, 8 Oct 2026 21:25:46 +0200 [thread overview]
Message-ID: <20261008192553.300025-7-tiwai@suse.de> (raw)
In-Reply-To: <20261008192553.300025-1-tiwai@suse.de>
URB completion and rawmidi trigger callbacks can race with each other,
which may put the state inconsistent, causing double submissions, etc.
Guard both with a new spinlock for avoiding the races.
Fixes: f3f80a9205da ("ALSA: caiaq - Fix Oops with MIDI")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/usb/caiaq/device.c | 1 +
sound/usb/caiaq/device.h | 3 ++-
sound/usb/caiaq/midi.c | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index c68ed16d7ac4..634dc36f2ead 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -455,6 +455,7 @@ static int create_card(struct usb_device *usb_dev,
cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
le16_to_cpu(usb_dev->descriptor.idProduct));
spin_lock_init(&cdev->spinlock);
+ spin_lock_init(&cdev->midi_lock);
mutex_init(&cdev->ep1_out_mutex);
*cardp = card;
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index dd726ca68e80..16f65e7867d1 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -77,7 +77,8 @@ struct snd_usb_caiaqdev {
unsigned char midi_out_buf[EP1_BUFSIZE];
struct caiaq_device_spec spec;
- spinlock_t spinlock;
+ spinlock_t spinlock; /* for PCM audio */
+ spinlock_t midi_lock; /* midi_x_stream, midi_out_active */
wait_queue_head_t ep1_wait_queue;
wait_queue_head_t prepare_wait_queue;
int spec_received, audio_parm_answer;
diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c
index 18529484c8dc..b7d7d24937a7 100644
--- a/sound/usb/caiaq/midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -79,6 +79,7 @@ static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *subs
{
struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;
+ guard(spinlock_irqsave)(&cdev->midi_lock);
if (up) {
cdev->midi_out_substream = substream;
if (!cdev->midi_out_active)
@@ -151,6 +152,7 @@ void snd_usb_caiaq_midi_output_done(struct urb* urb)
{
struct snd_usb_caiaqdev *cdev = urb->context;
+ guard(spinlock_irqsave)(&cdev->midi_lock);
cdev->midi_out_active = 0;
if (urb->status != 0)
return;
--
2.55.0
next prev parent reply other threads:[~2026-10-08 19:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 19:25 [PATCH 00/11] ALSA: yet a few more fixes for AI bug reports Takashi Iwai
2026-10-08 19:25 ` [PATCH 01/11] ALSA: hda: intel: Cancel delayed work at shutdown, too Takashi Iwai
2026-10-08 19:25 ` [PATCH 02/11] ALSA: hda: Disable unsol event handling at error and shutdown paths Takashi Iwai
2026-10-08 19:25 ` [PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations Takashi Iwai
2026-10-09 10:13 ` kernel test robot
2026-10-09 10:56 ` kernel test robot
2026-10-08 19:25 ` [PATCH 04/11] ALSA: hda: Add NULL check for the driver pointer at unsol event work Takashi Iwai
2026-10-08 19:25 ` [PATCH 05/11] ALSA: caiaq: Register card at the final step Takashi Iwai
2026-10-08 19:25 ` Takashi Iwai [this message]
2026-10-08 19:25 ` [PATCH 07/11] ALSA: usb: us16x08: Fix racy accesses of mixer elements Takashi Iwai
2026-10-08 19:25 ` [PATCH 08/11] ASoC: fsl_asrc_m2m: Fix bogus compress task pointer assignments Takashi Iwai
2026-10-08 19:25 ` [PATCH 09/11] ALSA: line6: Reject too small max packet sizes Takashi Iwai
2026-10-08 19:25 ` [PATCH 10/11] ALSA: line6: Fix potential OOB write in line6_capture_copy() Takashi Iwai
2026-10-08 19:25 ` [PATCH 11/11] ALSA: line6: Fix handling of zero-length capture packets Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261008192553.300025-7-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.