ALSA: firewire: oxfw: 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-18-tiwai@suse.de
This commit is contained in:
Takashi Iwai
2025-08-28 15:27:21 +02:00
parent 0b8bf8d00f
commit cae230e4d0
3 changed files with 18 additions and 50 deletions

View File

@@ -53,18 +53,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_oxfw *oxfw = hwdep->private_data;
__poll_t events;
poll_wait(file, &oxfw->hwdep_wait, wait);
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_changed)
events = EPOLLIN | EPOLLRDNORM;
return EPOLLIN | EPOLLRDNORM;
else
events = 0;
spin_unlock_irq(&oxfw->lock);
return events;
return 0;
}
static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg)
@@ -88,48 +84,35 @@ static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg)
static int hwdep_lock(struct snd_oxfw *oxfw)
{
int err;
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == 0) {
oxfw->dev_lock_count = -1;
err = 0;
return 0;
} else {
err = -EBUSY;
return -EBUSY;
}
spin_unlock_irq(&oxfw->lock);
return err;
}
static int hwdep_unlock(struct snd_oxfw *oxfw)
{
int err;
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == -1) {
oxfw->dev_lock_count = 0;
err = 0;
return 0;
} else {
err = -EBADFD;
return -EBADFD;
}
spin_unlock_irq(&oxfw->lock);
return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_oxfw *oxfw = hwdep->private_data;
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == -1)
oxfw->dev_lock_count = 0;
spin_unlock_irq(&oxfw->lock);
return 0;
}

View File

@@ -84,9 +84,8 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_oxfw *oxfw = substrm->rmidi->private_data;
unsigned long flags;
spin_lock_irqsave(&oxfw->lock, flags);
guard(spinlock_irqsave)(&oxfw->lock);
if (up)
amdtp_am824_midi_trigger(&oxfw->tx_stream,
@@ -94,16 +93,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&oxfw->tx_stream,
substrm->number, NULL);
spin_unlock_irqrestore(&oxfw->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_oxfw *oxfw = substrm->rmidi->private_data;
unsigned long flags;
spin_lock_irqsave(&oxfw->lock, flags);
guard(spinlock_irqsave)(&oxfw->lock);
if (up)
amdtp_am824_midi_trigger(&oxfw->rx_stream,
@@ -111,8 +107,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&oxfw->rx_stream,
substrm->number, NULL);
spin_unlock_irqrestore(&oxfw->lock, flags);
}
static void set_midi_substream_names(struct snd_oxfw *oxfw,

View File

@@ -866,33 +866,24 @@ void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw)
int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw)
{
int err;
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
/* user land lock this */
if (oxfw->dev_lock_count < 0) {
err = -EBUSY;
goto end;
}
if (oxfw->dev_lock_count < 0)
return -EBUSY;
/* this is the first time */
if (oxfw->dev_lock_count++ == 0)
snd_oxfw_stream_lock_changed(oxfw);
err = 0;
end:
spin_unlock_irq(&oxfw->lock);
return err;
return 0;
}
void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw)
{
spin_lock_irq(&oxfw->lock);
guard(spinlock_irq)(&oxfw->lock);
if (WARN_ON(oxfw->dev_lock_count <= 0))
goto end;
return;
if (--oxfw->dev_lock_count == 0)
snd_oxfw_stream_lock_changed(oxfw);
end:
spin_unlock_irq(&oxfw->lock);
}