summaryrefslogtreecommitdiff
path: root/sound/firewire/iso-resources.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/firewire/iso-resources.c')
-rw-r--r--sound/firewire/iso-resources.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/sound/firewire/iso-resources.c b/sound/firewire/iso-resources.c
index 84f71b2eaa82..4f63279225c5 100644
--- a/sound/firewire/iso-resources.c
+++ b/sound/firewire/iso-resources.c
@@ -114,38 +114,34 @@ int fw_iso_resources_allocate(struct fw_iso_resources *r,
r->bandwidth = packet_bandwidth(max_payload_bytes, speed);
retry_after_bus_reset:
- spin_lock_irq(&card->lock);
- r->generation = card->generation;
- r->bandwidth_overhead = current_bandwidth_overhead(card);
- spin_unlock_irq(&card->lock);
+ scoped_guard(spinlock_irq, &card->lock) {
+ r->generation = card->generation;
+ r->bandwidth_overhead = current_bandwidth_overhead(card);
+ }
err = wait_isoch_resource_delay_after_bus_reset(card);
if (err < 0)
return err;
- mutex_lock(&r->mutex);
-
- bandwidth = r->bandwidth + r->bandwidth_overhead;
- fw_iso_resource_manage(card, r->generation, r->channels_mask,
- &channel, &bandwidth, true);
- if (channel == -EAGAIN) {
- mutex_unlock(&r->mutex);
- goto retry_after_bus_reset;
- }
- if (channel >= 0) {
- r->channel = channel;
- r->allocated = true;
- } else {
- if (channel == -EBUSY)
- dev_err(&r->unit->device,
- "isochronous resources exhausted\n");
- else
- dev_err(&r->unit->device,
- "isochronous resource allocation failed\n");
+ scoped_guard(mutex, &r->mutex) {
+ bandwidth = r->bandwidth + r->bandwidth_overhead;
+ fw_iso_resource_manage(card, r->generation, r->channels_mask,
+ &channel, &bandwidth, true);
+ if (channel == -EAGAIN)
+ goto retry_after_bus_reset;
+ if (channel >= 0) {
+ r->channel = channel;
+ r->allocated = true;
+ } else {
+ if (channel == -EBUSY)
+ dev_err(&r->unit->device,
+ "isochronous resources exhausted\n");
+ else
+ dev_err(&r->unit->device,
+ "isochronous resource allocation failed\n");
+ }
}
- mutex_unlock(&r->mutex);
-
return channel;
}
EXPORT_SYMBOL(fw_iso_resources_allocate);
@@ -166,17 +162,15 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
struct fw_card *card = fw_parent_device(r->unit)->card;
int bandwidth, channel;
- mutex_lock(&r->mutex);
+ guard(mutex)(&r->mutex);
- if (!r->allocated) {
- mutex_unlock(&r->mutex);
+ if (!r->allocated)
return 0;
- }
- spin_lock_irq(&card->lock);
- r->generation = card->generation;
- r->bandwidth_overhead = current_bandwidth_overhead(card);
- spin_unlock_irq(&card->lock);
+ scoped_guard(spinlock_irq, &card->lock) {
+ r->generation = card->generation;
+ r->bandwidth_overhead = current_bandwidth_overhead(card);
+ }
bandwidth = r->bandwidth + r->bandwidth_overhead;
@@ -196,8 +190,6 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
"isochronous resource allocation failed\n");
}
- mutex_unlock(&r->mutex);
-
return channel;
}
EXPORT_SYMBOL(fw_iso_resources_update);
@@ -218,7 +210,7 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
return;
card = fw_parent_device(r->unit)->card;
- mutex_lock(&r->mutex);
+ guard(mutex)(&r->mutex);
if (r->allocated) {
bandwidth = r->bandwidth + r->bandwidth_overhead;
@@ -230,7 +222,5 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
r->allocated = false;
}
-
- mutex_unlock(&r->mutex);
}
EXPORT_SYMBOL(fw_iso_resources_free);