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;
.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));
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;
}
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
{
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;
}
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,
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,
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,
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);
}
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 {
}
} 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;
}
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);
/* confirm enough space for this response */
if (capacity < length) {
*rcode = RCODE_CONFLICT_ERROR;
- goto end;
+ return;
}
/* copy to ring buffer */
wake_up(&efw->hwdep_wait);
*rcode = RCODE_COMPLETE;
-end:
- spin_unlock_irq(&efw->lock);
}
static void
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];
break;
}
if (i == SNDRV_CARDS)
- goto end;
+ return;
copy_resp_to_buf(efw, data, length, rcode);
-end:
- spin_unlock(&instances_lock);
}
static void
{
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) ||
*rcode = RCODE_COMPLETE;
}
}
- spin_unlock_irqrestore(&transaction_queues_lock, flags);
}
static void
{
unsigned int i;
- spin_lock_irq(&instances_lock);
+ guard(spinlock_irq)(&instances_lock);
for (i = 0; i < SNDRV_CARDS; i++) {
if (instances[i] != NULL)
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)) {
wake_up(&t->wait);
}
}
- spin_unlock_irq(&transaction_queues_lock);
}
static struct fw_address_handler resp_register_handler = {