From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <[email protected]>
---
sound/soc/codecs/da7219.c | 59 +++++++++++++--------------------------
1 file changed, 19 insertions(+), 40 deletions(-)
diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c
index f0874d891e12..171ee6346b2e 100644
--- a/sound/soc/codecs/da7219.c
+++ b/sound/soc/codecs/da7219.c
@@ -256,13 +256,10 @@ static int da7219_volsw_locked_get(struct snd_kcontrol *kcontrol,
{
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
- int ret;
- mutex_lock(&da7219->ctrl_lock);
- ret = snd_soc_get_volsw(kcontrol, ucontrol);
- mutex_unlock(&da7219->ctrl_lock);
+ guard(mutex)(&da7219->ctrl_lock);
- return ret;
+ return snd_soc_get_volsw(kcontrol, ucontrol);
}
static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol,
@@ -270,13 +267,10 @@ static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol,
{
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
- int ret;
- mutex_lock(&da7219->ctrl_lock);
- ret = snd_soc_put_volsw(kcontrol, ucontrol);
- mutex_unlock(&da7219->ctrl_lock);
+ guard(mutex)(&da7219->ctrl_lock);
- return ret;
+ return snd_soc_put_volsw(kcontrol, ucontrol);
}
static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol,
@@ -284,13 +278,10 @@ static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol,
{
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
- int ret;
- mutex_lock(&da7219->ctrl_lock);
- ret = snd_soc_get_enum_double(kcontrol, ucontrol);
- mutex_unlock(&da7219->ctrl_lock);
+ guard(mutex)(&da7219->ctrl_lock);
- return ret;
+ return snd_soc_get_enum_double(kcontrol, ucontrol);
}
static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol,
@@ -298,13 +289,10 @@ static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol,
{
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
- int ret;
- mutex_lock(&da7219->ctrl_lock);
- ret = snd_soc_put_enum_double(kcontrol, ucontrol);
- mutex_unlock(&da7219->ctrl_lock);
+ guard(mutex)(&da7219->ctrl_lock);
- return ret;
+ return snd_soc_put_enum_double(kcontrol, ucontrol);
}
/* ALC */
@@ -422,9 +410,8 @@ static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol,
__le16 val;
int ret;
- mutex_lock(&da7219->ctrl_lock);
- ret = regmap_raw_read(da7219->regmap, reg, &val, sizeof(val));
- mutex_unlock(&da7219->ctrl_lock);
+ scoped_guard(mutex, &da7219->ctrl_lock)
+ ret = regmap_raw_read(da7219->regmap, reg, &val, sizeof(val));
if (ret)
return ret;
@@ -456,12 +443,12 @@ static int da7219_tonegen_freq_put(struct snd_kcontrol *kcontrol,
*/
val_new = cpu_to_le16(ucontrol->value.integer.value[0]);
- mutex_lock(&da7219->ctrl_lock);
- ret = regmap_raw_read(da7219->regmap, reg, &val_old, sizeof(val_old));
- if (ret == 0 && (val_old != val_new))
- ret = regmap_raw_write(da7219->regmap, reg,
- &val_new, sizeof(val_new));
- mutex_unlock(&da7219->ctrl_lock);
+ scoped_guard(mutex, &da7219->ctrl_lock) {
+ ret = regmap_raw_read(da7219->regmap, reg, &val_old, sizeof(val_old));
+ if (ret == 0 && (val_old != val_new))
+ ret = regmap_raw_write(da7219->regmap, reg,
+ &val_new, sizeof(val_new));
+ }
if (ret < 0)
return ret;
@@ -1167,15 +1154,12 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
int ret = 0;
- mutex_lock(&da7219->pll_lock);
+ guard(mutex)(&da7219->pll_lock);
- if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) {
- mutex_unlock(&da7219->pll_lock);
+ if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq))
return 0;
- }
if ((freq < 2000000) || (freq > 54000000)) {
- mutex_unlock(&da7219->pll_lock);
dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
freq);
return -EINVAL;
@@ -1193,7 +1177,6 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
break;
default:
dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
- mutex_unlock(&da7219->pll_lock);
return -EINVAL;
}
@@ -1205,15 +1188,12 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
if (ret) {
dev_err(codec_dai->dev, "Failed to set clock rate %d\n",
freq);
- mutex_unlock(&da7219->pll_lock);
return ret;
}
}
da7219->mclk_rate = freq;
- mutex_unlock(&da7219->pll_lock);
-
return 0;
}
@@ -1298,9 +1278,8 @@ static int da7219_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
int ret;
- mutex_lock(&da7219->pll_lock);
+ guard(mutex)(&da7219->pll_lock);
ret = da7219_set_pll(component, source, fout);
- mutex_unlock(&da7219->pll_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.