mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 10:01:39 -05:00
ALSA: firewire: fireworks: 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-16-tiwai@suse.de
This commit is contained in:
@@ -119,14 +119,14 @@ efw_transaction(struct snd_efw *efw, unsigned int category,
|
||||
return -ENOMEM;
|
||||
|
||||
/* to keep consistency of sequence number */
|
||||
spin_lock(&efw->lock);
|
||||
if ((efw->seqnum < KERNEL_SEQNUM_MIN) ||
|
||||
(efw->seqnum >= KERNEL_SEQNUM_MAX - 2))
|
||||
efw->seqnum = KERNEL_SEQNUM_MIN;
|
||||
else
|
||||
efw->seqnum += 2;
|
||||
seqnum = efw->seqnum;
|
||||
spin_unlock(&efw->lock);
|
||||
scoped_guard(spinlock, &efw->lock) {
|
||||
if ((efw->seqnum < KERNEL_SEQNUM_MIN) ||
|
||||
(efw->seqnum >= KERNEL_SEQNUM_MAX - 2))
|
||||
efw->seqnum = KERNEL_SEQNUM_MIN;
|
||||
else
|
||||
efw->seqnum += 2;
|
||||
seqnum = efw->seqnum;
|
||||
}
|
||||
|
||||
/* fill transaction header fields */
|
||||
cmd_bytes = sizeof(struct snd_efw_transaction) + param_bytes;
|
||||
|
||||
@@ -103,12 +103,10 @@ hwdep_read_locked(struct snd_efw *efw, char __user *buf, long count,
|
||||
.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
|
||||
};
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
|
||||
event.lock_status.status = (efw->dev_lock_count > 0);
|
||||
efw->dev_lock_changed = false;
|
||||
|
||||
spin_unlock_irq(&efw->lock);
|
||||
scoped_guard(spinlock_irq, &efw->lock) {
|
||||
event.lock_status.status = (efw->dev_lock_count > 0);
|
||||
efw->dev_lock_changed = false;
|
||||
}
|
||||
|
||||
count = min_t(long, count, sizeof(event.lock_status));
|
||||
|
||||
@@ -192,13 +190,11 @@ hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
|
||||
|
||||
poll_wait(file, &efw->hwdep_wait, wait);
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
if (efw->dev_lock_changed || efw->pull_ptr != efw->push_ptr)
|
||||
events = EPOLLIN | EPOLLRDNORM;
|
||||
else
|
||||
events = 0;
|
||||
spin_unlock_irq(&efw->lock);
|
||||
|
||||
return events | EPOLLOUT;
|
||||
}
|
||||
|
||||
@@ -225,39 +221,27 @@ hwdep_get_info(struct snd_efw *efw, void __user *arg)
|
||||
static int
|
||||
hwdep_lock(struct snd_efw *efw)
|
||||
{
|
||||
int err;
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
|
||||
if (efw->dev_lock_count == 0) {
|
||||
efw->dev_lock_count = -1;
|
||||
err = 0;
|
||||
return 0;
|
||||
} else {
|
||||
err = -EBUSY;
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
spin_unlock_irq(&efw->lock);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
hwdep_unlock(struct snd_efw *efw)
|
||||
{
|
||||
int err;
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
|
||||
if (efw->dev_lock_count == -1) {
|
||||
efw->dev_lock_count = 0;
|
||||
err = 0;
|
||||
return 0;
|
||||
} else {
|
||||
err = -EBADFD;
|
||||
return -EBADFD;
|
||||
}
|
||||
|
||||
spin_unlock_irq(&efw->lock);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -265,10 +249,9 @@ hwdep_release(struct snd_hwdep *hwdep, struct file *file)
|
||||
{
|
||||
struct snd_efw *efw = hwdep->private_data;
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
if (efw->dev_lock_count == -1)
|
||||
efw->dev_lock_count = 0;
|
||||
spin_unlock_irq(&efw->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
|
||||
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||
{
|
||||
struct snd_efw *efw = substrm->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&efw->lock, flags);
|
||||
guard(spinlock_irqsave)(&efw->lock);
|
||||
|
||||
if (up)
|
||||
amdtp_am824_midi_trigger(&efw->tx_stream,
|
||||
@@ -56,16 +55,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||
else
|
||||
amdtp_am824_midi_trigger(&efw->tx_stream,
|
||||
substrm->number, NULL);
|
||||
|
||||
spin_unlock_irqrestore(&efw->lock, flags);
|
||||
}
|
||||
|
||||
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||
{
|
||||
struct snd_efw *efw = substrm->rmidi->private_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&efw->lock, flags);
|
||||
guard(spinlock_irqsave)(&efw->lock);
|
||||
|
||||
if (up)
|
||||
amdtp_am824_midi_trigger(&efw->rx_stream,
|
||||
@@ -73,8 +69,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
|
||||
else
|
||||
amdtp_am824_midi_trigger(&efw->rx_stream,
|
||||
substrm->number, NULL);
|
||||
|
||||
spin_unlock_irqrestore(&efw->lock, flags);
|
||||
}
|
||||
|
||||
static void set_midi_substream_names(struct snd_efw *efw,
|
||||
|
||||
@@ -345,33 +345,24 @@ void snd_efw_stream_lock_changed(struct snd_efw *efw)
|
||||
|
||||
int snd_efw_stream_lock_try(struct snd_efw *efw)
|
||||
{
|
||||
int err;
|
||||
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
|
||||
/* user land lock this */
|
||||
if (efw->dev_lock_count < 0) {
|
||||
err = -EBUSY;
|
||||
goto end;
|
||||
}
|
||||
if (efw->dev_lock_count < 0)
|
||||
return -EBUSY;
|
||||
|
||||
/* this is the first time */
|
||||
if (efw->dev_lock_count++ == 0)
|
||||
snd_efw_stream_lock_changed(efw);
|
||||
err = 0;
|
||||
end:
|
||||
spin_unlock_irq(&efw->lock);
|
||||
return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void snd_efw_stream_lock_release(struct snd_efw *efw)
|
||||
{
|
||||
spin_lock_irq(&efw->lock);
|
||||
guard(spinlock_irq)(&efw->lock);
|
||||
|
||||
if (WARN_ON(efw->dev_lock_count <= 0))
|
||||
goto end;
|
||||
return;
|
||||
if (--efw->dev_lock_count == 0)
|
||||
snd_efw_stream_lock_changed(efw);
|
||||
end:
|
||||
spin_unlock_irq(&efw->lock);
|
||||
}
|
||||
|
||||
@@ -82,9 +82,9 @@ int snd_efw_transaction_run(struct fw_unit *unit,
|
||||
t.state = STATE_PENDING;
|
||||
init_waitqueue_head(&t.wait);
|
||||
|
||||
spin_lock_irq(&transaction_queues_lock);
|
||||
list_add_tail(&t.list, &transaction_queues);
|
||||
spin_unlock_irq(&transaction_queues_lock);
|
||||
scoped_guard(spinlock_irq, &transaction_queues_lock) {
|
||||
list_add_tail(&t.list, &transaction_queues);
|
||||
}
|
||||
|
||||
tries = 0;
|
||||
do {
|
||||
@@ -107,9 +107,9 @@ int snd_efw_transaction_run(struct fw_unit *unit,
|
||||
}
|
||||
} while (1);
|
||||
|
||||
spin_lock_irq(&transaction_queues_lock);
|
||||
list_del(&t.list);
|
||||
spin_unlock_irq(&transaction_queues_lock);
|
||||
scoped_guard(spinlock_irq, &transaction_queues_lock) {
|
||||
list_del(&t.list);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
|
||||
t = (struct snd_efw_transaction *)data;
|
||||
length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length);
|
||||
|
||||
spin_lock(&efw->lock);
|
||||
guard(spinlock)(&efw->lock);
|
||||
|
||||
if (efw->push_ptr < efw->pull_ptr)
|
||||
capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr);
|
||||
@@ -134,7 +134,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
|
||||
/* confirm enough space for this response */
|
||||
if (capacity < length) {
|
||||
*rcode = RCODE_CONFLICT_ERROR;
|
||||
goto end;
|
||||
return;
|
||||
}
|
||||
|
||||
/* copy to ring buffer */
|
||||
@@ -157,8 +157,6 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
|
||||
wake_up(&efw->hwdep_wait);
|
||||
|
||||
*rcode = RCODE_COMPLETE;
|
||||
end:
|
||||
spin_unlock_irq(&efw->lock);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -169,7 +167,7 @@ handle_resp_for_user(struct fw_card *card, int generation, int source,
|
||||
struct snd_efw *efw;
|
||||
unsigned int i;
|
||||
|
||||
spin_lock_irq(&instances_lock);
|
||||
guard(spinlock_irq)(&instances_lock);
|
||||
|
||||
for (i = 0; i < SNDRV_CARDS; i++) {
|
||||
efw = instances[i];
|
||||
@@ -186,11 +184,9 @@ handle_resp_for_user(struct fw_card *card, int generation, int source,
|
||||
break;
|
||||
}
|
||||
if (i == SNDRV_CARDS)
|
||||
goto end;
|
||||
return;
|
||||
|
||||
copy_resp_to_buf(efw, data, length, rcode);
|
||||
end:
|
||||
spin_unlock(&instances_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -199,9 +195,8 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source,
|
||||
{
|
||||
struct fw_device *device;
|
||||
struct transaction_queue *t;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&transaction_queues_lock, flags);
|
||||
guard(spinlock_irqsave)(&transaction_queues_lock);
|
||||
list_for_each_entry(t, &transaction_queues, list) {
|
||||
device = fw_parent_device(t->unit);
|
||||
if ((device->card != card) ||
|
||||
@@ -219,7 +214,6 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source,
|
||||
*rcode = RCODE_COMPLETE;
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&transaction_queues_lock, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -259,7 +253,7 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
spin_lock_irq(&instances_lock);
|
||||
guard(spinlock_irq)(&instances_lock);
|
||||
|
||||
for (i = 0; i < SNDRV_CARDS; i++) {
|
||||
if (instances[i] != NULL)
|
||||
@@ -267,30 +261,26 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw)
|
||||
instances[i] = efw;
|
||||
break;
|
||||
}
|
||||
|
||||
spin_unlock_irq(&instances_lock);
|
||||
}
|
||||
|
||||
void snd_efw_transaction_remove_instance(struct snd_efw *efw)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
spin_lock_irq(&instances_lock);
|
||||
guard(spinlock_irq)(&instances_lock);
|
||||
|
||||
for (i = 0; i < SNDRV_CARDS; i++) {
|
||||
if (instances[i] != efw)
|
||||
continue;
|
||||
instances[i] = NULL;
|
||||
}
|
||||
|
||||
spin_unlock_irq(&instances_lock);
|
||||
}
|
||||
|
||||
void snd_efw_transaction_bus_reset(struct fw_unit *unit)
|
||||
{
|
||||
struct transaction_queue *t;
|
||||
|
||||
spin_lock_irq(&transaction_queues_lock);
|
||||
guard(spinlock_irq)(&transaction_queues_lock);
|
||||
list_for_each_entry(t, &transaction_queues, list) {
|
||||
if ((t->unit == unit) &&
|
||||
(t->state == STATE_PENDING)) {
|
||||
@@ -298,7 +288,6 @@ void snd_efw_transaction_bus_reset(struct fw_unit *unit)
|
||||
wake_up(&t->wait);
|
||||
}
|
||||
}
|
||||
spin_unlock_irq(&transaction_queues_lock);
|
||||
}
|
||||
|
||||
static struct fw_address_handler resp_register_handler = {
|
||||
|
||||
Reference in New Issue
Block a user