mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
ASoC: Intel: atom: Use guard() for locking
Clean up the code using guard() for spin & 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/20260626082904.32344-5-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
4889a8a73f
commit
71c0f725d3
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/slab.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/tlv.h>
|
||||
|
|
@ -73,14 +74,10 @@ static int sst_fill_and_send_cmd(struct sst_data *drv,
|
|||
u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
|
||||
void *cmd_data, u16 len)
|
||||
{
|
||||
int ret;
|
||||
guard(mutex)(&drv->lock);
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
|
||||
task_id, pipe_id, cmd_data, len);
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
return ret;
|
||||
return sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
|
||||
task_id, pipe_id, cmd_data, len);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -167,7 +164,7 @@ static int sst_slot_get(struct snd_kcontrol *kcontrol,
|
|||
unsigned int val, mux;
|
||||
u8 *map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
guard(mutex)(&drv->lock);
|
||||
val = 1 << ctl_no;
|
||||
/* search which slot/channel has this bit set - there should be only one */
|
||||
for (mux = e->max; mux > 0; mux--)
|
||||
|
|
@ -175,7 +172,6 @@ static int sst_slot_get(struct snd_kcontrol *kcontrol,
|
|||
break;
|
||||
|
||||
ucontrol->value.enumerated.item[0] = mux;
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
dev_dbg(c->dev, "%s - %s map = %#x\n",
|
||||
is_tx ? "tx channel" : "rx slot",
|
||||
|
|
@ -235,7 +231,7 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
|
|||
if (mux > e->max - 1)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
guard(mutex)(&drv->lock);
|
||||
/* first clear all registers of this bit */
|
||||
for (i = 0; i < e->max; i++)
|
||||
map[i] &= ~val;
|
||||
|
|
@ -244,7 +240,6 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
|
|||
/* kctl set to 'none' and we reset the bits so send IPC */
|
||||
ret = sst_check_and_send_slot_map(drv, kcontrol);
|
||||
|
||||
mutex_unlock(&drv->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -258,7 +253,6 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
|
|||
|
||||
ret = sst_check_and_send_slot_map(drv, kcontrol);
|
||||
|
||||
mutex_unlock(&drv->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -354,13 +348,12 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
|
|||
struct sst_algo_control *bc = (void *)kcontrol->private_value;
|
||||
|
||||
dev_dbg(cmpnt->dev, "control_name=%s\n", kcontrol->id.name);
|
||||
mutex_lock(&drv->lock);
|
||||
guard(mutex)(&drv->lock);
|
||||
switch (bc->type) {
|
||||
case SST_ALGO_PARAMS:
|
||||
memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
|
||||
break;
|
||||
default:
|
||||
mutex_unlock(&drv->lock);
|
||||
dev_err(cmpnt->dev, "Invalid Input- algo type:%d\n",
|
||||
bc->type);
|
||||
return -EINVAL;
|
||||
|
|
@ -368,7 +361,6 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
|
|||
/*if pipe is enabled, need to send the algo params from here*/
|
||||
if (bc->w && bc->w->power)
|
||||
ret = sst_send_algo_cmd(drv, bc);
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -475,7 +467,7 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
|
|||
struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
|
||||
struct sst_gain_value *gv = mc->gain_val;
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
guard(mutex)(&drv->lock);
|
||||
|
||||
switch (mc->type) {
|
||||
case SST_GAIN_TLV:
|
||||
|
|
@ -497,7 +489,6 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
|
|||
break;
|
||||
|
||||
default:
|
||||
mutex_unlock(&drv->lock);
|
||||
dev_err(cmpnt->dev, "Invalid Input- gain type:%d\n",
|
||||
mc->type);
|
||||
return -EINVAL;
|
||||
|
|
@ -506,7 +497,6 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
|
|||
if (mc->w && mc->w->power)
|
||||
ret = sst_send_gain_cmd(drv, gv, mc->task_id,
|
||||
mc->pipe_id | mc->instance_id, mc->module_id, 0);
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -521,10 +511,9 @@ static int sst_send_pipe_module_params(struct snd_soc_dapm_widget *w,
|
|||
struct sst_data *drv = snd_soc_component_get_drvdata(c);
|
||||
struct sst_ids *ids = w->priv;
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
guard(mutex)(&drv->lock);
|
||||
sst_find_and_send_pipe_algo(drv, w->name, ids);
|
||||
sst_set_pipe_gain(ids, drv, 0);
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ int sst_register_dsp(struct sst_device *dev)
|
|||
return -EINVAL;
|
||||
if (!try_module_get(dev->dev->driver->owner))
|
||||
return -ENODEV;
|
||||
mutex_lock(&sst_lock);
|
||||
guard(mutex)(&sst_lock);
|
||||
if (sst) {
|
||||
dev_err(dev->dev, "we already have a device %s\n", sst->name);
|
||||
module_put(dev->dev->driver->owner);
|
||||
|
|
@ -42,7 +42,7 @@ int sst_register_dsp(struct sst_device *dev)
|
|||
}
|
||||
dev_dbg(dev->dev, "registering device %s\n", dev->name);
|
||||
sst = dev;
|
||||
mutex_unlock(&sst_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(sst_register_dsp);
|
||||
|
|
@ -54,17 +54,15 @@ int sst_unregister_dsp(struct sst_device *dev)
|
|||
if (dev != sst)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&sst_lock);
|
||||
guard(mutex)(&sst_lock);
|
||||
|
||||
if (!sst) {
|
||||
mutex_unlock(&sst_lock);
|
||||
if (!sst)
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
module_put(sst->dev->driver->owner);
|
||||
dev_dbg(dev->dev, "unreg %s\n", sst->name);
|
||||
sst = NULL;
|
||||
mutex_unlock(&sst_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(sst_unregister_dsp);
|
||||
|
|
@ -104,21 +102,14 @@ static int sst_media_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
|
|||
void sst_set_stream_status(struct sst_runtime_stream *stream,
|
||||
int state)
|
||||
{
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&stream->status_lock, flags);
|
||||
guard(spinlock_irqsave)(&stream->status_lock);
|
||||
stream->stream_status = state;
|
||||
spin_unlock_irqrestore(&stream->status_lock, flags);
|
||||
}
|
||||
|
||||
static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
|
||||
{
|
||||
int state;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&stream->status_lock, flags);
|
||||
state = stream->stream_status;
|
||||
spin_unlock_irqrestore(&stream->status_lock, flags);
|
||||
return state;
|
||||
guard(spinlock_irqsave)(&stream->status_lock);
|
||||
return stream->stream_status;
|
||||
}
|
||||
|
||||
static void sst_fill_alloc_params(struct snd_pcm_substream *substream,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/sched.h>
|
||||
|
|
@ -180,9 +181,8 @@ void intel_sst_clear_intr_mrfld(struct intel_sst_drv *sst_drv_ctx)
|
|||
union interrupt_reg_mrfld isr;
|
||||
union interrupt_reg_mrfld imr;
|
||||
union ipc_header_mrfld clear_ipc;
|
||||
unsigned long irq_flags;
|
||||
|
||||
spin_lock_irqsave(&sst_drv_ctx->ipc_spin_lock, irq_flags);
|
||||
guard(spinlock_irqsave)(&sst_drv_ctx->ipc_spin_lock);
|
||||
imr.full = sst_shim_read64(sst_drv_ctx->shim, SST_IMRX);
|
||||
isr.full = sst_shim_read64(sst_drv_ctx->shim, SST_ISRX);
|
||||
|
||||
|
|
@ -200,7 +200,6 @@ void intel_sst_clear_intr_mrfld(struct intel_sst_drv *sst_drv_ctx)
|
|||
/* un mask busy interrupt */
|
||||
imr.part.busy_interrupt = 0;
|
||||
sst_shim_write64(sst_drv_ctx->shim, SST_IMRX, imr.full);
|
||||
spin_unlock_irqrestore(&sst_drv_ctx->ipc_spin_lock, irq_flags);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/fs.h>
|
||||
|
|
@ -64,9 +65,8 @@ u64 sst_shim_read64(void __iomem *addr, int offset)
|
|||
void sst_set_fw_state_locked(
|
||||
struct intel_sst_drv *sst_drv_ctx, int sst_state)
|
||||
{
|
||||
mutex_lock(&sst_drv_ctx->sst_lock);
|
||||
guard(mutex)(&sst_drv_ctx->sst_lock);
|
||||
sst_drv_ctx->sst_state = sst_state;
|
||||
mutex_unlock(&sst_drv_ctx->sst_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -302,18 +302,17 @@ int sst_assign_pvt_id(struct intel_sst_drv *drv)
|
|||
{
|
||||
int local;
|
||||
|
||||
spin_lock(&drv->block_lock);
|
||||
guard(spinlock)(&drv->block_lock);
|
||||
/* find first zero index from lsb */
|
||||
local = ffz(drv->pvt_id);
|
||||
dev_dbg(drv->dev, "pvt_id assigned --> %d\n", local);
|
||||
if (local >= SST_MAX_BLOCKS){
|
||||
spin_unlock(&drv->block_lock);
|
||||
dev_err(drv->dev, "PVT _ID error: no free id blocks ");
|
||||
return -EINVAL;
|
||||
}
|
||||
/* toggle the index */
|
||||
change_bit(local, &drv->pvt_id);
|
||||
spin_unlock(&drv->block_lock);
|
||||
|
||||
return local;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user