Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
.../motu/motu-command-dsp-message-parser.c | 9 ++----
sound/firewire/motu/motu-hwdep.c | 30 +++++--------------
sound/firewire/motu/motu-midi.c | 10 ++-----
.../motu/motu-register-dsp-message-parser.c | 18 +++--------
sound/firewire/motu/motu-stream.c | 21 ++++---------
sound/firewire/motu/motu-transaction.c | 7 ++---
6 files changed, 25 insertions(+), 70 deletions(-)
diff --git a/sound/firewire/motu/motu-command-dsp-message-parser.c b/sound/firewire/motu/motu-command-dsp-message-parser.c
index 5d8a86a12f1f..c6440e6e360b 100644
--- a/sound/firewire/motu/motu-command-dsp-message-parser.c
+++ b/sound/firewire/motu/motu-command-dsp-message-parser.c
@@ -87,10 +87,9 @@ void snd_motu_command_dsp_message_parser_parse(const struct amdtp_stream *s,
unsigned int data_block_quadlets = s->data_block_quadlets;
struct msg_parser *parser = motu->message_parser;
unsigned int interval = parser->interval;
- unsigned long flags;
int i;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
for (i = 0; i < count; ++i) {
__be32 *buffer = desc->ctx_payload;
@@ -168,17 +167,13 @@ void snd_motu_command_dsp_message_parser_parse(const struct amdtp_stream *s,
}
}
}
-
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_command_dsp_message_parser_copy_meter(struct snd_motu *motu,
struct snd_firewire_motu_command_dsp_meter *meter)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(meter, &parser->meter, sizeof(*meter));
- spin_unlock_irqrestore(&parser->lock, flags);
}
diff --git a/sound/firewire/motu/motu-hwdep.c b/sound/firewire/motu/motu-hwdep.c
index 1ed60618220d..e0ce1e8703f5 100644
--- a/sound/firewire/motu/motu-hwdep.c
+++ b/sound/firewire/motu/motu-hwdep.c
@@ -104,12 +104,11 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_wait(file, &motu->hwdep_wait, wait);
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_changed || motu->msg || has_dsp_event(motu))
events = EPOLLIN | EPOLLRDNORM;
else
events = 0;
- spin_unlock_irq(&motu->lock);
return events | EPOLLOUT;
}
@@ -135,48 +134,35 @@ static int hwdep_get_info(struct snd_motu *motu, void __user *arg)
static int hwdep_lock(struct snd_motu *motu)
{
- int err;
-
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == 0) {
motu->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&motu->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_motu *motu)
{
- int err;
-
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == -1) {
motu->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&motu->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_motu *motu = hwdep->private_data;
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == -1)
motu->dev_lock_count = 0;
- spin_unlock_irq(&motu->lock);
return 0;
}
diff --git a/sound/firewire/motu/motu-midi.c b/sound/firewire/motu/motu-midi.c
index 18c5734e999f..85e3260f9349 100644
--- a/sound/firewire/motu/motu-midi.c
+++ b/sound/firewire/motu/motu-midi.c
@@ -47,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_motu *motu = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&motu->lock, flags);
+ guard(spinlock_irqsave)(&motu->lock);
if (up)
amdtp_motu_midi_trigger(&motu->tx_stream, substrm->number,
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_motu_midi_trigger(&motu->tx_stream, substrm->number,
NULL);
-
- spin_unlock_irqrestore(&motu->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_motu *motu = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&motu->lock, flags);
+ guard(spinlock_irqsave)(&motu->lock);
if (up)
amdtp_motu_midi_trigger(&motu->rx_stream, substrm->number,
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_motu_midi_trigger(&motu->rx_stream, substrm->number,
NULL);
-
- spin_unlock_irqrestore(&motu->lock, flags);
}
static void set_midi_substream_names(struct snd_motu *motu,
diff --git a/sound/firewire/motu/motu-register-dsp-message-parser.c b/sound/firewire/motu/motu-register-dsp-message-parser.c
index ef3b0b0f0dab..a8053e3ef065 100644
--- a/sound/firewire/motu/motu-register-dsp-message-parser.c
+++ b/sound/firewire/motu/motu-register-dsp-message-parser.c
@@ -150,10 +150,9 @@ void snd_motu_register_dsp_message_parser_parse(const struct amdtp_stream *s,
struct msg_parser *parser = motu->message_parser;
bool meter_pos_quirk = parser->meter_pos_quirk;
unsigned int pos = parser->push_pos;
- unsigned long flags;
int i;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
for (i = 0; i < count; ++i) {
__be32 *buffer = desc->ctx_payload;
@@ -363,30 +362,24 @@ void snd_motu_register_dsp_message_parser_parse(const struct amdtp_stream *s,
if (pos != parser->push_pos)
wake_up(&motu->hwdep_wait);
-
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_register_dsp_message_parser_copy_meter(struct snd_motu *motu,
struct snd_firewire_motu_register_dsp_meter *meter)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(meter, &parser->meter, sizeof(*meter));
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_register_dsp_message_parser_copy_parameter(struct snd_motu *motu,
struct snd_firewire_motu_register_dsp_parameter *param)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(param, &parser->param, sizeof(*param));
- spin_unlock_irqrestore(&parser->lock, flags);
}
unsigned int snd_motu_register_dsp_message_parser_count_event(struct snd_motu *motu)
@@ -403,12 +396,11 @@ bool snd_motu_register_dsp_message_parser_copy_event(struct snd_motu *motu, u32
{
struct msg_parser *parser = motu->message_parser;
unsigned int pos = parser->pull_pos;
- unsigned long flags;
if (pos == parser->push_pos)
return false;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
*event = parser->event_queue[pos];
@@ -417,7 +409,5 @@ bool snd_motu_register_dsp_message_parser_copy_event(struct snd_motu *motu, u32
pos = 0;
parser->pull_pos = pos;
- spin_unlock_irqrestore(&parser->lock, flags);
-
return true;
}
diff --git a/sound/firewire/motu/motu-stream.c b/sound/firewire/motu/motu-stream.c
index 64aec9c3eefd..e5f21360cfb7 100644
--- a/sound/firewire/motu/motu-stream.c
+++ b/sound/firewire/motu/motu-stream.c
@@ -407,32 +407,23 @@ static void motu_lock_changed(struct snd_motu *motu)
int snd_motu_stream_lock_try(struct snd_motu *motu)
{
- int err;
+ guard(spinlock_irq)(&motu->lock);
- spin_lock_irq(&motu->lock);
-
- if (motu->dev_lock_count < 0) {
- err = -EBUSY;
- goto out;
- }
+ if (motu->dev_lock_count < 0)
+ return -EBUSY;
if (motu->dev_lock_count++ == 0)
motu_lock_changed(motu);
- err = 0;
-out:
- spin_unlock_irq(&motu->lock);
- return err;
+ return 0;
}
void snd_motu_stream_lock_release(struct snd_motu *motu)
{
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (WARN_ON(motu->dev_lock_count <= 0))
- goto out;
+ return;
if (--motu->dev_lock_count == 0)
motu_lock_changed(motu);
-out:
- spin_unlock_irq(&motu->lock);
}
diff --git a/sound/firewire/motu/motu-transaction.c b/sound/firewire/motu/motu-transaction.c
index 2dc1d6e59144..804f4208cf81 100644
--- a/sound/firewire/motu/motu-transaction.c
+++ b/sound/firewire/motu/motu-transaction.c
@@ -51,7 +51,6 @@ static void handle_message(struct fw_card *card, struct fw_request *request,
{
struct snd_motu *motu = callback_data;
__be32 *buf = (__be32 *)data;
- unsigned long flags;
if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
fw_send_response(card, request, RCODE_COMPLETE);
@@ -63,9 +62,9 @@ static void handle_message(struct fw_card *card, struct fw_request *request,
return;
}
- spin_lock_irqsave(&motu->lock, flags);
- motu->msg = be32_to_cpu(*buf);
- spin_unlock_irqrestore(&motu->lock, flags);
+ scoped_guard(spinlock_irqsave, &motu->lock) {
+ motu->msg = be32_to_cpu(*buf);
+ }
fw_send_response(card, request, RCODE_COMPLETE);
--
2.50.1
[Index of Archives]
[Pulseaudio]
[Linux Audio Users]
[ALSA Devel]
[Fedora Desktop]
[Fedora SELinux]
[Big List of Linux Books]
[Yosemite News]
[KDE Users]