mirror of
https://github.com/torvalds/linux.git
synced 2026-10-09 12:06:03 +02:00
ASoC: codecs: madera: Use guard() for mutex locks
Clean up the code using guard() for mutex locks. Merely code refactoring, and no behavior change. Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260721102600.523199-12-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
9296b43050
commit
5dabb2549c
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user