ASoC: codecs: tas2781: 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>
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://patch.msgid.link/20260731030648.8706-5-phucduc.bui@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
bui duc phuc 2026-07-31 10:06:26 +07:00 committed by Mark Brown
parent d6c5e4accf
commit a41eb6d666
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 15 additions and 23 deletions

View File

@ -6,6 +6,7 @@
//
// Author: Shenghao Ding <shenghao-ding@ti.com>
#include <linux/cleanup.h>
#include <linux/crc8.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>
@ -342,7 +343,7 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
/* Codec Lock Hold to ensure that codec_probe and firmware parsing and
* loading do not simultaneously execute.
*/
mutex_lock(&tas_priv->codec_lock);
guard(mutex)(&tas_priv->codec_lock);
if (tas_priv->name_prefix)
scnprintf(tas_priv->rca_binaryname, 64, "%s-%sRCA%d.bin",
@ -360,8 +361,6 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
dev_err(tas_priv->dev, "request_firmware_nowait err:0x%08x\n",
ret);
/* Codec Lock Release*/
mutex_unlock(&tas_priv->codec_lock);
return ret;
}
EXPORT_SYMBOL_GPL(tascodec_init);

View File

@ -13,6 +13,7 @@
// Author: Kevin Lu <kevin-lu@ti.com>
//
#include <linux/cleanup.h>
#include <linux/crc8.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>
@ -852,12 +853,12 @@ static int tasdevice_digital_gain_get(
unsigned char data[4];
int ret;
mutex_lock(&tas_dev->codec_lock);
guard(mutex)(&tas_dev->codec_lock);
/* Read the primary device */
ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
if (ret) {
dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
goto out;
return ret;
}
target = get_unaligned_be32(&data[0]);
@ -877,8 +878,7 @@ static int tasdevice_digital_gain_get(
/* find out the member same as or closer to the current volume */
ucontrol->value.integer.value[0] =
abs(target - ar_l) <= abs(target - ar_r) ? l : r;
out:
mutex_unlock(&tas_dev->codec_lock);
return 0;
}
@ -891,29 +891,26 @@ static int tasdevice_digital_gain_put(
struct snd_soc_component *codec = snd_kcontrol_chip(kcontrol);
struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
int vol = ucontrol->value.integer.value[0];
int status = 0, max = mc->max, rc = 1;
int status = 0, max = mc->max;
int i, ret;
unsigned int reg = mc->reg;
unsigned int volrd, volwr;
unsigned char data[4];
vol = clamp(vol, 0, max);
mutex_lock(&tas_dev->codec_lock);
guard(mutex)(&tas_dev->codec_lock);
/* Read the primary device */
ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
if (ret) {
dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
rc = -1;
goto out;
return -1;
}
volrd = get_unaligned_be32(&data[0]);
volwr = get_unaligned_be32(tas_dev->dvc_tlv_table[vol]);
if (volrd == volwr) {
rc = 0;
goto out;
}
if (volrd == volwr)
return 0;
for (i = 0; i < tas_dev->ndev; i++) {
ret = tasdevice_dev_bulk_write(tas_dev, i, reg,
@ -927,10 +924,9 @@ static int tasdevice_digital_gain_put(
}
if (status)
rc = -1;
out:
mutex_unlock(&tas_dev->codec_lock);
return rc;
return -1;
return 1;
}
static const struct snd_kcontrol_new tasdevice_cali_controls[] = {
@ -1774,13 +1770,10 @@ static int tasdevice_dapm_event(struct snd_soc_dapm_widget *w,
struct tasdevice_priv *tas_priv = snd_soc_component_get_drvdata(codec);
int state = 0;
/* Codec Lock Hold */
mutex_lock(&tas_priv->codec_lock);
guard(mutex)(&tas_priv->codec_lock);
if (event == SND_SOC_DAPM_PRE_PMD)
state = 1;
tasdevice_tuning_switch(tas_priv, state);
/* Codec Lock Release*/
mutex_unlock(&tas_priv->codec_lock);
return 0;
}