ALSA: firewire: tascam: Use guard() for spin locks
Clean up the code using guard() for spin locks. Merely code refactoring, and no behavior change. Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250828132802.9032-19-tiwai@suse.de
This commit is contained in:
parent
cae230e4d0
commit
8885ab5f21
|
|
@ -157,15 +157,14 @@ static void read_status_messages(struct amdtp_stream *s,
|
||||||
if ((before ^ after) & mask) {
|
if ((before ^ after) & mask) {
|
||||||
struct snd_firewire_tascam_change *entry =
|
struct snd_firewire_tascam_change *entry =
|
||||||
&tscm->queue[tscm->push_pos];
|
&tscm->queue[tscm->push_pos];
|
||||||
unsigned long flag;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&tscm->lock, flag);
|
scoped_guard(spinlock_irqsave, &tscm->lock) {
|
||||||
entry->index = index;
|
entry->index = index;
|
||||||
entry->before = before;
|
entry->before = before;
|
||||||
entry->after = after;
|
entry->after = after;
|
||||||
if (++tscm->push_pos >= SND_TSCM_QUEUE_COUNT)
|
if (++tscm->push_pos >= SND_TSCM_QUEUE_COUNT)
|
||||||
tscm->push_pos = 0;
|
tscm->push_pos = 0;
|
||||||
spin_unlock_irqrestore(&tscm->lock, flag);
|
}
|
||||||
|
|
||||||
wake_up(&tscm->hwdep_wait);
|
wake_up(&tscm->hwdep_wait);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,18 +130,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
|
||||||
poll_table *wait)
|
poll_table *wait)
|
||||||
{
|
{
|
||||||
struct snd_tscm *tscm = hwdep->private_data;
|
struct snd_tscm *tscm = hwdep->private_data;
|
||||||
__poll_t events;
|
|
||||||
|
|
||||||
poll_wait(file, &tscm->hwdep_wait, wait);
|
poll_wait(file, &tscm->hwdep_wait, wait);
|
||||||
|
|
||||||
spin_lock_irq(&tscm->lock);
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
if (tscm->dev_lock_changed || tscm->push_pos != tscm->pull_pos)
|
if (tscm->dev_lock_changed || tscm->push_pos != tscm->pull_pos)
|
||||||
events = EPOLLIN | EPOLLRDNORM;
|
return EPOLLIN | EPOLLRDNORM;
|
||||||
else
|
else
|
||||||
events = 0;
|
return 0;
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
return events;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
|
static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
|
||||||
|
|
@ -165,38 +161,26 @@ static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
|
||||||
|
|
||||||
static int hwdep_lock(struct snd_tscm *tscm)
|
static int hwdep_lock(struct snd_tscm *tscm)
|
||||||
{
|
{
|
||||||
int err;
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
|
|
||||||
spin_lock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
if (tscm->dev_lock_count == 0) {
|
if (tscm->dev_lock_count == 0) {
|
||||||
tscm->dev_lock_count = -1;
|
tscm->dev_lock_count = -1;
|
||||||
err = 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
err = -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hwdep_unlock(struct snd_tscm *tscm)
|
static int hwdep_unlock(struct snd_tscm *tscm)
|
||||||
{
|
{
|
||||||
int err;
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
|
|
||||||
spin_lock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
if (tscm->dev_lock_count == -1) {
|
if (tscm->dev_lock_count == -1) {
|
||||||
tscm->dev_lock_count = 0;
|
tscm->dev_lock_count = 0;
|
||||||
err = 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
err = -EBADFD;
|
return -EBADFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tscm_hwdep_state(struct snd_tscm *tscm, void __user *arg)
|
static int tscm_hwdep_state(struct snd_tscm *tscm, void __user *arg)
|
||||||
|
|
@ -211,10 +195,9 @@ static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
|
||||||
{
|
{
|
||||||
struct snd_tscm *tscm = hwdep->private_data;
|
struct snd_tscm *tscm = hwdep->private_data;
|
||||||
|
|
||||||
spin_lock_irq(&tscm->lock);
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
if (tscm->dev_lock_count == -1)
|
if (tscm->dev_lock_count == -1)
|
||||||
tscm->dev_lock_count = 0;
|
tscm->dev_lock_count = 0;
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,30 +43,24 @@ static void midi_playback_drain(struct snd_rawmidi_substream *substream)
|
||||||
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
|
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||||
{
|
{
|
||||||
struct snd_tscm *tscm = substrm->rmidi->private_data;
|
struct snd_tscm *tscm = substrm->rmidi->private_data;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&tscm->lock, flags);
|
guard(spinlock_irqsave)(&tscm->lock);
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
tscm->tx_midi_substreams[substrm->number] = substrm;
|
tscm->tx_midi_substreams[substrm->number] = substrm;
|
||||||
else
|
else
|
||||||
tscm->tx_midi_substreams[substrm->number] = NULL;
|
tscm->tx_midi_substreams[substrm->number] = NULL;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&tscm->lock, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
|
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||||
{
|
{
|
||||||
struct snd_tscm *tscm = substrm->rmidi->private_data;
|
struct snd_tscm *tscm = substrm->rmidi->private_data;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&tscm->lock, flags);
|
guard(spinlock_irqsave)(&tscm->lock);
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
snd_fw_async_midi_port_run(&tscm->out_ports[substrm->number],
|
snd_fw_async_midi_port_run(&tscm->out_ports[substrm->number],
|
||||||
substrm);
|
substrm);
|
||||||
|
|
||||||
spin_unlock_irqrestore(&tscm->lock, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int snd_tscm_create_midi_devices(struct snd_tscm *tscm)
|
int snd_tscm_create_midi_devices(struct snd_tscm *tscm)
|
||||||
|
|
|
||||||
|
|
@ -527,33 +527,24 @@ void snd_tscm_stream_lock_changed(struct snd_tscm *tscm)
|
||||||
|
|
||||||
int snd_tscm_stream_lock_try(struct snd_tscm *tscm)
|
int snd_tscm_stream_lock_try(struct snd_tscm *tscm)
|
||||||
{
|
{
|
||||||
int err;
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
|
|
||||||
spin_lock_irq(&tscm->lock);
|
|
||||||
|
|
||||||
/* user land lock this */
|
/* user land lock this */
|
||||||
if (tscm->dev_lock_count < 0) {
|
if (tscm->dev_lock_count < 0)
|
||||||
err = -EBUSY;
|
return -EBUSY;
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this is the first time */
|
/* this is the first time */
|
||||||
if (tscm->dev_lock_count++ == 0)
|
if (tscm->dev_lock_count++ == 0)
|
||||||
snd_tscm_stream_lock_changed(tscm);
|
snd_tscm_stream_lock_changed(tscm);
|
||||||
err = 0;
|
return 0;
|
||||||
end:
|
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void snd_tscm_stream_lock_release(struct snd_tscm *tscm)
|
void snd_tscm_stream_lock_release(struct snd_tscm *tscm)
|
||||||
{
|
{
|
||||||
spin_lock_irq(&tscm->lock);
|
guard(spinlock_irq)(&tscm->lock);
|
||||||
|
|
||||||
if (WARN_ON(tscm->dev_lock_count <= 0))
|
if (WARN_ON(tscm->dev_lock_count <= 0))
|
||||||
goto end;
|
return;
|
||||||
if (--tscm->dev_lock_count == 0)
|
if (--tscm->dev_lock_count == 0)
|
||||||
snd_tscm_stream_lock_changed(tscm);
|
snd_tscm_stream_lock_changed(tscm);
|
||||||
end:
|
|
||||||
spin_unlock_irq(&tscm->lock);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue