Skip to content

Commit

Permalink
ALSA: seq: oss: Avoid mutex lock for a long-time ioctl
Browse files Browse the repository at this point in the history
[ Upstream commit 2759caa ]

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: 80982c7 ("ALSA: seq: oss: Serialize ioctls")
Suggested-by: Pavel Machek <pavel@ucw.cz>
Link: https://lore.kernel.org/r/20200922083856.28572-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
tiwai authored and gregkh committed Oct 29, 2020
1 parent 6f04266 commit f706500
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sound/core/seq/oss/seq_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f706500

Please sign in to comment.