Skip to contentSkip to conversation

ALSA: seq: oss: Avoid mutex lock for a long-time ioctl

PATCH New Takashi Iwai 1 participant 1 message Sep 22, 2020 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: seq: oss: Avoid mutex lock for a long-time ioctl

Recently we applied a fix to cover the whole OSS sequencer ioctls with the mutex for dealing with the possible races. This works fine in general, but in theory, this may lead to unexpectedly long stall if an ioctl like SNDCTL_SEQ_SYNC is issued and an event with the far future timestamp was queued.

For fixing such a potential stall, this patch changes the mutex lock applied conditionally excluding such an ioctl command. Also, change the mutex_lock() with the interruptible version for user to allow escaping from the big-hammer mutex.

Fixes 80982c7e834e ("ALSA: seq: oss: Serialize ioctls")
---
 sound/core/seq/oss/seq_oss.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
sound/core/seq/oss/seq_oss.c +5 -2
index c8b9c0b315d8..250a92b18726 100644
@@ -174,9 +174,12 @@ odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	if (snd_BUG_ON(!dp))
 		return -ENXIO;
 
-	mutex_lock(&register_mutex);
+	if (cmd != SNDCTL_SEQ_SYNC &&
+	    mutex_lock_interruptible(&register_mutex))
+		return -ERESTARTSYS;
 	rc = snd_seq_oss_ioctl(dp, cmd, arg);
-	mutex_unlock(&register_mutex);
+	if (cmd != SNDCTL_SEQ_SYNC)
+		mutex_unlock(&register_mutex);
 	return rc;
 }
 
Signature · 1 line
2.16.4