mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-12-04 21:10:57 -06:00
ASoC: codecs: ak4613: Use guard() for mutex locks
Clean up the code using guard() for mutex locks. Merely code refactoring, and no behavior change. Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260708125002.202515-3-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
+37
-40
@@ -95,6 +95,7 @@
|
||||
* see
|
||||
* AK4613_ENABLE_TDM_TEST
|
||||
*/
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/i2c.h>
|
||||
@@ -384,7 +385,7 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream,
|
||||
struct ak4613_priv *priv = snd_soc_component_get_drvdata(component);
|
||||
struct device *dev = component->dev;
|
||||
|
||||
mutex_lock(&priv->lock);
|
||||
guard(mutex)(&priv->lock);
|
||||
priv->cnt--;
|
||||
if (priv->cnt < 0) {
|
||||
dev_err(dev, "unexpected counter error\n");
|
||||
@@ -392,7 +393,6 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream,
|
||||
}
|
||||
if (!priv->cnt)
|
||||
priv->ctrl1 = 0;
|
||||
mutex_unlock(&priv->lock);
|
||||
}
|
||||
|
||||
static void ak4613_hw_constraints(struct ak4613_priv *priv,
|
||||
@@ -507,10 +507,9 @@ static int ak4613_dai_startup(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_component *component = dai->component;
|
||||
struct ak4613_priv *priv = snd_soc_component_get_drvdata(component);
|
||||
|
||||
mutex_lock(&priv->lock);
|
||||
guard(mutex)(&priv->lock);
|
||||
ak4613_hw_constraints(priv, substream);
|
||||
priv->cnt++;
|
||||
mutex_unlock(&priv->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -599,45 +598,47 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
|
||||
*/
|
||||
ret = -EINVAL;
|
||||
|
||||
mutex_lock(&priv->lock);
|
||||
if (priv->cnt > 1) {
|
||||
/*
|
||||
* If it was already working, use current priv->ctrl1
|
||||
*/
|
||||
ret = 0;
|
||||
} else {
|
||||
/*
|
||||
* It is not yet working,
|
||||
*/
|
||||
unsigned int channel = params_channels(params);
|
||||
u8 tdm;
|
||||
scoped_guard(mutex, &priv->lock) {
|
||||
if (priv->cnt > 1) {
|
||||
/*
|
||||
* If it was already working, use current priv->ctrl1
|
||||
*/
|
||||
ret = 0;
|
||||
} else {
|
||||
/*
|
||||
* It is not yet working,
|
||||
*/
|
||||
unsigned int channel = params_channels(params);
|
||||
u8 tdm;
|
||||
|
||||
/* STEREO or TDM */
|
||||
if (channel == 2)
|
||||
tdm = AK4613_CONFIG_MODE_STEREO;
|
||||
else
|
||||
tdm = AK4613_CONFIG_GET(priv, MODE);
|
||||
/* STEREO or TDM */
|
||||
if (channel == 2)
|
||||
tdm = AK4613_CONFIG_MODE_STEREO;
|
||||
else
|
||||
tdm = AK4613_CONFIG_GET(priv, MODE);
|
||||
|
||||
for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
|
||||
const struct ak4613_interface *iface = ak4613_iface + i;
|
||||
for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
|
||||
const struct ak4613_interface *iface = ak4613_iface + i;
|
||||
|
||||
if ((iface->fmt == fmt) && (iface->width == width)) {
|
||||
/*
|
||||
* Ctrl1
|
||||
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
|
||||
* |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE|
|
||||
* < tdm > < iface->dif >
|
||||
*/
|
||||
priv->ctrl1 = (tdm << 6) | (iface->dif << 3);
|
||||
ret = 0;
|
||||
break;
|
||||
if (iface->fmt == fmt && iface->width == width) {
|
||||
/*
|
||||
* Ctrl1
|
||||
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
|
||||
* |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE|
|
||||
* < tdm > < iface->dif >
|
||||
*/
|
||||
priv->ctrl1 = (tdm << 6) | (iface->dif << 3);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mutex_unlock(&priv->lock);
|
||||
|
||||
if (ret < 0)
|
||||
goto hw_params_end;
|
||||
if (ret < 0) {
|
||||
dev_warn(dev, "unsupported data width/format combination\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
snd_soc_component_update_bits(component, CTRL1, FMT_MASK, priv->ctrl1);
|
||||
snd_soc_component_update_bits(component, CTRL2, DFS_MASK, ctrl2);
|
||||
@@ -645,10 +646,6 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
|
||||
snd_soc_component_update_bits(component, ICTRL, ICTRL_MASK, priv->ic);
|
||||
snd_soc_component_update_bits(component, OCTRL, OCTRL_MASK, priv->oc);
|
||||
|
||||
hw_params_end:
|
||||
if (ret < 0)
|
||||
dev_warn(dev, "unsupported data width/format combination\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user