mirror of https://github.com/torvalds/linux.git
ALSA: firewire: lib: Use guard() for mutex locks
Replace the manual mutex lock/unlock pairs with guard() for code simplification. Only 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-11-tiwai@suse.de
This commit is contained in:
parent
b8ed2b1432
commit
6061b4accb
|
|
@ -1688,20 +1688,16 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
|
||||||
struct pkt_desc *descs;
|
struct pkt_desc *descs;
|
||||||
int i, type, tag, err;
|
int i, type, tag, err;
|
||||||
|
|
||||||
mutex_lock(&s->mutex);
|
guard(mutex)(&s->mutex);
|
||||||
|
|
||||||
if (WARN_ON(amdtp_stream_running(s) ||
|
if (WARN_ON(amdtp_stream_running(s) ||
|
||||||
(s->data_block_quadlets < 1))) {
|
(s->data_block_quadlets < 1)))
|
||||||
err = -EBADFD;
|
return -EBADFD;
|
||||||
goto err_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->direction == AMDTP_IN_STREAM) {
|
if (s->direction == AMDTP_IN_STREAM) {
|
||||||
// NOTE: IT context should be used for constant IRQ.
|
// NOTE: IT context should be used for constant IRQ.
|
||||||
if (is_irq_target) {
|
if (is_irq_target)
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->data_block_counter = UINT_MAX;
|
s->data_block_counter = UINT_MAX;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1725,7 +1721,7 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
|
||||||
|
|
||||||
err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, max_ctx_payload_size, dir);
|
err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, max_ctx_payload_size, dir);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto err_unlock;
|
return err;
|
||||||
s->queue_size = queue_size;
|
s->queue_size = queue_size;
|
||||||
|
|
||||||
s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
|
s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
|
||||||
|
|
@ -1846,8 +1842,6 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto err_pkt_descs;
|
goto err_pkt_descs;
|
||||||
|
|
||||||
mutex_unlock(&s->mutex);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err_pkt_descs:
|
err_pkt_descs:
|
||||||
kfree(s->packet_descs);
|
kfree(s->packet_descs);
|
||||||
|
|
@ -1863,8 +1857,6 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
|
||||||
s->context = ERR_PTR(-1);
|
s->context = ERR_PTR(-1);
|
||||||
err_buffer:
|
err_buffer:
|
||||||
iso_packets_buffer_destroy(&s->buffer, s->unit);
|
iso_packets_buffer_destroy(&s->buffer, s->unit);
|
||||||
err_unlock:
|
|
||||||
mutex_unlock(&s->mutex);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
@ -1934,12 +1926,10 @@ EXPORT_SYMBOL(amdtp_stream_update);
|
||||||
*/
|
*/
|
||||||
static void amdtp_stream_stop(struct amdtp_stream *s)
|
static void amdtp_stream_stop(struct amdtp_stream *s)
|
||||||
{
|
{
|
||||||
mutex_lock(&s->mutex);
|
guard(mutex)(&s->mutex);
|
||||||
|
|
||||||
if (!amdtp_stream_running(s)) {
|
if (!amdtp_stream_running(s))
|
||||||
mutex_unlock(&s->mutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
cancel_work_sync(&s->period_work);
|
cancel_work_sync(&s->period_work);
|
||||||
fw_iso_context_stop(s->context);
|
fw_iso_context_stop(s->context);
|
||||||
|
|
@ -1955,8 +1945,6 @@ static void amdtp_stream_stop(struct amdtp_stream *s)
|
||||||
if (s->domain->replay.enable)
|
if (s->domain->replay.enable)
|
||||||
kfree(s->ctx_data.tx.cache.descs);
|
kfree(s->ctx_data.tx.cache.descs);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&s->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -188,32 +188,23 @@ EXPORT_SYMBOL(cmp_connection_destroy);
|
||||||
int cmp_connection_reserve(struct cmp_connection *c,
|
int cmp_connection_reserve(struct cmp_connection *c,
|
||||||
unsigned int max_payload_bytes)
|
unsigned int max_payload_bytes)
|
||||||
{
|
{
|
||||||
int err;
|
guard(mutex)(&c->mutex);
|
||||||
|
|
||||||
mutex_lock(&c->mutex);
|
if (WARN_ON(c->resources.allocated))
|
||||||
|
return -EBUSY;
|
||||||
if (WARN_ON(c->resources.allocated)) {
|
|
||||||
err = -EBUSY;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->speed = min(c->max_speed,
|
c->speed = min(c->max_speed,
|
||||||
fw_parent_device(c->resources.unit)->max_speed);
|
fw_parent_device(c->resources.unit)->max_speed);
|
||||||
|
|
||||||
err = fw_iso_resources_allocate(&c->resources, max_payload_bytes,
|
return fw_iso_resources_allocate(&c->resources, max_payload_bytes,
|
||||||
c->speed);
|
c->speed);
|
||||||
end:
|
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(cmp_connection_reserve);
|
EXPORT_SYMBOL(cmp_connection_reserve);
|
||||||
|
|
||||||
void cmp_connection_release(struct cmp_connection *c)
|
void cmp_connection_release(struct cmp_connection *c)
|
||||||
{
|
{
|
||||||
mutex_lock(&c->mutex);
|
guard(mutex)(&c->mutex);
|
||||||
fw_iso_resources_free(&c->resources);
|
fw_iso_resources_free(&c->resources);
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(cmp_connection_release);
|
EXPORT_SYMBOL(cmp_connection_release);
|
||||||
|
|
||||||
|
|
@ -304,12 +295,10 @@ int cmp_connection_establish(struct cmp_connection *c)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
mutex_lock(&c->mutex);
|
guard(mutex)(&c->mutex);
|
||||||
|
|
||||||
if (WARN_ON(c->connected)) {
|
if (WARN_ON(c->connected))
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
}
|
|
||||||
|
|
||||||
retry_after_bus_reset:
|
retry_after_bus_reset:
|
||||||
if (c->direction == CMP_OUTPUT)
|
if (c->direction == CMP_OUTPUT)
|
||||||
|
|
@ -327,8 +316,6 @@ int cmp_connection_establish(struct cmp_connection *c)
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
c->connected = true;
|
c->connected = true;
|
||||||
|
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(cmp_connection_establish);
|
EXPORT_SYMBOL(cmp_connection_establish);
|
||||||
|
|
@ -350,19 +337,15 @@ void cmp_connection_break(struct cmp_connection *c)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
mutex_lock(&c->mutex);
|
guard(mutex)(&c->mutex);
|
||||||
|
|
||||||
if (!c->connected) {
|
if (!c->connected)
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
err = pcr_modify(c, pcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);
|
err = pcr_modify(c, pcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
cmp_error(c, "plug is still connected\n");
|
cmp_error(c, "plug is still connected\n");
|
||||||
|
|
||||||
c->connected = false;
|
c->connected = false;
|
||||||
|
|
||||||
mutex_unlock(&c->mutex);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(cmp_connection_break);
|
EXPORT_SYMBOL(cmp_connection_break);
|
||||||
|
|
|
||||||
|
|
@ -123,28 +123,24 @@ int fw_iso_resources_allocate(struct fw_iso_resources *r,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
mutex_lock(&r->mutex);
|
scoped_guard(mutex, &r->mutex) {
|
||||||
|
bandwidth = r->bandwidth + r->bandwidth_overhead;
|
||||||
bandwidth = r->bandwidth + r->bandwidth_overhead;
|
fw_iso_resource_manage(card, r->generation, r->channels_mask,
|
||||||
fw_iso_resource_manage(card, r->generation, r->channels_mask,
|
&channel, &bandwidth, true);
|
||||||
&channel, &bandwidth, true);
|
if (channel == -EAGAIN)
|
||||||
if (channel == -EAGAIN) {
|
goto retry_after_bus_reset;
|
||||||
mutex_unlock(&r->mutex);
|
if (channel >= 0) {
|
||||||
goto retry_after_bus_reset;
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
@ -166,12 +162,10 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
|
||||||
struct fw_card *card = fw_parent_device(r->unit)->card;
|
struct fw_card *card = fw_parent_device(r->unit)->card;
|
||||||
int bandwidth, channel;
|
int bandwidth, channel;
|
||||||
|
|
||||||
mutex_lock(&r->mutex);
|
guard(mutex)(&r->mutex);
|
||||||
|
|
||||||
if (!r->allocated) {
|
if (!r->allocated)
|
||||||
mutex_unlock(&r->mutex);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irq(&card->lock);
|
spin_lock_irq(&card->lock);
|
||||||
r->generation = card->generation;
|
r->generation = card->generation;
|
||||||
|
|
@ -196,8 +190,6 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
|
||||||
"isochronous resource allocation failed\n");
|
"isochronous resource allocation failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&r->mutex);
|
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(fw_iso_resources_update);
|
EXPORT_SYMBOL(fw_iso_resources_update);
|
||||||
|
|
@ -218,7 +210,7 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
|
||||||
return;
|
return;
|
||||||
card = fw_parent_device(r->unit)->card;
|
card = fw_parent_device(r->unit)->card;
|
||||||
|
|
||||||
mutex_lock(&r->mutex);
|
guard(mutex)(&r->mutex);
|
||||||
|
|
||||||
if (r->allocated) {
|
if (r->allocated) {
|
||||||
bandwidth = r->bandwidth + r->bandwidth_overhead;
|
bandwidth = r->bandwidth + r->bandwidth_overhead;
|
||||||
|
|
@ -230,7 +222,5 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
|
||||||
|
|
||||||
r->allocated = false;
|
r->allocated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&r->mutex);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(fw_iso_resources_free);
|
EXPORT_SYMBOL(fw_iso_resources_free);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue