mirror of
https://github.com/torvalds/linux.git
synced 2026-09-26 01:52:03 +02:00
ASoC: codecs: wm_adsp: Use guard() for mutex locks
Clean up the code using guard() for mutex locks. Merely code refactoring, and no behavior change. Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com> 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-26-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
a65ce15323
commit
46f3500915
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user