diff mbox

[1/6] bebob: Arrangement for critical section to be shorter

Message ID 1405908605-8105-2-git-send-email-o-takashi@sakamocchi.jp (mailing list archive)
State Accepted
Delegated to: Takashi Iwai
Headers show

Commit Message

Takashi Sakamoto July 21, 2014, 2:10 a.m. UTC
Cc: Wei Yongjun <weiyj_lk@163.com>

This commit move some mutex_lock() to shorten critical section in some
functions. This commit is my solution for this post.

[PATCH -next] ALSA: bebob: Fix missing unlock on error in special_clk_ctl_put()
https://lkml.org/lkml/2014/7/20/12

This commit also renames a function for my naming consistency.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/bebob/bebob_maudio.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c
index 6af50eb..0a33045 100644
--- a/sound/firewire/bebob/bebob_maudio.c
+++ b/sound/firewire/bebob/bebob_maudio.c
@@ -372,23 +372,24 @@  static int special_clk_ctl_get(struct snd_kcontrol *kctl,
 	uval->value.enumerated.item[0] = params->clk_src;
 	return 0;
 }
-static int special_clk_ctl_put(struct snd_kcontrol *kctl,
+static int special_clk_ctl_set(struct snd_kcontrol *kctl,
 			       struct snd_ctl_elem_value *uval)
 {
 	struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
 	struct special_params *params = bebob->maudio_special_quirk;
 	int err, id;
 
-	mutex_lock(&bebob->mutex);
-
 	id = uval->value.enumerated.item[0];
 	if (id >= ARRAY_SIZE(special_clk_labels))
 		return 0;
 
+	mutex_lock(&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);
 
 	return err >= 0;
@@ -399,7 +400,7 @@  static struct snd_kcontrol_new special_clk_ctl = {
 	.access	= SNDRV_CTL_ELEM_ACCESS_READWRITE,
 	.info	= special_clk_ctl_info,
 	.get	= special_clk_ctl_get,
-	.put	= special_clk_ctl_put
+	.put	= special_clk_ctl_set
 };
 
 /* Clock synchronization control for special firmware */
@@ -491,14 +492,14 @@  static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
 	unsigned int id, dig_in_fmt, dig_in_iface;
 	int err;
 
-	mutex_lock(&bebob->mutex);
-
 	id = uval->value.enumerated.item[0];
 
 	/* decode user value */
 	dig_in_fmt = (id >> 1) & 0x01;
 	dig_in_iface = id & 0x01;
 
+	mutex_lock(&bebob->mutex);
+
 	err = avc_maudio_set_special_clk(bebob,
 					 params->clk_src,
 					 dig_in_fmt,
@@ -558,10 +559,10 @@  static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
 	unsigned int id;
 	int err;
 
-	mutex_lock(&bebob->mutex);
-
 	id = uval->value.enumerated.item[0];
 
+	mutex_lock(&bebob->mutex);
+
 	err = avc_maudio_set_special_clk(bebob,
 					 params->clk_src,
 					 params->dig_in_fmt,