summaryrefslogtreecommitdiff
path: root/sound/firewire/bebob
diff options
context:
space:
mode:
Diffstat (limited to 'sound/firewire/bebob')
-rw-r--r--sound/firewire/bebob/bebob.c36
-rw-r--r--sound/firewire/bebob/bebob_hwdep.c37
-rw-r--r--sound/firewire/bebob/bebob_maudio.c42
-rw-r--r--sound/firewire/bebob/bebob_midi.c34
-rw-r--r--sound/firewire/bebob/bebob_pcm.c70
-rw-r--r--sound/firewire/bebob/bebob_stream.c21
6 files changed, 91 insertions, 149 deletions
diff --git a/sound/firewire/bebob/bebob.c b/sound/firewire/bebob/bebob.c
index 4ebaeff16455..01e2c4cc03d4 100644
--- a/sound/firewire/bebob/bebob.c
+++ b/sound/firewire/bebob/bebob.c
@@ -122,9 +122,9 @@ bebob_card_free(struct snd_card *card)
{
struct snd_bebob *bebob = card->private_data;
- mutex_lock(&devices_mutex);
- clear_bit(bebob->card_index, devices_used);
- mutex_unlock(&devices_mutex);
+ scoped_guard(mutex, &devices_mutex) {
+ clear_bit(bebob->card_index, devices_used);
+ }
snd_bebob_stream_destroy_duplex(bebob);
@@ -207,25 +207,21 @@ static int bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *en
return -ENODEV;
}
- mutex_lock(&devices_mutex);
- for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
- if (!test_bit(card_index, devices_used) && enable[card_index])
- break;
- }
- if (card_index >= SNDRV_CARDS) {
- mutex_unlock(&devices_mutex);
- return -ENOENT;
- }
+ scoped_guard(mutex, &devices_mutex) {
+ for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
+ if (!test_bit(card_index, devices_used) && enable[card_index])
+ break;
+ }
+ if (card_index >= SNDRV_CARDS)
+ return -ENOENT;
- err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
- sizeof(*bebob), &card);
- if (err < 0) {
- mutex_unlock(&devices_mutex);
- return err;
+ err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
+ sizeof(*bebob), &card);
+ if (err < 0)
+ return err;
+ card->private_free = bebob_card_free;
+ set_bit(card_index, devices_used);
}
- card->private_free = bebob_card_free;
- set_bit(card_index, devices_used);
- mutex_unlock(&devices_mutex);
bebob = card->private_data;
bebob->unit = fw_unit_get(unit);
diff --git a/sound/firewire/bebob/bebob_hwdep.c b/sound/firewire/bebob/bebob_hwdep.c
index 5779e99a6bb2..216d1fceb6e7 100644
--- a/sound/firewire/bebob/bebob_hwdep.c
+++ b/sound/firewire/bebob/bebob_hwdep.c
@@ -53,18 +53,14 @@ static __poll_t
hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
{
struct snd_bebob *bebob = hwdep->private_data;
- __poll_t events;
poll_wait(file, &bebob->hwdep_wait, wait);
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_changed)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&bebob->lock);
-
- return events;
+ return 0;
}
static int
@@ -90,39 +86,27 @@ hwdep_get_info(struct snd_bebob *bebob, void __user *arg)
static int
hwdep_lock(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == 0) {
bebob->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&bebob->lock);
-
- return err;
}
static int
hwdep_unlock(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == -1) {
bebob->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&bebob->lock);
-
- return err;
}
static int
@@ -130,10 +114,9 @@ hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_bebob *bebob = hwdep->private_data;
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == -1)
bebob->dev_lock_count = 0;
- spin_unlock_irq(&bebob->lock);
return 0;
}
diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c
index 177699e1be11..376a9a175479 100644
--- a/sound/firewire/bebob/bebob_maudio.c
+++ b/sound/firewire/bebob/bebob_maudio.c
@@ -265,7 +265,7 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
if (!params)
return -ENOMEM;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
bebob->maudio_special_quirk = (void *)params;
params->is1814 = is1814;
@@ -277,12 +277,12 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
if (err < 0) {
dev_err(&bebob->unit->device,
"fail to initialize clock params: %d\n", err);
- goto end;
+ return err;
}
err = add_special_controls(bebob);
if (err < 0)
- goto end;
+ return err;
special_stream_formation_set(bebob);
@@ -293,8 +293,6 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
bebob->midi_input_ports = 2;
bebob->midi_output_ports = 2;
}
-end:
- mutex_unlock(&bebob->mutex);
return err;
}
@@ -383,14 +381,12 @@ static int special_clk_ctl_put(struct snd_kcontrol *kctl,
if (id >= ARRAY_SIZE(special_clk_types))
return -EINVAL;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob, id,
params->dig_in_fmt,
params->dig_out_fmt,
params->clk_lock);
- mutex_unlock(&bebob->mutex);
-
if (err >= 0)
err = 1;
@@ -456,14 +452,14 @@ static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
unsigned int dig_in_iface;
int err, val;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,
&dig_in_iface);
if (err < 0) {
dev_err(&bebob->unit->device,
"fail to get digital input interface: %d\n", err);
- goto end;
+ return err;
}
/* encoded id for user value */
@@ -474,9 +470,7 @@ static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
val = 2;
uval->value.enumerated.item[0] = val;
-end:
- mutex_unlock(&bebob->mutex);
- return err;
+ return 0;
}
static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *uval)
@@ -494,7 +488,7 @@ static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
dig_in_fmt = (id >> 1) & 0x01;
dig_in_iface = id & 0x01;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob,
params->clk_src,
@@ -502,24 +496,19 @@ static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
params->dig_out_fmt,
params->clk_lock);
if (err < 0)
- goto end;
+ return err;
/* For ADAT, optical interface is only available. */
- if (params->dig_in_fmt > 0) {
- err = 1;
- goto end;
- }
+ if (params->dig_in_fmt > 0)
+ return 1;
/* For S/PDIF, optical/coaxial interfaces are selectable. */
err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);
if (err < 0)
dev_err(&bebob->unit->device,
"fail to set digital input interface: %d\n", err);
- err = 1;
-end:
special_stream_formation_set(bebob);
- mutex_unlock(&bebob->mutex);
- return err;
+ return 1;
}
static const struct snd_kcontrol_new special_dig_in_iface_ctl = {
.name = "Digital Input Interface",
@@ -546,9 +535,9 @@ static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
{
struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
struct special_params *params = bebob->maudio_special_quirk;
- mutex_lock(&bebob->mutex);
+
+ guard(mutex)(&bebob->mutex);
uval->value.enumerated.item[0] = params->dig_out_fmt;
- mutex_unlock(&bebob->mutex);
return 0;
}
static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
@@ -563,7 +552,7 @@ static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
if (id >= ARRAY_SIZE(special_dig_out_iface_labels))
return -EINVAL;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob,
params->clk_src,
@@ -574,7 +563,6 @@ static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
err = 1;
}
- mutex_unlock(&bebob->mutex);
return err;
}
static const struct snd_kcontrol_new special_dig_out_iface_ctl = {
diff --git a/sound/firewire/bebob/bebob_midi.c b/sound/firewire/bebob/bebob_midi.c
index b1425bf98c3b..678631f31d3c 100644
--- a/sound/firewire/bebob/bebob_midi.c
+++ b/sound/firewire/bebob/bebob_midi.c
@@ -16,15 +16,15 @@ static int midi_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&bebob->mutex);
- err = snd_bebob_stream_reserve_duplex(bebob, 0, 0, 0);
- if (err >= 0) {
- ++bebob->substreams_counter;
- err = snd_bebob_stream_start_duplex(bebob);
- if (err < 0)
- --bebob->substreams_counter;
+ scoped_guard(mutex, &bebob->mutex) {
+ err = snd_bebob_stream_reserve_duplex(bebob, 0, 0, 0);
+ if (err >= 0) {
+ ++bebob->substreams_counter;
+ err = snd_bebob_stream_start_duplex(bebob);
+ if (err < 0)
+ --bebob->substreams_counter;
+ }
}
- mutex_unlock(&bebob->mutex);
if (err < 0)
snd_bebob_stream_lock_release(bebob);
@@ -35,10 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_bebob *bebob = substream->rmidi->private_data;
- mutex_lock(&bebob->mutex);
- bebob->substreams_counter--;
- snd_bebob_stream_stop_duplex(bebob);
- mutex_unlock(&bebob->mutex);
+ scoped_guard(mutex, &bebob->mutex) {
+ bebob->substreams_counter--;
+ snd_bebob_stream_stop_duplex(bebob);
+ }
snd_bebob_stream_lock_release(bebob);
return 0;
@@ -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_bebob *bebob = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&bebob->lock, flags);
+ guard(spinlock_irqsave)(&bebob->lock);
if (up)
amdtp_am824_midi_trigger(&bebob->tx_stream,
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&bebob->tx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&bebob->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_bebob *bebob = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&bebob->lock, flags);
+ guard(spinlock_irqsave)(&bebob->lock);
if (up)
amdtp_am824_midi_trigger(&bebob->rx_stream,
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&bebob->rx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&bebob->lock, flags);
}
static void set_midi_substream_names(struct snd_bebob *bebob,
diff --git a/sound/firewire/bebob/bebob_pcm.c b/sound/firewire/bebob/bebob_pcm.c
index 360ebf3c4ca2..692d33bac2d2 100644
--- a/sound/firewire/bebob/bebob_pcm.c
+++ b/sound/firewire/bebob/bebob_pcm.c
@@ -149,49 +149,42 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto err_locked;
- mutex_lock(&bebob->mutex);
-
- // When source of clock is not internal or any stream is reserved for
- // transmission of PCM frames, the available sampling rate is limited
- // at current one.
- if (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL ||
- (bebob->substreams_counter > 0 && d->events_per_period > 0)) {
- unsigned int frames_per_period = d->events_per_period;
- unsigned int frames_per_buffer = d->events_per_buffer;
- unsigned int sampling_rate;
-
- err = spec->get(bebob, &sampling_rate);
- if (err < 0) {
- mutex_unlock(&bebob->mutex);
- dev_err(&bebob->unit->device,
- "fail to get sampling rate: %d\n", err);
- goto err_locked;
- }
-
- substream->runtime->hw.rate_min = sampling_rate;
- substream->runtime->hw.rate_max = sampling_rate;
-
- if (frames_per_period > 0) {
- err = snd_pcm_hw_constraint_minmax(substream->runtime,
- SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
- frames_per_period, frames_per_period);
+ scoped_guard(mutex, &bebob->mutex) {
+ // When source of clock is not internal or any stream is reserved for
+ // transmission of PCM frames, the available sampling rate is limited
+ // at current one.
+ if (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL ||
+ (bebob->substreams_counter > 0 && d->events_per_period > 0)) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
+ unsigned int sampling_rate;
+
+ err = spec->get(bebob, &sampling_rate);
if (err < 0) {
- mutex_unlock(&bebob->mutex);
+ dev_err(&bebob->unit->device,
+ "fail to get sampling rate: %d\n", err);
goto err_locked;
}
- err = snd_pcm_hw_constraint_minmax(substream->runtime,
- SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
- frames_per_buffer, frames_per_buffer);
- if (err < 0) {
- mutex_unlock(&bebob->mutex);
- goto err_locked;
+ substream->runtime->hw.rate_min = sampling_rate;
+ substream->runtime->hw.rate_max = sampling_rate;
+
+ if (frames_per_period > 0) {
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+ frames_per_period, frames_per_period);
+ if (err < 0)
+ goto err_locked;
+
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+ frames_per_buffer, frames_per_buffer);
+ if (err < 0)
+ goto err_locked;
}
}
}
- mutex_unlock(&bebob->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -219,12 +212,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
unsigned int frames_per_period = params_period_size(hw_params);
unsigned int frames_per_buffer = params_buffer_size(hw_params);
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = snd_bebob_stream_reserve_duplex(bebob, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++bebob->substreams_counter;
- mutex_unlock(&bebob->mutex);
}
return err;
@@ -234,15 +226,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_bebob *bebob = substream->private_data;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
bebob->substreams_counter--;
snd_bebob_stream_stop_duplex(bebob);
- mutex_unlock(&bebob->mutex);
-
return 0;
}
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
index 8629b14ded76..449cb17717f0 100644
--- a/sound/firewire/bebob/bebob_stream.c
+++ b/sound/firewire/bebob/bebob_stream.c
@@ -964,33 +964,24 @@ void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
/* user land lock this */
- if (bebob->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (bebob->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (bebob->dev_lock_count++ == 0)
snd_bebob_stream_lock_changed(bebob);
- err = 0;
-end:
- spin_unlock_irq(&bebob->lock);
- return err;
+ return 0;
}
void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
{
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (WARN_ON(bebob->dev_lock_count <= 0))
- goto end;
+ return;
if (--bebob->dev_lock_count == 0)
snd_bebob_stream_lock_changed(bebob);
-end:
- spin_unlock_irq(&bebob->lock);
}