From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
Reviewed-by: Charles Keepax <[email protected]>
Signed-off-by: bui duc phuc <[email protected]>
---
Changes in v2:
- Add Reviewed-by tags from Charles
- Remove the temporary `ret` variable and return directly in
madera_adsp_rate_put().
sound/soc/codecs/madera.c | 39 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/sound/soc/codecs/madera.c b/sound/soc/codecs/madera.c
index 98d72db599d8..55ea6950ca90 100644
--- a/sound/soc/codecs/madera.c
+++ b/sound/soc/codecs/madera.c
@@ -6,6 +6,7 @@
// Cirrus Logic International Semiconductor Ltd.
//
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/gcd.h>
#include <linux/module.h>
@@ -513,7 +514,7 @@ int madera_domain_clk_ev(struct snd_soc_dapm_widget *w,
* We can't rely on the DAPM mutex for locking because we need a lock
* that can safely be called in hw_params
*/
- mutex_lock(&priv->rate_lock);
+ guard(mutex)(&priv->rate_lock);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
@@ -532,8 +533,6 @@ int madera_domain_clk_ev(struct snd_soc_dapm_widget *w,
madera_debug_dump_domain_groups(priv);
- mutex_unlock(&priv->rate_lock);
-
return 0;
}
EXPORT_SYMBOL_GPL(madera_domain_clk_ev);
@@ -875,9 +874,8 @@ static int madera_adsp_rate_get(struct snd_kcontrol *kcontrol,
const int adsp_num = e->shift_l;
int item;
- mutex_lock(&priv->rate_lock);
- cached_rate = priv->adsp_rate_cache[adsp_num];
- mutex_unlock(&priv->rate_lock);
+ scoped_guard(mutex, &priv->rate_lock)
+ cached_rate = priv->adsp_rate_cache[adsp_num];
item = snd_soc_enum_val_to_item(e, cached_rate);
ucontrol->value.enumerated.item[0] = item;
@@ -893,7 +891,6 @@ static int madera_adsp_rate_put(struct snd_kcontrol *kcontrol,
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
const int adsp_num = e->shift_l;
const unsigned int item = ucontrol->value.enumerated.item[0];
- int ret = 0;
if (item >= e->items)
return -EINVAL;
@@ -903,22 +900,20 @@ static int madera_adsp_rate_put(struct snd_kcontrol *kcontrol,
* maintain consistent behaviour that rate domains cannot be changed
* while in use since this is a hardware requirement
*/
- mutex_lock(&priv->rate_lock);
+ guard(mutex)(&priv->rate_lock);
if (!madera_can_change_grp_rate(priv, priv->adsp[adsp_num].cs_dsp.base)) {
dev_warn(priv->madera->dev,
"Cannot change '%s' while in use by active audio paths\n",
kcontrol->id.name);
- ret = -EBUSY;
+ return -EBUSY;
} else if (priv->adsp_rate_cache[adsp_num] != e->values[item]) {
/* Volatile register so defer until the codec is powered up */
priv->adsp_rate_cache[adsp_num] = e->values[item];
- ret = 1;
+ return 1;
}
- mutex_unlock(&priv->rate_lock);
-
- return ret;
+ return 0;
}
static const struct soc_enum madera_adsp_rate_enum[] = {
@@ -1061,15 +1056,13 @@ int madera_rate_put(struct snd_kcontrol *kcontrol,
* Prevent the domain powering up while we're checking whether it's
* safe to change rate domain
*/
- mutex_lock(&priv->rate_lock);
+ guard(mutex)(&priv->rate_lock);
val = snd_soc_component_read(component, e->reg);
val >>= e->shift_l;
val &= e->mask;
- if (snd_soc_enum_item_to_val(e, item) == val) {
- ret = 0;
- goto out;
- }
+ if (snd_soc_enum_item_to_val(e, item) == val)
+ return 0;
if (!madera_can_change_grp_rate(priv, e->reg)) {
dev_warn(priv->madera->dev,
@@ -1082,8 +1075,6 @@ int madera_rate_put(struct snd_kcontrol *kcontrol,
ret = snd_soc_put_enum_double(kcontrol, ucontrol);
madera_spin_sysclk(priv);
}
-out:
- mutex_unlock(&priv->rate_lock);
return ret;
}
@@ -3041,12 +3032,11 @@ static int madera_hw_params_rate(struct snd_pcm_substream *substream,
if ((cur & MADERA_AIF1_RATE_MASK) == (tar & MADERA_AIF1_RATE_MASK))
return 0;
- mutex_lock(&priv->rate_lock);
+ guard(mutex)(&priv->rate_lock);
if (!madera_can_change_grp_rate(priv, base + MADERA_AIF_RATE_CTRL)) {
madera_aif_warn(dai, "Cannot change rate while active\n");
- ret = -EBUSY;
- goto out;
+ return -EBUSY;
}
/* Guard the rate change with SYSCLK cycles */
@@ -3055,9 +3045,6 @@ static int madera_hw_params_rate(struct snd_pcm_substream *substream,
MADERA_AIF1_RATE_MASK, tar);
madera_spin_sysclk(priv);
-out:
- mutex_unlock(&priv->rate_lock);
-
return ret;
}
--
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.