mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-12-04 22:31:15 -06:00
ASoC: codecs: da7219: Use guard() for mutex locks
Clean up the code using guard() for mutex locks. Merely code refactoring, and no behavior change. Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260721102600.523199-3-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
+19
-43
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/clkdev.h>
|
||||
#include <linux/clk-provider.h>
|
||||
@@ -256,13 +257,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 +268,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 +279,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 +290,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 +411,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 +444,11 @@ 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);
|
||||
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));
|
||||
mutex_unlock(&da7219->ctrl_lock);
|
||||
&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);
|
||||
if (freq < 2000000 || freq > 54000000) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1203,17 +1186,13 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
||||
freq = clk_round_rate(da7219->mclk, freq);
|
||||
ret = clk_set_rate(da7219->mclk, freq);
|
||||
if (ret) {
|
||||
dev_err(codec_dai->dev, "Failed to set clock rate %d\n",
|
||||
freq);
|
||||
mutex_unlock(&da7219->pll_lock);
|
||||
dev_err(codec_dai->dev, "Failed to set clock rate %d\n", freq);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
da7219->mclk_rate = freq;
|
||||
|
||||
mutex_unlock(&da7219->pll_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1296,13 +1275,10 @@ static int da7219_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
|
||||
{
|
||||
struct snd_soc_component *component = codec_dai->component;
|
||||
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&da7219->pll_lock);
|
||||
ret = da7219_set_pll(component, source, fout);
|
||||
mutex_unlock(&da7219->pll_lock);
|
||||
guard(mutex)(&da7219->pll_lock);
|
||||
|
||||
return ret;
|
||||
return da7219_set_pll(component, source, fout);
|
||||
}
|
||||
|
||||
static int da7219_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
|
||||
|
||||
Reference in New Issue
Block a user