ASoC: codecs: Use guard() for mutex & spin locks - part 3

bui duc phuc <phucduc.bui@gmail.com> says:

This series is the final part of the cleanup to convert ASoC codec
drivers to use the guard() and scoped_guard() helpers for mutex and
spinlock handling.

Compile-tested only.

Link: https://patch.msgid.link/20260731030648.8706-1-phucduc.bui@gmail.com
This commit is contained in:
Mark Brown 2026-07-31 16:31:12 +01:00
commit 66c4f11a25
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
28 changed files with 303 additions and 501 deletions

View File

@ -5,6 +5,7 @@
* Copyright 2009-2014 Analog Devices Inc.
*/
#include <linux/cleanup.h>
#include <linux/crc32.h>
#include <linux/firmware.h>
#include <linux/kernel.h>
@ -135,7 +136,7 @@ static int sigmadsp_ctrl_put(struct snd_kcontrol *kcontrol,
uint8_t *data;
int ret = 0;
mutex_lock(&sigmadsp->lock);
guard(mutex)(&sigmadsp->lock);
data = ucontrol->value.bytes.data;
@ -148,8 +149,6 @@ static int sigmadsp_ctrl_put(struct snd_kcontrol *kcontrol,
ctrl->cached = true;
}
mutex_unlock(&sigmadsp->lock);
return ret;
}
@ -160,7 +159,7 @@ static int sigmadsp_ctrl_get(struct snd_kcontrol *kcontrol,
struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
int ret = 0;
mutex_lock(&sigmadsp->lock);
guard(mutex)(&sigmadsp->lock);
if (!ctrl->cached) {
ret = sigmadsp_read(sigmadsp, ctrl->addr, ctrl->cache,
@ -174,8 +173,6 @@ static int sigmadsp_ctrl_get(struct snd_kcontrol *kcontrol,
ctrl->num_bytes);
}
mutex_unlock(&sigmadsp->lock);
return ret;
}
@ -677,10 +674,10 @@ static void sigmadsp_activate_ctrl(struct sigmadsp *sigmadsp,
return;
changed = snd_ctl_activate_id(card, &ctrl->kcontrol->id, active);
if (active && changed > 0) {
mutex_lock(&sigmadsp->lock);
if (ctrl->cached)
sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
mutex_unlock(&sigmadsp->lock);
scoped_guard(mutex, &sigmadsp->lock) {
if (ctrl->cached)
sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
}
}
}

View File

@ -17,6 +17,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pm.h>
@ -269,9 +270,9 @@ static int sta32x_coefficient_get(struct snd_kcontrol *kcontrol,
int numcoef = kcontrol->private_value >> 16;
int index = kcontrol->private_value & 0xffff;
unsigned int cfud, val;
int i, ret = 0;
int i;
mutex_lock(&sta32x->coeff_lock);
guard(mutex)(&sta32x->coeff_lock);
/* preserve reserved bits in STA32X_CFUD */
regmap_read(sta32x->regmap, STA32X_CFUD, &cfud);
@ -283,24 +284,20 @@ static int sta32x_coefficient_get(struct snd_kcontrol *kcontrol,
regmap_write(sta32x->regmap, STA32X_CFUD, cfud);
regmap_write(sta32x->regmap, STA32X_CFADDR2, index);
if (numcoef == 1) {
if (numcoef == 1)
regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x04);
} else if (numcoef == 5) {
else if (numcoef == 5)
regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x08);
} else {
ret = -EINVAL;
goto exit_unlock;
}
else
return -EINVAL;
for (i = 0; i < 3 * numcoef; i++) {
regmap_read(sta32x->regmap, STA32X_B1CF1 + i, &val);
ucontrol->value.bytes.data[i] = val;
}
exit_unlock:
mutex_unlock(&sta32x->coeff_lock);
return ret;
return 0;
}
static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol,

View File

@ -16,6 +16,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ":%s:%d: " fmt, __func__, __LINE__
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -306,9 +307,9 @@ static int sta350_coefficient_get(struct snd_kcontrol *kcontrol,
int numcoef = kcontrol->private_value >> 16;
int index = kcontrol->private_value & 0xffff;
unsigned int cfud, val;
int i, ret = 0;
int i;
mutex_lock(&sta350->coeff_lock);
guard(mutex)(&sta350->coeff_lock);
/* preserve reserved bits in STA350_CFUD */
regmap_read(sta350->regmap, STA350_CFUD, &cfud);
@ -320,24 +321,19 @@ static int sta350_coefficient_get(struct snd_kcontrol *kcontrol,
regmap_write(sta350->regmap, STA350_CFUD, cfud);
regmap_write(sta350->regmap, STA350_CFADDR2, index);
if (numcoef == 1) {
if (numcoef == 1)
regmap_write(sta350->regmap, STA350_CFUD, cfud | 0x04);
} else if (numcoef == 5) {
else if (numcoef == 5)
regmap_write(sta350->regmap, STA350_CFUD, cfud | 0x08);
} else {
ret = -EINVAL;
goto exit_unlock;
}
else
return -EINVAL;
for (i = 0; i < 3 * numcoef; i++) {
regmap_read(sta350->regmap, STA350_B1CF1 + i, &val);
ucontrol->value.bytes.data[i] = val;
}
exit_unlock:
mutex_unlock(&sta350->coeff_lock);
return ret;
return 0;
}
static int sta350_coefficient_put(struct snd_kcontrol *kcontrol,

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;
}

View File

@ -12,6 +12,7 @@
// Author: Baojun Xu <baojun.xu@ti.com>
// Author: Kevin Lu <kevin-lu@ti.com>
#include <linux/cleanup.h>
#include <linux/unaligned.h>
#include <linux/crc32.h>
#include <linux/efi.h>
@ -693,12 +694,12 @@ static s32 tas2783_update_calibdata(struct tas2783_prv *tas_dev)
return 0;
}
mutex_lock(&tas_dev->calib_lock);
ret = tas2783_validate_calibdata(tas_dev, tas_dev->cali_data.data,
tas_dev->cali_data.read_sz);
if (!ret)
tas2783_set_calib_params_to_device(tas_dev, tmp_val);
mutex_unlock(&tas_dev->calib_lock);
scoped_guard(mutex, &tas_dev->calib_lock) {
ret = tas2783_validate_calibdata(tas_dev, tas_dev->cali_data.data,
tas_dev->cali_data.read_sz);
if (!ret)
tas2783_set_calib_params_to_device(tas_dev, tmp_val);
}
return ret;
}
@ -927,22 +928,23 @@ static s32 tas_sdw_hw_params(struct snd_pcm_substream *substream,
dev_err(tas_dev->dev,
"clear latch failed, err=%d", ret);
mutex_lock(&tas_dev->pde_lock);
/*
* Sometimes, there is error returned during power on.
* So added retry logic to ensure power on so that
* port prepare succeeds
*/
do {
ret = regmap_write(tas_dev->regmap,
SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23,
TAS2783_SDCA_CTL_REQ_POW_STATE, 0),
TAS2783_SDCA_POW_STATE_ON);
if (!ret)
break;
usleep_range(2000, 2200);
} while (retry--);
mutex_unlock(&tas_dev->pde_lock);
scoped_guard(mutex, &tas_dev->pde_lock) {
/*
* Sometimes, there is error returned during power on.
* So added retry logic to ensure power on so that
* port prepare succeeds
*/
do {
ret = regmap_write(tas_dev->regmap,
SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23,
TAS2783_SDCA_CTL_REQ_POW_STATE, 0),
TAS2783_SDCA_POW_STATE_ON);
if (!ret)
break;
usleep_range(2000, 2200);
} while (retry--);
}
if (ret)
return ret;
@ -966,7 +968,6 @@ static s32 tas_sdw_hw_params(struct snd_pcm_substream *substream,
static s32 tas_sdw_pcm_hw_free(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
s32 ret;
struct snd_soc_component *component = dai->component;
struct tas2783_prv *tas_dev =
snd_soc_component_get_drvdata(component);
@ -975,14 +976,11 @@ static s32 tas_sdw_pcm_hw_free(struct snd_pcm_substream *substream,
sdw_stream_remove_slave(tas_dev->sdw_peripheral, sdw_stream);
mutex_lock(&tas_dev->pde_lock);
ret = regmap_write(tas_dev->regmap,
SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23,
TAS2783_SDCA_CTL_REQ_POW_STATE, 0),
TAS2783_SDCA_POW_STATE_OFF);
mutex_unlock(&tas_dev->pde_lock);
return ret;
guard(mutex)(&tas_dev->pde_lock);
return regmap_write(tas_dev->regmap,
SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23,
TAS2783_SDCA_CTL_REQ_POW_STATE, 0),
TAS2783_SDCA_POW_STATE_OFF);
}
static const struct snd_soc_dai_ops tas_dai_ops = {

View File

@ -12,6 +12,7 @@
//
// It has been simplified a little and reworked for the 5.x ALSA SoC API.
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
@ -230,10 +231,9 @@ static int tas5805m_vol_get(struct snd_kcontrol *kcontrol,
struct tas5805m_priv *tas5805m =
snd_soc_component_get_drvdata(component);
mutex_lock(&tas5805m->lock);
guard(mutex)(&tas5805m->lock);
ucontrol->value.integer.value[0] = tas5805m->vol[0];
ucontrol->value.integer.value[1] = tas5805m->vol[1];
mutex_unlock(&tas5805m->lock);
return 0;
}
@ -249,13 +249,12 @@ static int tas5805m_vol_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct tas5805m_priv *tas5805m =
snd_soc_component_get_drvdata(component);
int ret = 0;
if (!(volume_is_valid(ucontrol->value.integer.value[0]) &&
volume_is_valid(ucontrol->value.integer.value[1])))
return -EINVAL;
mutex_lock(&tas5805m->lock);
guard(mutex)(&tas5805m->lock);
if (tas5805m->vol[0] != ucontrol->value.integer.value[0] ||
tas5805m->vol[1] != ucontrol->value.integer.value[1]) {
tas5805m->vol[0] = ucontrol->value.integer.value[0];
@ -265,11 +264,10 @@ static int tas5805m_vol_put(struct snd_kcontrol *kcontrol,
tas5805m->is_powered);
if (tas5805m->is_powered)
tas5805m_refresh(tas5805m);
ret = 1;
return 1;
}
mutex_unlock(&tas5805m->lock);
return ret;
return 0;
}
static const struct snd_kcontrol_new tas5805m_snd_controls[] = {
@ -332,7 +330,7 @@ static void do_work(struct work_struct *work)
dev_dbg(&tas5805m->i2c->dev, "DSP startup\n");
mutex_lock(&tas5805m->lock);
guard(mutex)(&tas5805m->lock);
/* We mustn't issue any I2C transactions until the I2S
* clock is stable. Furthermore, we must allow a 5ms
* delay after the first set of register writes to
@ -345,7 +343,6 @@ static void do_work(struct work_struct *work)
tas5805m->is_powered = true;
tas5805m_refresh(tas5805m);
mutex_unlock(&tas5805m->lock);
}
static int tas5805m_dac_event(struct snd_soc_dapm_widget *w,
@ -362,7 +359,7 @@ static int tas5805m_dac_event(struct snd_soc_dapm_widget *w,
dev_dbg(component->dev, "DSP shutdown\n");
cancel_work_sync(&tas5805m->work);
mutex_lock(&tas5805m->lock);
guard(mutex)(&tas5805m->lock);
if (tas5805m->is_powered) {
tas5805m->is_powered = false;
@ -379,7 +376,6 @@ static int tas5805m_dac_event(struct snd_soc_dapm_widget *w,
regmap_write(rm, REG_DEVICE_CTRL_2, DCTRL2_MODE_HIZ);
}
mutex_unlock(&tas5805m->lock);
}
return 0;
@ -414,14 +410,13 @@ static int tas5805m_mute(struct snd_soc_dai *dai, int mute, int direction)
struct tas5805m_priv *tas5805m =
snd_soc_component_get_drvdata(component);
mutex_lock(&tas5805m->lock);
guard(mutex)(&tas5805m->lock);
dev_dbg(component->dev, "set mute=%d (is_powered=%d)\n",
mute, tas5805m->is_powered);
tas5805m->is_muted = mute;
if (tas5805m->is_powered)
tas5805m_refresh(tas5805m);
mutex_unlock(&tas5805m->lock);
return 0;
}

View File

@ -7,6 +7,7 @@
* Copyright: (C) 2009 Nokia Corporation
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -236,13 +237,10 @@ static int dac33_write_locked(struct snd_soc_component *component, unsigned int
unsigned int value)
{
struct tlv320dac33_priv *dac33 = snd_soc_component_get_drvdata(component);
int ret;
mutex_lock(&dac33->mutex);
ret = dac33_write(component, reg, value);
mutex_unlock(&dac33->mutex);
guard(mutex)(&dac33->mutex);
return ret;
return dac33_write(component, reg, value);
}
#define DAC33_I2C_ADDR_AUTOINC 0x80
@ -365,13 +363,13 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
struct tlv320dac33_priv *dac33 = snd_soc_component_get_drvdata(component);
int ret = 0;
mutex_lock(&dac33->mutex);
guard(mutex)(&dac33->mutex);
/* Safety check */
if (unlikely(power == dac33->chip_power)) {
dev_dbg(component->dev, "Trying to set the same power state: %s\n",
power ? "ON" : "OFF");
goto exit;
return ret;
}
if (power) {
@ -380,7 +378,7 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
if (ret != 0) {
dev_err(component->dev,
"Failed to enable supplies: %d\n", ret);
goto exit;
return ret;
}
if (dac33->reset_gpiod) {
@ -388,7 +386,7 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
if (ret < 0) {
dev_err(&dac33->i2c->dev,
"Failed to set reset GPIO: %d\n", ret);
goto exit;
return ret;
}
}
@ -400,7 +398,7 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
if (ret < 0) {
dev_err(&dac33->i2c->dev,
"Failed to set reset GPIO: %d\n", ret);
goto exit;
return ret;
}
}
@ -409,14 +407,12 @@ static int dac33_hard_power(struct snd_soc_component *component, int power)
if (ret != 0) {
dev_err(component->dev,
"Failed to disable supplies: %d\n", ret);
goto exit;
return ret;
}
dac33->chip_power = 0;
}
exit:
mutex_unlock(&dac33->mutex);
return ret;
}
@ -659,7 +655,6 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
{
struct snd_soc_component *component = dac33->component;
unsigned int delay;
unsigned long flags;
switch (dac33->fifo_mode) {
case DAC33_FIFO_MODE1:
@ -667,10 +662,10 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
DAC33_THRREG(dac33->nsample));
/* Take the timestamps */
spin_lock_irqsave(&dac33->lock, flags);
dac33->t_stamp2 = ktime_to_us(ktime_get());
dac33->t_stamp1 = dac33->t_stamp2;
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock) {
dac33->t_stamp2 = ktime_to_us(ktime_get());
dac33->t_stamp1 = dac33->t_stamp2;
}
dac33_write16(component, DAC33_PREFILL_MSB,
DAC33_THRREG(dac33->alarm_threshold));
@ -682,11 +677,11 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
break;
case DAC33_FIFO_MODE7:
/* Take the timestamp */
spin_lock_irqsave(&dac33->lock, flags);
dac33->t_stamp1 = ktime_to_us(ktime_get());
/* Move back the timestamp with drain time */
dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock) {
dac33->t_stamp1 = ktime_to_us(ktime_get());
/* Move back the timestamp with drain time */
dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
}
dac33_write16(component, DAC33_PREFILL_MSB,
DAC33_THRREG(DAC33_MODE7_MARGIN));
@ -704,14 +699,12 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
{
struct snd_soc_component *component = dac33->component;
unsigned long flags;
switch (dac33->fifo_mode) {
case DAC33_FIFO_MODE1:
/* Take the timestamp */
spin_lock_irqsave(&dac33->lock, flags);
dac33->t_stamp2 = ktime_to_us(ktime_get());
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock)
dac33->t_stamp2 = ktime_to_us(ktime_get());
dac33_write16(component, DAC33_NSAMPLE_MSB,
DAC33_THRREG(dac33->nsample));
@ -735,7 +728,7 @@ static void dac33_work(struct work_struct *work)
dac33 = container_of(work, struct tlv320dac33_priv, work);
component = dac33->component;
mutex_lock(&dac33->mutex);
guard(mutex)(&dac33->mutex);
switch (dac33->state) {
case DAC33_PREFILL:
dac33->state = DAC33_PLAYBACK;
@ -757,18 +750,15 @@ static void dac33_work(struct work_struct *work)
dac33_write(component, DAC33_FIFO_CTRL_A, reg);
break;
}
mutex_unlock(&dac33->mutex);
}
static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
{
struct snd_soc_component *component = dev;
struct tlv320dac33_priv *dac33 = snd_soc_component_get_drvdata(component);
unsigned long flags;
spin_lock_irqsave(&dac33->lock, flags);
dac33->t_stamp1 = ktime_to_us(ktime_get());
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock)
dac33->t_stamp1 = ktime_to_us(ktime_get());
/* Do not schedule the workqueue in Mode7 */
if (dac33->fifo_mode != DAC33_FIFO_MODE7)
@ -902,14 +892,13 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream,
return -EINVAL;
}
mutex_lock(&dac33->mutex);
guard(mutex)(&dac33->mutex);
if (!dac33->chip_power) {
/*
* Chip is not powered yet.
* Do the init in the dac33_set_bias_level later.
*/
mutex_unlock(&dac33->mutex);
return 0;
}
@ -1053,8 +1042,6 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream,
break;
}
mutex_unlock(&dac33->mutex);
return 0;
}
@ -1156,21 +1143,20 @@ static snd_pcm_sframes_t dac33_dai_delay(
unsigned int time_delta, uthr;
int samples_out, samples_in, samples;
snd_pcm_sframes_t delay = 0;
unsigned long flags;
switch (dac33->fifo_mode) {
case DAC33_FIFO_BYPASS:
break;
case DAC33_FIFO_MODE1:
spin_lock_irqsave(&dac33->lock, flags);
t0 = dac33->t_stamp1;
t1 = dac33->t_stamp2;
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock) {
t0 = dac33->t_stamp1;
t1 = dac33->t_stamp2;
}
t_now = ktime_to_us(ktime_get());
/* We have not started to fill the FIFO yet, delay is 0 */
if (!t1)
goto out;
return 0;
if (t0 > t1) {
/*
@ -1230,23 +1216,22 @@ static snd_pcm_sframes_t dac33_dai_delay(
}
break;
case DAC33_FIFO_MODE7:
spin_lock_irqsave(&dac33->lock, flags);
t0 = dac33->t_stamp1;
uthr = dac33->uthr;
spin_unlock_irqrestore(&dac33->lock, flags);
scoped_guard(spinlock_irqsave, &dac33->lock) {
t0 = dac33->t_stamp1;
uthr = dac33->uthr;
}
t_now = ktime_to_us(ktime_get());
/* We have not started to fill the FIFO yet, delay is 0 */
if (!t0)
goto out;
return 0;
if (t_now <= t0) {
/*
* Either the timestamps are messed or equal. Report
* maximum delay
*/
delay = uthr;
goto out;
return uthr;
}
time_delta = t_now - t0;
@ -1287,7 +1272,7 @@ static snd_pcm_sframes_t dac33_dai_delay(
dac33->fifo_mode);
break;
}
out:
return delay;
}

View File

@ -12,6 +12,7 @@
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <sound/tlv.h>
#include <sound/pcm_params.h>
@ -210,25 +211,21 @@ static int power_up_audio_plls(struct snd_soc_component *component)
return ret;
}
mutex_lock(&tscs42xx->pll_lock);
guard(mutex)(&tscs42xx->pll_lock);
ret = snd_soc_component_update_bits(component, R_PLLCTL1C, mask, val);
if (ret < 0) {
dev_err(component->dev, "Failed to turn PLL on (%d)\n", ret);
goto exit;
return ret;
}
if (!plls_locked(component)) {
dev_err(component->dev, "Failed to lock plls\n");
ret = -ENOMSG;
goto exit;
return ret;
}
ret = 0;
exit:
mutex_unlock(&tscs42xx->pll_lock);
return ret;
return 0;
}
static int power_down_audio_plls(struct snd_soc_component *component)
@ -236,28 +233,24 @@ static int power_down_audio_plls(struct snd_soc_component *component)
struct tscs42xx *tscs42xx = snd_soc_component_get_drvdata(component);
int ret;
mutex_lock(&tscs42xx->pll_lock);
guard(mutex)(&tscs42xx->pll_lock);
ret = snd_soc_component_update_bits(component, R_PLLCTL1C,
RM_PLLCTL1C_PDB_PLL1,
RV_PLLCTL1C_PDB_PLL1_DISABLE);
if (ret < 0) {
dev_err(component->dev, "Failed to turn PLL off (%d)\n", ret);
goto exit;
return ret;
}
ret = snd_soc_component_update_bits(component, R_PLLCTL1C,
RM_PLLCTL1C_PDB_PLL2,
RV_PLLCTL1C_PDB_PLL2_DISABLE);
if (ret < 0) {
dev_err(component->dev, "Failed to turn PLL off (%d)\n", ret);
goto exit;
return ret;
}
ret = 0;
exit:
mutex_unlock(&tscs42xx->pll_lock);
return ret;
return 0;
}
static int coeff_ram_get(struct snd_kcontrol *kcontrol,
@ -269,13 +262,11 @@ static int coeff_ram_get(struct snd_kcontrol *kcontrol,
(struct coeff_ram_ctl *)kcontrol->private_value;
struct soc_bytes_ext *params = &ctl->bytes_ext;
mutex_lock(&tscs42xx->coeff_ram_lock);
guard(mutex)(&tscs42xx->coeff_ram_lock);
memcpy(ucontrol->value.bytes.data,
&tscs42xx->coeff_ram[ctl->addr * COEFF_SIZE], params->max);
mutex_unlock(&tscs42xx->coeff_ram_lock);
return 0;
}
@ -290,14 +281,14 @@ static int coeff_ram_put(struct snd_kcontrol *kcontrol,
unsigned int coeff_cnt = params->max / COEFF_SIZE;
int ret;
mutex_lock(&tscs42xx->coeff_ram_lock);
guard(mutex)(&tscs42xx->coeff_ram_lock);
tscs42xx->coeff_ram_synced = false;
memcpy(&tscs42xx->coeff_ram[ctl->addr * COEFF_SIZE],
ucontrol->value.bytes.data, params->max);
mutex_lock(&tscs42xx->pll_lock);
guard(mutex)(&tscs42xx->pll_lock);
if (plls_locked(component)) {
ret = write_coeff_ram(component, tscs42xx->coeff_ram,
@ -305,18 +296,12 @@ static int coeff_ram_put(struct snd_kcontrol *kcontrol,
if (ret < 0) {
dev_err(component->dev,
"Failed to flush coeff ram cache (%d)\n", ret);
goto exit;
return ret;
}
tscs42xx->coeff_ram_synced = true;
}
ret = 0;
exit:
mutex_unlock(&tscs42xx->pll_lock);
mutex_unlock(&tscs42xx->coeff_ram_lock);
return ret;
return 0;
}
/* Input L Capture Route */
@ -385,21 +370,17 @@ static int dac_event(struct snd_soc_dapm_widget *w,
struct tscs42xx *tscs42xx = snd_soc_component_get_drvdata(component);
int ret;
mutex_lock(&tscs42xx->coeff_ram_lock);
guard(mutex)(&tscs42xx->coeff_ram_lock);
if (!tscs42xx->coeff_ram_synced) {
ret = write_coeff_ram(component, tscs42xx->coeff_ram, 0x00,
COEFF_RAM_COEFF_COUNT);
if (ret < 0)
goto exit;
return ret;
tscs42xx->coeff_ram_synced = true;
}
ret = 0;
exit:
mutex_unlock(&tscs42xx->coeff_ram_lock);
return ret;
return 0;
}
static const struct snd_soc_dapm_widget tscs42xx_dapm_widgets[] = {
@ -926,12 +907,10 @@ static int setup_sample_rate(struct snd_soc_component *component,
return ret;
}
mutex_lock(&tscs42xx->audio_params_lock);
guard(mutex)(&tscs42xx->audio_params_lock);
tscs42xx->samplerate = rate;
mutex_unlock(&tscs42xx->audio_params_lock);
return 0;
}
@ -1253,12 +1232,10 @@ static int tscs42xx_set_dai_bclk_ratio(struct snd_soc_dai *codec_dai,
return ret;
}
mutex_lock(&tscs42xx->audio_params_lock);
guard(mutex)(&tscs42xx->audio_params_lock);
tscs42xx->bclk_ratio = ratio;
mutex_unlock(&tscs42xx->audio_params_lock);
return 0;
}

View File

@ -4,6 +4,7 @@
// Author: Steven Eckhoff <steven.eckhoff.opensource@gmail.com>
#include <linux/kernel.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/regmap.h>
@ -329,12 +330,10 @@ static int coeff_ram_get(struct snd_kcontrol *kcontrol,
return -EINVAL;
}
mutex_lock(coeff_ram_lock);
memcpy(ucontrol->value.bytes.data,
&coeff_ram[ctl->addr * COEFF_SIZE], params->max);
mutex_unlock(coeff_ram_lock);
scoped_guard(mutex, coeff_ram_lock) {
memcpy(ucontrol->value.bytes.data,
&coeff_ram[ctl->addr * COEFF_SIZE], params->max);
}
return 0;
}
@ -428,15 +427,15 @@ static int coeff_ram_put(struct snd_kcontrol *kcontrol,
return -EINVAL;
}
mutex_lock(coeff_ram_lock);
guard(mutex)(coeff_ram_lock);
*coeff_ram_synced = false;
memcpy(&coeff_ram[ctl->addr * COEFF_SIZE],
ucontrol->value.bytes.data, params->max);
mutex_lock(&tscs454->pll1.lock);
mutex_lock(&tscs454->pll2.lock);
guard(mutex)(&tscs454->pll1.lock);
guard(mutex)(&tscs454->pll2.lock);
val = snd_soc_component_read(component, R_PLLSTAT);
if (val) { /* PLLs locked */
@ -446,18 +445,12 @@ static int coeff_ram_put(struct snd_kcontrol *kcontrol,
if (ret < 0) {
dev_err(component->dev,
"Failed to flush coeff ram cache (%d)\n", ret);
goto exit;
return ret;
}
*coeff_ram_synced = true;
}
ret = 0;
exit:
mutex_unlock(&tscs454->pll2.lock);
mutex_unlock(&tscs454->pll1.lock);
mutex_unlock(coeff_ram_lock);
return ret;
return 0;
}
static inline int coeff_ram_sync(struct snd_soc_component *component,
@ -465,41 +458,35 @@ static inline int coeff_ram_sync(struct snd_soc_component *component,
{
int ret;
mutex_lock(&tscs454->dac_ram.lock);
if (!tscs454->dac_ram.synced) {
ret = write_coeff_ram(component, tscs454->dac_ram.cache,
R_DACCRS, R_DACCRADD, R_DACCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0) {
mutex_unlock(&tscs454->dac_ram.lock);
return ret;
scoped_guard(mutex, &tscs454->dac_ram.lock) {
if (!tscs454->dac_ram.synced) {
ret = write_coeff_ram(component, tscs454->dac_ram.cache,
R_DACCRS, R_DACCRADD, R_DACCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0)
return ret;
}
}
mutex_unlock(&tscs454->dac_ram.lock);
mutex_lock(&tscs454->spk_ram.lock);
if (!tscs454->spk_ram.synced) {
ret = write_coeff_ram(component, tscs454->spk_ram.cache,
R_SPKCRS, R_SPKCRADD, R_SPKCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0) {
mutex_unlock(&tscs454->spk_ram.lock);
return ret;
scoped_guard(mutex, &tscs454->spk_ram.lock) {
if (!tscs454->spk_ram.synced) {
ret = write_coeff_ram(component, tscs454->spk_ram.cache,
R_SPKCRS, R_SPKCRADD, R_SPKCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0)
return ret;
}
}
mutex_unlock(&tscs454->spk_ram.lock);
mutex_lock(&tscs454->sub_ram.lock);
if (!tscs454->sub_ram.synced) {
ret = write_coeff_ram(component, tscs454->sub_ram.cache,
R_SUBCRS, R_SUBCRADD, R_SUBCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0) {
mutex_unlock(&tscs454->sub_ram.lock);
return ret;
scoped_guard(mutex, &tscs454->sub_ram.lock) {
if (!tscs454->sub_ram.synced) {
ret = write_coeff_ram(component, tscs454->sub_ram.cache,
R_SUBCRS, R_SUBCRADD, R_SUBCRWDL,
0x00, COEFF_RAM_COEFF_COUNT);
if (ret < 0)
return ret;
}
}
mutex_unlock(&tscs454->sub_ram.lock);
return 0;
}
@ -658,16 +645,14 @@ static int set_sysclk(struct snd_soc_component *component)
static inline void reserve_pll(struct pll *pll)
{
mutex_lock(&pll->lock);
guard(mutex)(&pll->lock);
pll->users++;
mutex_unlock(&pll->lock);
}
static inline void free_pll(struct pll *pll)
{
mutex_lock(&pll->lock);
guard(mutex)(&pll->lock);
pll->users--;
mutex_unlock(&pll->lock);
}
static int pll_connected(struct snd_soc_dapm_widget *source,
@ -679,15 +664,13 @@ static int pll_connected(struct snd_soc_dapm_widget *source,
int users;
if (strstr(source->name, "PLL 1")) {
mutex_lock(&tscs454->pll1.lock);
users = tscs454->pll1.users;
mutex_unlock(&tscs454->pll1.lock);
scoped_guard(mutex, &tscs454->pll1.lock)
users = tscs454->pll1.users;
dev_dbg(component->dev, "%s(): PLL 1 users = %d\n", __func__,
users);
} else {
mutex_lock(&tscs454->pll2.lock);
users = tscs454->pll2.users;
mutex_unlock(&tscs454->pll2.lock);
scoped_guard(mutex, &tscs454->pll2.lock)
users = tscs454->pll2.users;
dev_dbg(component->dev, "%s(): PLL 2 users = %d\n", __func__,
users);
}
@ -806,7 +789,7 @@ static inline int aif_free(struct snd_soc_component *component,
{
struct tscs454 *tscs454 = snd_soc_component_get_drvdata(component);
mutex_lock(&tscs454->aifs_status_lock);
guard(mutex)(&tscs454->aifs_status_lock);
dev_dbg(component->dev, "%s(): aif %d\n", __func__, aif->id);
@ -829,8 +812,6 @@ static inline int aif_free(struct snd_soc_component *component,
free_pll(tscs454->internal_rate.pll);
}
mutex_unlock(&tscs454->aifs_status_lock);
return 0;
}
@ -3174,7 +3155,7 @@ static int tscs454_hw_params(struct snd_pcm_substream *substream,
unsigned int val;
int ret;
mutex_lock(&tscs454->aifs_status_lock);
guard(mutex)(&tscs454->aifs_status_lock);
dev_dbg(component->dev, "%s(): aif %d fs = %u\n", __func__,
aif->id, fs);
@ -3207,14 +3188,14 @@ static int tscs454_hw_params(struct snd_pcm_substream *substream,
ret = set_aif_fs(component, aif->id, fs);
if (ret < 0) {
dev_err(component->dev, "Failed to set aif fs (%d)\n", ret);
goto exit;
return ret;
}
ret = set_aif_sample_format(component, params_format(params), aif->id);
if (ret < 0) {
dev_err(component->dev,
"Failed to set aif sample format (%d)\n", ret);
goto exit;
return ret;
}
set_aif_status_active(&tscs454->aifs_status, aif->id,
@ -3223,11 +3204,7 @@ static int tscs454_hw_params(struct snd_pcm_substream *substream,
dev_dbg(component->dev, "Set aif %d active. Streams status is 0x%x\n",
aif->id, tscs454->aifs_status.streams);
ret = 0;
exit:
mutex_unlock(&tscs454->aifs_status_lock);
return ret;
return 0;
}
static int tscs454_hw_free(struct snd_pcm_substream *substream,

View File

@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/platform_device.h>
@ -273,7 +274,7 @@ static void twl6040_hs_jack_report(struct snd_soc_component *component,
struct twl6040_data *priv = snd_soc_component_get_drvdata(component);
int status;
mutex_lock(&priv->mutex);
guard(mutex)(&priv->mutex);
/* Sync status */
status = twl6040_read(component, TWL6040_REG_STATUS);
@ -281,8 +282,6 @@ static void twl6040_hs_jack_report(struct snd_soc_component *component,
snd_soc_jack_report(jack, report, report);
else
snd_soc_jack_report(jack, 0, report);
mutex_unlock(&priv->mutex);
}
void twl6040_hs_jack_detect(struct snd_soc_component *component,

View File

@ -1265,13 +1265,10 @@ static int wcd934x_set_sido_input_src(struct wcd934x_codec *wcd, int sido_src)
static int wcd934x_enable_ana_bias_and_sysclk(struct wcd934x_codec *wcd)
{
mutex_lock(&wcd->sysclk_mutex);
if (++wcd->sysclk_users != 1) {
mutex_unlock(&wcd->sysclk_mutex);
return 0;
scoped_guard(mutex, &wcd->sysclk_mutex) {
if (++wcd->sysclk_users != 1)
return 0;
}
mutex_unlock(&wcd->sysclk_mutex);
regmap_update_bits(wcd->regmap, WCD934X_ANA_BIAS,
WCD934X_ANA_BIAS_EN_MASK,
@ -1328,12 +1325,10 @@ static int wcd934x_enable_ana_bias_and_sysclk(struct wcd934x_codec *wcd)
static int wcd934x_disable_ana_bias_and_syclk(struct wcd934x_codec *wcd)
{
mutex_lock(&wcd->sysclk_mutex);
if (--wcd->sysclk_users != 0) {
mutex_unlock(&wcd->sysclk_mutex);
return 0;
scoped_guard(mutex, &wcd->sysclk_mutex) {
if (--wcd->sysclk_users != 0)
return 0;
}
mutex_unlock(&wcd->sysclk_mutex);
regmap_update_bits(wcd->regmap, WCD934X_CLK_SYS_MCLK_PRG,
WCD934X_EXT_CLK_BUF_EN_MASK |
@ -2384,7 +2379,7 @@ static int wcd934x_micbias_control(struct snd_soc_component *component,
__func__, micb_num);
return -EINVAL;
}
mutex_lock(&wcd934x->micb_lock);
guard(mutex)(&wcd934x->micb_lock);
switch (req) {
case MICB_PULLUP_ENABLE:
@ -2446,8 +2441,6 @@ static int wcd934x_micbias_control(struct snd_soc_component *component,
break;
}
mutex_unlock(&wcd934x->micb_lock);
return 0;
}
@ -2488,7 +2481,7 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
struct wcd934x_codec *wcd934x = snd_soc_component_get_drvdata(component);
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0;
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en;
switch (micb_num) {
case MIC_BIAS_1:
@ -2506,7 +2499,7 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
default:
return -EINVAL;
}
mutex_lock(&wcd934x->micb_lock);
guard(mutex)(&wcd934x->micb_lock);
/*
* If requested micbias voltage is same as current micbias
* voltage, then just return. Otherwise, adjust voltage as
@ -2521,15 +2514,11 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
WCD934X_MICB_VAL_MASK);
req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
}
if (req_vout_ctl < 0)
return -EINVAL;
if (cur_vout_ctl == req_vout_ctl) {
ret = 0;
goto exit;
}
if (cur_vout_ctl == req_vout_ctl)
return 0;
if (micb_en == WCD934X_MICB_ENABLE)
snd_soc_component_write_field(component, micb_reg,
@ -2550,9 +2539,8 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
*/
usleep_range(2000, 2100);
}
exit:
mutex_unlock(&wcd934x->micb_lock);
return ret;
return 0;
}
static int wcd934x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,

View File

@ -2,6 +2,7 @@
// Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
#include <linux/component.h>
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
@ -1056,7 +1057,7 @@ static int wcd937x_micbias_control(struct snd_soc_component *component,
return -EINVAL;
}
mutex_lock(&wcd937x->micb_lock);
guard(mutex)(&wcd937x->micb_lock);
switch (req) {
case MICB_PULLUP_ENABLE:
wcd937x->pullup_ref[micb_index]++;
@ -1136,7 +1137,6 @@ static int wcd937x_micbias_control(struct snd_soc_component *component,
}
break;
}
mutex_unlock(&wcd937x->micb_lock);
return 0;
}
@ -1460,7 +1460,7 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component);
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0;
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en;
switch (micb_num) {
case MIC_BIAS_1:
@ -1475,7 +1475,7 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
default:
return -EINVAL;
}
mutex_lock(&wcd937x->micb_lock);
guard(mutex)(&wcd937x->micb_lock);
/*
* If requested micbias voltage is same as current micbias
* voltage, then just return. Otherwise, adjust voltage as
@ -1490,15 +1490,11 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
WCD937X_MICB_VOUT_MASK);
req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
}
if (req_vout_ctl < 0)
return -EINVAL;
if (cur_vout_ctl == req_vout_ctl) {
ret = 0;
goto exit;
}
if (cur_vout_ctl == req_vout_ctl)
return 0;
if (micb_en == WCD937X_MICB_ENABLE)
snd_soc_component_write_field(component, micb_reg,
@ -1519,9 +1515,8 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
*/
usleep_range(2000, 2100);
}
exit:
mutex_unlock(&wcd937x->micb_lock);
return ret;
return 0;
}
static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
@ -1976,7 +1977,7 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0;
int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en;
switch (micb_num) {
case MIC_BIAS_1:
@ -1994,7 +1995,7 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
default:
return -EINVAL;
}
mutex_lock(&wcd938x->micb_lock);
guard(mutex)(&wcd938x->micb_lock);
/*
* If requested micbias voltage is same as current micbias
* voltage, then just return. Otherwise, adjust voltage as
@ -2009,15 +2010,11 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
WCD938X_MICB_VOUT_MASK);
req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
}
if (req_vout_ctl < 0)
return -EINVAL;
if (cur_vout_ctl == req_vout_ctl) {
ret = 0;
goto exit;
}
if (cur_vout_ctl == req_vout_ctl)
return 0;
if (micb_en == WCD938X_MICB_ENABLE)
snd_soc_component_write_field(component, micb_reg,
@ -2038,9 +2035,8 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
*/
usleep_range(2000, 2100);
}
exit:
mutex_unlock(&wcd938x->micb_lock);
return ret;
return 0;
}
static int wcd938x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,

View File

@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
@ -1923,7 +1924,6 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
unsigned int micb_reg, cur_vout_ctl, micb_en;
int req_vout_ctl;
int ret = 0;
switch (micb_num) {
case MIC_BIAS_1:
@ -1941,7 +1941,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
default:
return -EINVAL;
}
mutex_lock(&wcd939x->micb_lock);
guard(mutex)(&wcd939x->micb_lock);
/*
* If requested micbias voltage is same as current micbias
@ -1957,15 +1957,11 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
WCD939X_MICB_VOUT_CTL);
req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = req_vout_ctl;
goto exit;
}
if (req_vout_ctl < 0)
return req_vout_ctl;
if (cur_vout_ctl == req_vout_ctl) {
ret = 0;
goto exit;
}
if (cur_vout_ctl == req_vout_ctl)
return 0;
dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
__func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
@ -1990,9 +1986,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
usleep_range(2000, 2100);
}
exit:
mutex_unlock(&wcd939x->micb_lock);
return ret;
return 0;
}
static int wcd939x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,

View File

@ -9,6 +9,7 @@
* Scott Ling <sl@opensource.wolfsonmicro.com>
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interrupt.h>
@ -148,13 +149,11 @@ static const char *wm0010_state_to_str(enum wm0010_state state)
static void wm0010_halt(struct snd_soc_component *component)
{
struct wm0010_priv *wm0010 = snd_soc_component_get_drvdata(component);
unsigned long flags;
enum wm0010_state state;
/* Fetch the wm0010 state */
spin_lock_irqsave(&wm0010->irq_lock, flags);
state = wm0010->state;
spin_unlock_irqrestore(&wm0010->irq_lock, flags);
scoped_guard(spinlock_irqsave, &wm0010->irq_lock)
state = wm0010->state;
switch (state) {
case WM0010_POWER_OFF:
@ -173,9 +172,8 @@ static void wm0010_halt(struct snd_soc_component *component)
break;
}
spin_lock_irqsave(&wm0010->irq_lock, flags);
wm0010->state = WM0010_POWER_OFF;
spin_unlock_irqrestore(&wm0010->irq_lock, flags);
scoped_guard(spinlock_irqsave, &wm0010->irq_lock)
wm0010->state = WM0010_POWER_OFF;
}
struct wm0010_boot_xfer {
@ -190,11 +188,9 @@ struct wm0010_boot_xfer {
static void wm0010_mark_boot_failure(struct wm0010_priv *wm0010)
{
enum wm0010_state state;
unsigned long flags;
spin_lock_irqsave(&wm0010->irq_lock, flags);
state = wm0010->state;
spin_unlock_irqrestore(&wm0010->irq_lock, flags);
scoped_guard(spinlock_irqsave, &wm0010->irq_lock)
state = wm0010->state;
dev_err(wm0010->dev, "Failed to transition from `%s' state to `%s' state\n",
wm0010_state_to_str(state), wm0010_state_to_str(state + 1));
@ -734,9 +730,8 @@ static int wm0010_set_bias_level(struct snd_soc_component *component,
break;
case SND_SOC_BIAS_STANDBY:
if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_PREPARE) {
mutex_lock(&wm0010->lock);
wm0010_halt(component);
mutex_unlock(&wm0010->lock);
scoped_guard(mutex, &wm0010->lock)
wm0010_halt(component);
}
break;
case SND_SOC_BIAS_OFF:
@ -832,9 +827,8 @@ static irqreturn_t wm0010_irq(int irq, void *data)
case WM0010_OUT_OF_RESET:
case WM0010_BOOTROM:
case WM0010_STAGE2:
spin_lock(&wm0010->irq_lock);
complete(&wm0010->boot_completion);
spin_unlock(&wm0010->irq_lock);
scoped_guard(spinlock, &wm0010->irq_lock)
complete(&wm0010->boot_completion);
return IRQ_HANDLED;
default:
return IRQ_NONE;

View File

@ -23,6 +23,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/firmware.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pm.h>
@ -612,20 +613,15 @@ static int wm2000_anc_mode_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
unsigned int anc_active = ucontrol->value.integer.value[0];
int ret;
if (anc_active > 1)
return -EINVAL;
mutex_lock(&wm2000->lock);
guard(mutex)(&wm2000->lock);
wm2000->anc_active = anc_active;
ret = wm2000_anc_set_mode(wm2000);
mutex_unlock(&wm2000->lock);
return ret;
return wm2000_anc_set_mode(wm2000);
}
static int wm2000_speaker_get(struct snd_kcontrol *kcontrol,
@ -645,20 +641,15 @@ static int wm2000_speaker_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
unsigned int val = ucontrol->value.integer.value[0];
int ret;
if (val > 1)
return -EINVAL;
mutex_lock(&wm2000->lock);
guard(mutex)(&wm2000->lock);
wm2000->spk_ena = val;
ret = wm2000_anc_set_mode(wm2000);
mutex_unlock(&wm2000->lock);
return ret;
return wm2000_anc_set_mode(wm2000);
}
static const struct snd_kcontrol_new wm2000_controls[] = {
@ -676,9 +667,8 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
{
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
int ret;
mutex_lock(&wm2000->lock);
guard(mutex)(&wm2000->lock);
if (SND_SOC_DAPM_EVENT_ON(event))
wm2000->anc_eng_ena = 1;
@ -686,11 +676,7 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
if (SND_SOC_DAPM_EVENT_OFF(event))
wm2000->anc_eng_ena = 0;
ret = wm2000_anc_set_mode(wm2000);
mutex_unlock(&wm2000->lock);
return ret;
return wm2000_anc_set_mode(wm2000);
}
static const struct snd_soc_dapm_widget wm2000_dapm_widgets[] = {

View File

@ -7,6 +7,7 @@
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -667,10 +668,9 @@ static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct arizona *arizona = dev_get_drvdata(component->dev->parent);
mutex_lock(&arizona->dac_comp_lock);
guard(mutex)(&arizona->dac_comp_lock);
put_unaligned_be16(arizona->dac_comp_coeff,
ucontrol->value.bytes.data);
mutex_unlock(&arizona->dac_comp_lock);
return 0;
}
@ -681,16 +681,14 @@ static int wm5102_out_comp_coeff_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct arizona *arizona = dev_get_drvdata(component->dev->parent);
uint16_t dac_comp_coeff = get_unaligned_be16(ucontrol->value.bytes.data);
int ret = 0;
mutex_lock(&arizona->dac_comp_lock);
guard(mutex)(&arizona->dac_comp_lock);
if (arizona->dac_comp_coeff != dac_comp_coeff) {
arizona->dac_comp_coeff = dac_comp_coeff;
ret = 1;
return 1;
}
mutex_unlock(&arizona->dac_comp_lock);
return ret;
return 0;
}
static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
@ -699,9 +697,8 @@ static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct arizona *arizona = dev_get_drvdata(component->dev->parent);
mutex_lock(&arizona->dac_comp_lock);
guard(mutex)(&arizona->dac_comp_lock);
ucontrol->value.integer.value[0] = arizona->dac_comp_enabled;
mutex_unlock(&arizona->dac_comp_lock);
return 0;
}
@ -712,19 +709,17 @@ static int wm5102_out_comp_switch_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct arizona *arizona = dev_get_drvdata(component->dev->parent);
struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
int ret = 0;
if (ucontrol->value.integer.value[0] > mc->max)
return -EINVAL;
mutex_lock(&arizona->dac_comp_lock);
guard(mutex)(&arizona->dac_comp_lock);
if (arizona->dac_comp_enabled != ucontrol->value.integer.value[0]) {
arizona->dac_comp_enabled = ucontrol->value.integer.value[0];
ret = 1;
return 1;
}
mutex_unlock(&arizona->dac_comp_lock);
return ret;
return 0;
}
static const char * const wm5102_osr_text[] = {

View File

@ -10,6 +10,7 @@
* Based on wm8753.c by Liam Girdwood
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -110,22 +111,20 @@ static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component);
unsigned int deemph = ucontrol->value.integer.value[0];
int ret = 0;
if (deemph > 1)
return -EINVAL;
mutex_lock(&wm8731->lock);
guard(mutex)(&wm8731->lock);
if (wm8731->deemph != deemph) {
wm8731->deemph = deemph;
wm8731_set_deemph(component);
ret = 1;
return 1;
}
mutex_unlock(&wm8731->lock);
return ret;
return 0;
}
static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);

View File

@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/gpio/driver.h>
@ -458,22 +459,20 @@ static int wm8903_put_deemph(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm8903_priv *wm8903 = snd_soc_component_get_drvdata(component);
unsigned int deemph = ucontrol->value.integer.value[0];
int ret = 0;
if (deemph > 1)
return -EINVAL;
mutex_lock(&wm8903->lock);
guard(mutex)(&wm8903->lock);
if (wm8903->deemph != deemph) {
wm8903->deemph = deemph;
wm8903_set_deemph(component);
ret = 1;
return 1;
}
mutex_unlock(&wm8903->lock);
return ret;
return 0;
}
/* ALSA can only do steps of .01dB */

View File

@ -7,6 +7,7 @@
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -864,9 +865,8 @@ static void wm8958_enh_eq_loaded(const struct firmware *fw, void *context)
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
if (fw && (wm8958_dsp2_fw(component, "ENH_EQ", fw, true) == 0)) {
mutex_lock(&wm8994->fw_lock);
guard(mutex)(&wm8994->fw_lock);
wm8994->enh_eq = fw;
mutex_unlock(&wm8994->fw_lock);
}
}
@ -876,9 +876,8 @@ static void wm8958_mbc_vss_loaded(const struct firmware *fw, void *context)
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
if (fw && (wm8958_dsp2_fw(component, "MBC+VSS", fw, true) == 0)) {
mutex_lock(&wm8994->fw_lock);
guard(mutex)(&wm8994->fw_lock);
wm8994->mbc_vss = fw;
mutex_unlock(&wm8994->fw_lock);
}
}
@ -888,9 +887,8 @@ static void wm8958_mbc_loaded(const struct firmware *fw, void *context)
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
if (fw && (wm8958_dsp2_fw(component, "MBC", fw, true) == 0)) {
mutex_lock(&wm8994->fw_lock);
guard(mutex)(&wm8994->fw_lock);
wm8994->mbc = fw;
mutex_unlock(&wm8994->fw_lock);
}
}

View File

@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pm.h>
@ -1564,11 +1565,10 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
int old = wm8962->dsp2_ena;
int ret = 0;
int dsp2_running = snd_soc_component_read(component, WM8962_DSP2_POWER_MANAGEMENT) &
WM8962_DSP2_ENA;
mutex_lock(&wm8962->dsp2_ena_lock);
guard(mutex)(&wm8962->dsp2_ena_lock);
if (ucontrol->value.integer.value[0])
wm8962->dsp2_ena |= 1 << shift;
@ -1576,9 +1576,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
wm8962->dsp2_ena &= ~(1 << shift);
if (wm8962->dsp2_ena == old)
goto out;
ret = 1;
return 0;
if (dsp2_running) {
if (wm8962->dsp2_ena)
@ -1587,10 +1585,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
wm8962_dsp2_stop(component);
}
out:
mutex_unlock(&wm8962->dsp2_ena_lock);
return ret;
return 1;
}
/* The VU bits for the headphones are in a different register to the mute

View File

@ -7,6 +7,7 @@
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*/
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@ -766,7 +767,7 @@ static void active_reference(struct snd_soc_component *component)
{
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
mutex_lock(&wm8994->accdet_lock);
guard(mutex)(&wm8994->accdet_lock);
wm8994->active_refcount++;
@ -775,8 +776,6 @@ static void active_reference(struct snd_soc_component *component)
/* If we're using jack detection go into audio mode */
wm1811_jackdet_set_mode(component, WM1811_JACKDET_MODE_AUDIO);
mutex_unlock(&wm8994->accdet_lock);
}
static void active_dereference(struct snd_soc_component *component)
@ -784,7 +783,7 @@ static void active_dereference(struct snd_soc_component *component)
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
u16 mode;
mutex_lock(&wm8994->accdet_lock);
guard(mutex)(&wm8994->accdet_lock);
wm8994->active_refcount--;
@ -800,8 +799,6 @@ static void active_dereference(struct snd_soc_component *component)
wm1811_jackdet_set_mode(component, mode);
}
mutex_unlock(&wm8994->accdet_lock);
}
static int clk_sys_event(struct snd_soc_dapm_widget *w,
@ -3704,7 +3701,7 @@ static void wm8958_open_circuit_work(struct work_struct *work)
open_circuit_work.work);
struct device *dev = wm8994->wm8994->dev;
mutex_lock(&wm8994->accdet_lock);
guard(mutex)(&wm8994->accdet_lock);
wm1811_micd_stop(wm8994->hubs.component);
@ -3718,8 +3715,6 @@ static void wm8958_open_circuit_work(struct work_struct *work)
snd_soc_jack_report(wm8994->micdet[0].jack, 0,
wm8994->btn_mask |
SND_JACK_HEADSET);
mutex_unlock(&wm8994->accdet_lock);
}
static void wm8958_mic_id(void *data, u16 status)
@ -3777,7 +3772,7 @@ static void wm1811_mic_work(struct work_struct *work)
struct snd_soc_component *component = wm8994->hubs.component;
struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
pm_runtime_get_sync(component->dev);
guard(pm_runtime_active)(component->dev);
/* If required for an external cap force MICBIAS on */
if (control->pdata.jd_ext_cap) {
@ -3785,7 +3780,7 @@ static void wm1811_mic_work(struct work_struct *work)
snd_soc_dapm_sync(dapm);
}
mutex_lock(&wm8994->accdet_lock);
guard(mutex)(&wm8994->accdet_lock);
dev_dbg(component->dev, "Starting mic detection\n");
@ -3803,10 +3798,6 @@ static void wm1811_mic_work(struct work_struct *work)
snd_soc_component_update_bits(component, WM8958_MIC_DETECT_1,
WM8958_MICD_ENA, WM8958_MICD_ENA);
}
mutex_unlock(&wm8994->accdet_lock);
pm_runtime_put(component->dev);
}
static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
@ -4026,15 +4017,10 @@ static void wm8958_mic_work(struct work_struct *work)
mic_complete_work.work);
struct snd_soc_component *component = wm8994->hubs.component;
pm_runtime_get_sync(component->dev);
mutex_lock(&wm8994->accdet_lock);
guard(pm_runtime_active)(component->dev);
guard(mutex)(&wm8994->accdet_lock);
wm8994->mic_id_cb(wm8994->mic_id_cb_data, wm8994->mic_status);
mutex_unlock(&wm8994->accdet_lock);
pm_runtime_put(component->dev);
}
static irqreturn_t wm8958_mic_irq(int irq, void *data)

View File

@ -6,6 +6,7 @@
* Author: Liam Girdwood <lrg@slimlogic.co.uk>
*/
#include <linux/cleanup.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mfd/wm97xx.h>
@ -229,7 +230,7 @@ static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol,
shift = mc->shift & 0xff;
mask = 1 << shift;
mutex_lock(&wm9712->lock);
guard(mutex)(&wm9712->lock);
old = wm9712->hp_mixer[mixer];
if (ucontrol->value.integer.value[0])
wm9712->hp_mixer[mixer] |= mask;
@ -251,8 +252,6 @@ static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol,
&update);
}
mutex_unlock(&wm9712->lock);
return change;
}

View File

@ -11,6 +11,7 @@
* o Support for DAPM
*/
#include <linux/cleanup.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mfd/wm97xx.h>
@ -238,7 +239,7 @@ static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol,
shift = mc->shift & 0xff;
mask = (1 << shift);
mutex_lock(&wm9713->lock);
guard(mutex)(&wm9713->lock);
old = wm9713->hp_mixer[mixer];
if (ucontrol->value.integer.value[0])
wm9713->hp_mixer[mixer] |= mask;
@ -260,8 +261,6 @@ static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol,
&update);
}
mutex_unlock(&wm9713->lock);
return change;
}

View File

@ -348,7 +348,6 @@ int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
struct wm_adsp *dsp = snd_soc_component_get_drvdata(component);
int ret = 1;
if (ucontrol->value.enumerated.item[0] == dsp[e->shift_l].fw)
return 0;
@ -356,16 +355,14 @@ int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
if (ucontrol->value.enumerated.item[0] >= WM_ADSP_NUM_FW)
return -EINVAL;
mutex_lock(&dsp[e->shift_l].cs_dsp.pwr_lock);
guard(mutex)(&dsp[e->shift_l].cs_dsp.pwr_lock);
if (dsp[e->shift_l].cs_dsp.booted || !list_empty(&dsp[e->shift_l].compr_list))
ret = -EBUSY;
return -EBUSY;
else
dsp[e->shift_l].fw = ucontrol->value.enumerated.item[0];
mutex_unlock(&dsp[e->shift_l].cs_dsp.pwr_lock);
return ret;
return 1;
}
EXPORT_SYMBOL_GPL(wm_adsp_fw_put);
@ -450,15 +447,13 @@ static int wm_coeff_put_acked(struct snd_kcontrol *kctl,
if (val == 0)
return 0; /* 0 means no event */
mutex_lock(&cs_ctl->dsp->pwr_lock);
guard(mutex)(&cs_ctl->dsp->pwr_lock);
if (cs_ctl->enabled)
ret = cs_dsp_coeff_write_acked_control(cs_ctl, val);
else
ret = -EPERM;
mutex_unlock(&cs_ctl->dsp->pwr_lock);
if (ret < 0)
return ret;
@ -486,15 +481,13 @@ static int wm_coeff_tlv_get(struct snd_kcontrol *kctl,
struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
int ret = 0;
mutex_lock(&cs_ctl->dsp->pwr_lock);
guard(mutex)(&cs_ctl->dsp->pwr_lock);
ret = cs_dsp_coeff_read_ctrl(cs_ctl, 0, cs_ctl->cache, size);
if (!ret && copy_to_user(bytes, cs_ctl->cache, size))
ret = -EFAULT;
mutex_unlock(&cs_ctl->dsp->pwr_lock);
return ret;
}
@ -694,10 +687,9 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
struct cs_dsp_coeff_ctl *cs_ctl;
int ret;
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
cs_ctl = cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg);
ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len);
mutex_unlock(&dsp->cs_dsp.pwr_lock);
if (ret < 0)
return ret;
@ -709,14 +701,10 @@ EXPORT_SYMBOL_GPL(wm_adsp_write_ctl);
int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len)
{
int ret;
guard(mutex)(&dsp->cs_dsp.pwr_lock);
mutex_lock(&dsp->cs_dsp.pwr_lock);
ret = cs_dsp_coeff_read_ctrl(cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg),
return cs_dsp_coeff_read_ctrl(cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg),
0, buf, len);
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return ret;
}
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
@ -1270,38 +1258,32 @@ int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream)
{
struct wm_adsp_compr *compr, *tmp;
struct snd_soc_pcm_runtime *rtd = stream->private_data;
int ret = 0;
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
if (wm_adsp_fw[dsp->fw].num_caps == 0) {
adsp_err(dsp, "%s: Firmware does not support compressed API\n",
snd_soc_rtd_to_codec(rtd, 0)->name);
ret = -ENXIO;
goto out;
return -ENXIO;
}
if (wm_adsp_fw[dsp->fw].compr_direction != stream->direction) {
adsp_err(dsp, "%s: Firmware does not support stream direction\n",
snd_soc_rtd_to_codec(rtd, 0)->name);
ret = -EINVAL;
goto out;
return -EINVAL;
}
list_for_each_entry(tmp, &dsp->compr_list, list) {
if (!strcmp(tmp->name, snd_soc_rtd_to_codec(rtd, 0)->name)) {
adsp_err(dsp, "%s: Only a single stream supported per dai\n",
snd_soc_rtd_to_codec(rtd, 0)->name);
ret = -EBUSY;
goto out;
return -EBUSY;
}
}
compr = kzalloc_obj(*compr);
if (!compr) {
ret = -ENOMEM;
goto out;
}
if (!compr)
return -ENOMEM;
compr->dsp = dsp;
compr->stream = stream;
@ -1311,10 +1293,7 @@ int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream)
stream->runtime->private_data = compr;
out:
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return ret;
return 0;
}
EXPORT_SYMBOL_GPL(wm_adsp_compr_open);
@ -1324,7 +1303,7 @@ int wm_adsp_compr_free(struct snd_soc_component *component,
struct wm_adsp_compr *compr = stream->runtime->private_data;
struct wm_adsp *dsp = compr->dsp;
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
wm_adsp_compr_detach(compr);
list_del(&compr->list);
@ -1332,8 +1311,6 @@ int wm_adsp_compr_free(struct snd_soc_component *component,
kfree(compr->raw_buf);
kfree(compr);
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return 0;
}
EXPORT_SYMBOL_GPL(wm_adsp_compr_free);
@ -1741,7 +1718,7 @@ int wm_adsp_compr_trigger(struct snd_soc_component *component,
compr_dbg(compr, "Trigger: %d\n", cmd);
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@ -1777,8 +1754,6 @@ int wm_adsp_compr_trigger(struct snd_soc_component *component,
break;
}
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return ret;
}
EXPORT_SYMBOL_GPL(wm_adsp_compr_trigger);
@ -1907,21 +1882,20 @@ int wm_adsp_compr_pointer(struct snd_soc_component *component,
compr_dbg(compr, "Pointer request\n");
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
buf = compr->buf;
if (dsp->fatal_error || !buf || buf->error) {
snd_compr_stop_error(stream, SNDRV_PCM_STATE_XRUN);
ret = -EIO;
goto out;
return -EIO;
}
if (buf->avail < wm_adsp_compr_frag_words(compr)) {
ret = wm_adsp_buffer_update_avail(buf);
if (ret < 0) {
compr_err(compr, "Error reading avail: %d\n", ret);
goto out;
return ret;
}
/*
@ -1934,14 +1908,14 @@ int wm_adsp_compr_pointer(struct snd_soc_component *component,
if (buf->error)
snd_compr_stop_error(stream,
SNDRV_PCM_STATE_XRUN);
goto out;
return ret;
}
ret = wm_adsp_buffer_reenable_irq(buf);
if (ret < 0) {
compr_err(compr, "Failed to re-enable buffer IRQ: %d\n",
ret);
goto out;
return ret;
}
}
}
@ -1950,9 +1924,6 @@ int wm_adsp_compr_pointer(struct snd_soc_component *component,
tstamp->copied_total += buf->avail * CS_DSP_DATA_WORD_SIZE;
tstamp->sampling_rate = compr->sample_rate;
out:
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return ret;
}
EXPORT_SYMBOL_GPL(wm_adsp_compr_pointer);
@ -2063,15 +2034,13 @@ int wm_adsp_compr_copy(struct snd_soc_component *component,
struct wm_adsp *dsp = compr->dsp;
int ret;
mutex_lock(&dsp->cs_dsp.pwr_lock);
guard(mutex)(&dsp->cs_dsp.pwr_lock);
if (stream->direction == SND_COMPRESS_CAPTURE)
ret = wm_adsp_compr_read(compr, buf, count);
else
ret = -ENOTSUPP;
mutex_unlock(&dsp->cs_dsp.pwr_lock);
return ret;
}
EXPORT_SYMBOL_GPL(wm_adsp_compr_copy);

View File

@ -4,6 +4,7 @@
*/
#include <linux/bitops.h>
#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/hwmon.h>
@ -1237,9 +1238,8 @@ static int wsa883x_spkr_event(struct snd_soc_dapm_widget *w,
switch (event) {
case SND_SOC_DAPM_POST_PMU:
mutex_lock(&wsa883x->sp_lock);
wsa883x->pa_on = true;
mutex_unlock(&wsa883x->sp_lock);
scoped_guard(mutex, &wsa883x->sp_lock)
wsa883x->pa_on = true;
switch (wsa883x->dev_mode) {
case RECEIVER:
@ -1290,9 +1290,8 @@ static int wsa883x_spkr_event(struct snd_soc_dapm_widget *w,
WSA883X_GLOBAL_PA_EN_MASK, 0);
snd_soc_component_write_field(component, WSA883X_PDM_WD_CTL,
WSA883X_PDM_EN_MASK, 0);
mutex_lock(&wsa883x->sp_lock);
wsa883x->pa_on = false;
mutex_unlock(&wsa883x->sp_lock);
scoped_guard(mutex, &wsa883x->sp_lock)
wsa883x->pa_on = false;
break;
}
return 0;

View File

@ -1701,9 +1701,8 @@ static int wsa884x_spkr_event(struct snd_soc_dapm_widget *w,
switch (event) {
case SND_SOC_DAPM_POST_PMU:
mutex_lock(&wsa884x->sp_lock);
wsa884x->pa_on = true;
mutex_unlock(&wsa884x->sp_lock);
scoped_guard(mutex, &wsa884x->sp_lock)
wsa884x->pa_on = true;
wsa884x_spkr_post_pmu(component, wsa884x);
@ -1717,9 +1716,8 @@ static int wsa884x_spkr_event(struct snd_soc_dapm_widget *w,
WSA884X_PDM_WD_CTL_PDM_WD_EN_MASK,
0x0);
mutex_lock(&wsa884x->sp_lock);
wsa884x->pa_on = false;
mutex_unlock(&wsa884x->sp_lock);
scoped_guard(mutex, &wsa884x->sp_lock)
wsa884x->pa_on = false;
break;
}