ASoC: SOF: Use guard()/scoped_guard() for locks when

Merge series from Peter Ujfalusi <peter.ujfalusi@linux.intel.com>:

Only code refactoring, and no behavior change.

Replace most of the manual *lock/*unlock handling with guard use.
This commit is contained in:
Mark Brown 2026-01-13 11:55:35 +00:00
commit 28e5a3de98
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
22 changed files with 95 additions and 220 deletions

View File

@ -190,15 +190,13 @@ irqreturn_t acp_sof_ipc_irq_thread(int irq, void *context)
dsp_ack = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + dsp_ack_write);
if (dsp_ack) {
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
spin_lock_irq(&sdev->ipc_lock);
guard(spinlock_irq)(&sdev->ipc_lock);
/* handle immediate reply from DSP core */
acp_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, 0);
/* set the done bit */
acp_dsp_ipc_dsp_done(sdev);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_BOOT_COMPLETE: %#x\n",
dsp_ack);

View File

@ -81,14 +81,10 @@ EXPORT_SYMBOL(imx8_dump);
static void imx_handle_reply(struct imx_dsp_ipc *ipc)
{
struct snd_sof_dev *sdev;
unsigned long flags;
struct snd_sof_dev *sdev = imx_dsp_get_data(ipc);
sdev = imx_dsp_get_data(ipc);
spin_lock_irqsave(&sdev->ipc_lock, flags);
guard(spinlock_irqsave)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, 0);
spin_unlock_irqrestore(&sdev->ipc_lock, flags);
}
static void imx_handle_request(struct imx_dsp_ipc *ipc)

View File

@ -143,9 +143,6 @@ irqreturn_t atom_irq_thread(int irq, void *context)
/* reply message from DSP */
if (ipcx & SHIM_BYT_IPCX_DONE) {
spin_lock_irq(&sdev->ipc_lock);
/*
* handle immediate reply from DSP core. If the msg is
* found, set done bit in cmd_done which is called at the
@ -153,11 +150,9 @@ irqreturn_t atom_irq_thread(int irq, void *context)
* because the done bit can't be set in cmd_done function
* which is triggered by msg
*/
guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, ipcx);
atom_dsp_done(sdev);
spin_unlock_irq(&sdev->ipc_lock);
}
/* new message from DSP */

View File

@ -315,9 +315,6 @@ static irqreturn_t bdw_irq_thread(int irq, void *context)
snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR,
SHIM_IMRX, SHIM_IMRX_DONE,
SHIM_IMRX_DONE);
spin_lock_irq(&sdev->ipc_lock);
/*
* handle immediate reply from DSP core. If the msg is
* found, set done bit in cmd_done which is called at the
@ -325,11 +322,9 @@ static irqreturn_t bdw_irq_thread(int irq, void *context)
* because the done bit can't be set in cmd_done function
* which is triggered by msg
*/
guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, ipcx);
bdw_dsp_done(sdev);
spin_unlock_irq(&sdev->ipc_lock);
}
ipcd = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCD);

View File

@ -69,13 +69,10 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
spin_lock_irq(&sdev->ipc_lock);
guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
cnl_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",
@ -141,15 +138,11 @@ irqreturn_t cnl_ipc_irq_thread(int irq, void *context)
CNL_DSP_REG_HIPCCTL_DONE, 0);
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
spin_lock_irq(&sdev->ipc_lock);
/* handle immediate reply from DSP core */
guard(spinlock_irq)(&sdev->ipc_lock);
hda_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, msg);
cnl_ipc_dsp_done(sdev);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n",
msg);

View File

@ -58,7 +58,7 @@ hda_link_stream_assign(struct hdac_bus *bus, struct snd_pcm_substream *substream
return NULL;
}
spin_lock_irq(&bus->reg_lock);
guard(spinlock_irq)(&bus->reg_lock);
list_for_each_entry(hstream, &bus->stream_list, list) {
struct hdac_ext_stream *hext_stream =
stream_to_hdac_ext_stream(hstream);
@ -110,7 +110,6 @@ hda_link_stream_assign(struct hdac_bus *bus, struct snd_pcm_substream *substream
res->link_locked = 1;
res->link_substream = substream;
}
spin_unlock_irq(&bus->reg_lock);
return res;
}
@ -311,7 +310,7 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
if (pipe_widget->instance_id < 0)
return 0;
mutex_lock(&ipc4_data->pipeline_state_mutex);
guard(mutex)(&ipc4_data->pipeline_state_mutex);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@ -323,16 +322,16 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_PAUSED);
if (ret < 0)
goto out;
return ret;
pipeline->state = SOF_IPC4_PIPE_PAUSED;
break;
default:
dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
ret = -EINVAL;
}
out:
mutex_unlock(&ipc4_data->pipeline_state_mutex);
return ret;
}
@ -388,7 +387,7 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
if (pipe_widget->instance_id < 0)
return 0;
mutex_lock(&ipc4_data->pipeline_state_mutex);
guard(mutex)(&ipc4_data->pipeline_state_mutex);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@ -396,14 +395,16 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_PAUSED);
if (ret < 0)
goto out;
return ret;
pipeline->state = SOF_IPC4_PIPE_PAUSED;
}
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_RUNNING);
if (ret < 0)
goto out;
return ret;
pipeline->state = SOF_IPC4_PIPE_RUNNING;
swidget->spipe->started_count++;
break;
@ -411,7 +412,8 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_RUNNING);
if (ret < 0)
goto out;
return ret;
pipeline->state = SOF_IPC4_PIPE_RUNNING;
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
@ -429,8 +431,7 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = -EINVAL;
break;
}
out:
mutex_unlock(&ipc4_data->pipeline_state_mutex);
return ret;
}

View File

@ -204,13 +204,10 @@ irqreturn_t hda_dsp_ipc4_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
spin_lock_irq(&sdev->ipc_lock);
guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
hda_dsp_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",
@ -289,16 +286,12 @@ irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context)
* reply.
*/
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
spin_lock_irq(&sdev->ipc_lock);
/* handle immediate reply from DSP core */
guard(spinlock_irq)(&sdev->ipc_lock);
hda_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, msg);
/* set the done bit */
hda_dsp_ipc_dsp_done(sdev);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n",
msg);

View File

@ -524,11 +524,8 @@ void hdac_bus_eml_enable_interrupt(struct hdac_bus *bus, bool alt, int elid, boo
hlink = &h2link->hext_link;
mutex_lock(&h2link->eml_lock);
hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
mutex_unlock(&h2link->eml_lock);
scoped_guard(mutex, &h2link->eml_lock)
hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
}
EXPORT_SYMBOL_NS(hdac_bus_eml_enable_interrupt, "SND_SOC_SOF_HDA_MLINK");
@ -837,11 +834,8 @@ int hdac_bus_eml_sdw_set_lsdiid(struct hdac_bus *bus, int sublink, int dev_num)
hlink = &h2link->hext_link;
mutex_lock(&h2link->eml_lock);
hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
mutex_unlock(&h2link->eml_lock);
scoped_guard(mutex, &h2link->eml_lock)
hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
return 0;
} EXPORT_SYMBOL_NS(hdac_bus_eml_sdw_set_lsdiid, "SND_SOC_SOF_HDA_MLINK");
@ -875,12 +869,8 @@ int hdac_bus_eml_sdw_map_stream_ch(struct hdac_bus *bus, int sublink, int y,
lchan = 0;
}
mutex_lock(&h2link->eml_lock);
hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan,
stream_id, dir);
mutex_unlock(&h2link->eml_lock);
scoped_guard(mutex, &h2link->eml_lock)
hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan, stream_id, dir);
val = readw(pcmsycm);
@ -1012,11 +1002,8 @@ int hdac_bus_eml_enable_offload(struct hdac_bus *bus, bool alt, int elid, bool e
hlink = &h2link->hext_link;
mutex_lock(&h2link->eml_lock);
hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
mutex_unlock(&h2link->eml_lock);
scoped_guard(mutex, &h2link->eml_lock)
hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
return 0;
}

View File

@ -724,12 +724,12 @@ int hda_dsp_stream_hw_free(struct snd_sof_dev *sdev,
struct hdac_bus *bus = sof_to_bus(sdev);
u32 mask = BIT(hstream->index);
spin_lock_irq(&bus->reg_lock);
guard(spinlock_irq)(&bus->reg_lock);
/* couple host and link DMA if link DMA channel is idle */
if (!hext_stream->link_locked)
snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR,
SOF_HDA_REG_PP_PPCTL, mask, 0);
spin_unlock_irq(&bus->reg_lock);
}
hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
@ -747,7 +747,7 @@ bool hda_dsp_check_stream_irq(struct snd_sof_dev *sdev)
u32 status;
/* The function can be called at irq thread, so use spin_lock_irq */
spin_lock_irq(&bus->reg_lock);
guard(spinlock_irq)(&bus->reg_lock);
status = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
@ -757,8 +757,6 @@ bool hda_dsp_check_stream_irq(struct snd_sof_dev *sdev)
if (status != 0xffffffff)
ret = true;
spin_unlock_irq(&bus->reg_lock);
return ret;
}
EXPORT_SYMBOL_NS(hda_dsp_check_stream_irq, "SND_SOC_SOF_INTEL_HDA_COMMON");
@ -842,7 +840,7 @@ irqreturn_t hda_dsp_stream_threaded_handler(int irq, void *context)
* unsolicited responses from the codec
*/
for (i = 0, active = true; i < 10 && active; i++) {
spin_lock_irq(&bus->reg_lock);
guard(spinlock_irq)(&bus->reg_lock);
status = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
@ -853,7 +851,6 @@ irqreturn_t hda_dsp_stream_threaded_handler(int irq, void *context)
if (status & AZX_INT_CTRL_EN) {
active |= hda_codec_check_rirb_status(sdev);
}
spin_unlock_irq(&bus->reg_lock);
}
return IRQ_HANDLED;

View File

@ -596,13 +596,10 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
spin_lock_irq(&sdev->ipc_lock);
guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
mtl_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",

View File

@ -47,7 +47,7 @@ int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
* The spin-lock is needed to protect message objects against other
* atomic contexts.
*/
spin_lock_irq(&sdev->ipc_lock);
guard(spinlock_irq)(&sdev->ipc_lock);
/* initialise the message */
msg = &ipc->msg;
@ -66,8 +66,6 @@ int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
if (!ret)
msg->ipc_complete = false;
spin_unlock_irq(&sdev->ipc_lock);
return ret;
}
@ -225,9 +223,8 @@ void snd_sof_ipc_free(struct snd_sof_dev *sdev)
return;
/* disable sending of ipc's */
mutex_lock(&ipc->tx_mutex);
ipc->disable_ipc_tx = true;
mutex_unlock(&ipc->tx_mutex);
scoped_guard(mutex, &ipc->tx_mutex)
ipc->disable_ipc_tx = true;
if (ipc->ops->exit)
ipc->ops->exit(sdev);

View File

@ -2427,9 +2427,9 @@ static int sof_ipc3_free_widgets_in_list(struct snd_sof_dev *sdev, bool include_
/* Do not free widgets for static pipelines with FW older than SOF2.2 */
if (!verify && !swidget->dynamic_pipeline_widget &&
SOF_FW_VER(v->major, v->minor, v->micro) < SOF_FW_VER(2, 2, 0)) {
mutex_lock(&swidget->setup_mutex);
swidget->use_count = 0;
mutex_unlock(&swidget->setup_mutex);
scoped_guard(mutex, &swidget->setup_mutex)
swidget->use_count = 0;
if (swidget->spipe)
swidget->spipe->complete = 0;
continue;

View File

@ -378,7 +378,7 @@ static int sof_ipc3_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
/* Serialise IPC TX */
mutex_lock(&ipc->tx_mutex);
guard(mutex)(&ipc->tx_mutex);
ret = ipc3_tx_msg_unlocked(ipc, msg_data, msg_bytes, reply_data, reply_bytes);
@ -405,8 +405,6 @@ static int sof_ipc3_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
}
mutex_unlock(&ipc->tx_mutex);
return ret;
}
@ -477,7 +475,7 @@ static int sof_ipc3_set_get_data(struct snd_sof_dev *sdev, void *data, size_t da
memcpy(cdata_chunk, cdata, hdr_bytes);
/* Serialise IPC TX */
mutex_lock(&sdev->ipc->tx_mutex);
guard(mutex)(&ipc->tx_mutex);
/* copy the payload data in a loop */
for (i = 0; i < num_msg; i++) {
@ -511,8 +509,6 @@ static int sof_ipc3_set_get_data(struct snd_sof_dev *sdev, void *data, size_t da
sof_ipc3_dump_payload(sdev, payload, data_bytes - header_bytes);
}
mutex_unlock(&sdev->ipc->tx_mutex);
kfree(cdata_chunk);
return ret;

View File

@ -118,22 +118,19 @@ static int sof_ipc4_mtrace_dfs_open(struct inode *inode, struct file *file)
struct sof_mtrace_core_data *core_data = inode->i_private;
int ret;
mutex_lock(&core_data->buffer_lock);
guard(mutex)(&core_data->buffer_lock);
if (core_data->log_buffer) {
ret = -EBUSY;
goto out;
}
if (core_data->log_buffer)
return -EBUSY;
ret = debugfs_file_get(file->f_path.dentry);
if (unlikely(ret))
goto out;
return ret;
core_data->log_buffer = kmalloc(SOF_IPC4_DEBUG_SLOT_SIZE, GFP_KERNEL);
if (!core_data->log_buffer) {
debugfs_file_put(file->f_path.dentry);
ret = -ENOMEM;
goto out;
return -ENOMEM;
}
ret = simple_open(inode, file);
@ -142,9 +139,6 @@ static int sof_ipc4_mtrace_dfs_open(struct inode *inode, struct file *file)
debugfs_file_put(file->f_path.dentry);
}
out:
mutex_unlock(&core_data->buffer_lock);
return ret;
}
@ -281,10 +275,10 @@ static int sof_ipc4_mtrace_dfs_release(struct inode *inode, struct file *file)
debugfs_file_put(file->f_path.dentry);
mutex_lock(&core_data->buffer_lock);
kfree(core_data->log_buffer);
core_data->log_buffer = NULL;
mutex_unlock(&core_data->buffer_lock);
scoped_guard(mutex, &core_data->buffer_lock) {
kfree(core_data->log_buffer);
core_data->log_buffer = NULL;
}
return 0;
}

View File

@ -487,7 +487,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
return -ENOMEM;
}
mutex_lock(&ipc4_data->pipeline_state_mutex);
guard(mutex)(&ipc4_data->pipeline_state_mutex);
/*
* IPC4 requires pipelines to be triggered in order starting at the sink and
@ -580,7 +580,6 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
}
free:
mutex_unlock(&ipc4_data->pipeline_state_mutex);
kfree(trigger_list);
kfree(pipe_priority);
return ret;

View File

@ -3241,7 +3241,7 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
int ret = 0;
mutex_lock(&ipc4_data->pipeline_state_mutex);
guard(mutex)(&ipc4_data->pipeline_state_mutex);
/* freeing a pipeline frees all the widgets associated with it */
if (swidget->id == snd_soc_dapm_scheduler) {
@ -3252,7 +3252,6 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
if (pipeline->use_chain_dma) {
dev_warn(sdev->dev, "use_chain_dma set for scheduler %s",
swidget->widget->name);
mutex_unlock(&ipc4_data->pipeline_state_mutex);
return 0;
}
@ -3280,8 +3279,6 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
ida_free(&fw_module->m_ida, swidget->instance_id);
}
mutex_unlock(&ipc4_data->pipeline_state_mutex);
return ret;
}

View File

@ -412,7 +412,7 @@ static int sof_ipc4_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
/* Serialise IPC TX */
mutex_lock(&ipc->tx_mutex);
guard(mutex)(&ipc->tx_mutex);
ret = ipc4_tx_msg_unlocked(ipc, msg_data, msg_bytes, reply_data, reply_bytes);
@ -429,8 +429,6 @@ static int sof_ipc4_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
sof_ipc4_dump_payload(sdev, msg->data_ptr, msg->data_size);
}
mutex_unlock(&ipc->tx_mutex);
return ret;
}
@ -506,7 +504,7 @@ static int sof_ipc4_set_get_data(struct snd_sof_dev *sdev, void *data,
}
/* Serialise IPC TX */
mutex_lock(&sdev->ipc->tx_mutex);
guard(mutex)(&sdev->ipc->tx_mutex);
do {
size_t tx_size, rx_size;
@ -590,8 +588,6 @@ static int sof_ipc4_set_get_data(struct snd_sof_dev *sdev, void *data,
if (sof_debug_check_flag(SOF_DBG_DUMP_IPC_MESSAGE_PAYLOAD))
sof_ipc4_dump_payload(sdev, ipc4_msg->data_ptr, ipc4_msg->data_size);
mutex_unlock(&sdev->ipc->tx_mutex);
kfree(tx_payload_for_get);
return ret;

View File

@ -107,11 +107,9 @@ EXPORT_SYMBOL(mtk_adsp_send_msg);
void mtk_adsp_handle_reply(struct mtk_adsp_ipc *ipc)
{
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
unsigned long flags;
spin_lock_irqsave(&priv->sdev->ipc_lock, flags);
guard(spinlock_irqsave)(&priv->sdev->ipc_lock);
snd_sof_ipc_process_reply(priv->sdev, 0);
spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags);
}
EXPORT_SYMBOL(mtk_adsp_handle_reply);

View File

@ -38,13 +38,8 @@ bool snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset,
bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
u32 mask, u32 value)
{
unsigned long flags;
bool change;
spin_lock_irqsave(&sdev->hw_lock, flags);
change = snd_sof_pci_update_bits_unlocked(sdev, offset, mask, value);
spin_unlock_irqrestore(&sdev->hw_lock, flags);
return change;
guard(spinlock_irqsave)(&sdev->hw_lock);
return snd_sof_pci_update_bits_unlocked(sdev, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_pci_update_bits);
@ -90,28 +85,16 @@ EXPORT_SYMBOL(snd_sof_dsp_update_bits64_unlocked);
bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
u32 mask, u32 value)
{
unsigned long flags;
bool change;
spin_lock_irqsave(&sdev->hw_lock, flags);
change = snd_sof_dsp_update_bits_unlocked(sdev, bar, offset, mask,
value);
spin_unlock_irqrestore(&sdev->hw_lock, flags);
return change;
guard(spinlock_irqsave)(&sdev->hw_lock);
return snd_sof_dsp_update_bits_unlocked(sdev, bar, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits);
bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar, u32 offset,
u64 mask, u64 value)
{
unsigned long flags;
bool change;
spin_lock_irqsave(&sdev->hw_lock, flags);
change = snd_sof_dsp_update_bits64_unlocked(sdev, bar, offset, mask,
value);
spin_unlock_irqrestore(&sdev->hw_lock, flags);
return change;
guard(spinlock_irqsave)(&sdev->hw_lock);
return snd_sof_dsp_update_bits64_unlocked(sdev, bar, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits64);
@ -134,11 +117,8 @@ void snd_sof_dsp_update_bits_forced_unlocked(struct snd_sof_dev *sdev, u32 bar,
void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
u32 offset, u32 mask, u32 value)
{
unsigned long flags;
spin_lock_irqsave(&sdev->hw_lock, flags);
guard(spinlock_irqsave)(&sdev->hw_lock);
snd_sof_dsp_update_bits_forced_unlocked(sdev, bar, offset, mask, value);
spin_unlock_irqrestore(&sdev->hw_lock, flags);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits_forced);

View File

@ -287,16 +287,12 @@ static inline int
snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
const struct sof_dsp_power_state *target_state)
{
int ret = 0;
mutex_lock(&sdev->power_state_access);
guard(mutex)(&sdev->power_state_access);
if (sof_ops(sdev)->set_power_state)
ret = sof_ops(sdev)->set_power_state(sdev, target_state);
return sof_ops(sdev)->set_power_state(sdev, target_state);
mutex_unlock(&sdev->power_state_access);
return ret;
return 0;
}
/* debug */

View File

@ -121,13 +121,8 @@ static int sof_widget_free_unlocked(struct snd_sof_dev *sdev,
int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
int ret;
mutex_lock(&swidget->setup_mutex);
ret = sof_widget_free_unlocked(sdev, swidget);
mutex_unlock(&swidget->setup_mutex);
return ret;
guard(mutex)(&swidget->setup_mutex);
return sof_widget_free_unlocked(sdev, swidget);
}
EXPORT_SYMBOL(sof_widget_free);
@ -240,13 +235,8 @@ static int sof_widget_setup_unlocked(struct snd_sof_dev *sdev,
int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
int ret;
mutex_lock(&swidget->setup_mutex);
ret = sof_widget_setup_unlocked(sdev, swidget);
mutex_unlock(&swidget->setup_mutex);
return ret;
guard(mutex)(&swidget->setup_mutex);
return sof_widget_setup_unlocked(sdev, swidget);
}
EXPORT_SYMBOL(sof_widget_setup);
@ -377,24 +367,22 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
else
swidget = sroute->src_widget;
mutex_lock(&swidget->setup_mutex);
if (!swidget->use_count) {
mutex_unlock(&swidget->setup_mutex);
continue;
}
scoped_guard(mutex, &swidget->setup_mutex) {
if (!swidget->use_count)
continue;
if (tplg_ops && tplg_ops->route_setup) {
/*
* this route will get freed when either the source widget or the sink
* widget is freed during hw_free
*/
ret = tplg_ops->route_setup(sdev, sroute);
if (!ret)
sroute->setup = true;
if (tplg_ops && tplg_ops->route_setup) {
/*
* this route will get freed when either the
* source widget or the sink widget is freed
* during hw_free
*/
ret = tplg_ops->route_setup(sdev, sroute);
if (!ret)
sroute->setup = true;
}
}
mutex_unlock(&swidget->setup_mutex);
if (ret < 0)
return ret;
}

View File

@ -265,9 +265,8 @@ int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
}
/* add to list of SOF client devices */
mutex_lock(&sdev->ipc_client_mutex);
list_add(&centry->list, &sdev->ipc_client_list);
mutex_unlock(&sdev->ipc_client_mutex);
scoped_guard(mutex, &sdev->ipc_client_mutex)
list_add(&centry->list, &sdev->ipc_client_list);
return 0;
@ -285,7 +284,7 @@ void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 i
{
struct sof_client_dev_entry *centry;
mutex_lock(&sdev->ipc_client_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
/*
* sof_client_auxdev_release() will be invoked to free up memory
@ -301,8 +300,6 @@ void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 i
break;
}
}
mutex_unlock(&sdev->ipc_client_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_dev_unregister, "SND_SOC_SOF_CLIENT");
@ -400,7 +397,7 @@ int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
const struct auxiliary_driver *adrv;
struct sof_client_dev_entry *centry;
mutex_lock(&sdev->ipc_client_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(centry, &sdev->ipc_client_list, list) {
struct sof_client_dev *cdev = &centry->client_dev;
@ -414,8 +411,6 @@ int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
adrv->suspend(&cdev->auxdev, state);
}
mutex_unlock(&sdev->ipc_client_mutex);
return 0;
}
EXPORT_SYMBOL_NS_GPL(sof_suspend_clients, "SND_SOC_SOF_CLIENT");
@ -425,7 +420,7 @@ int sof_resume_clients(struct snd_sof_dev *sdev)
const struct auxiliary_driver *adrv;
struct sof_client_dev_entry *centry;
mutex_lock(&sdev->ipc_client_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(centry, &sdev->ipc_client_list, list) {
struct sof_client_dev *cdev = &centry->client_dev;
@ -439,8 +434,6 @@ int sof_resume_clients(struct snd_sof_dev *sdev)
adrv->resume(&cdev->auxdev);
}
mutex_unlock(&sdev->ipc_client_mutex);
return 0;
}
EXPORT_SYMBOL_NS_GPL(sof_resume_clients, "SND_SOC_SOF_CLIENT");
@ -532,14 +525,11 @@ void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
return;
}
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->client_event_handler_mutex);
list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
if (event->ipc_msg_type == msg_type)
event->callback(event->cdev, msg_buf);
}
mutex_unlock(&sdev->client_event_handler_mutex);
}
int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
@ -573,9 +563,8 @@ int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
event->callback = callback;
/* add to list of SOF client devices */
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->client_event_handler_mutex);
list_add(&event->list, &sdev->ipc_rx_handler_list);
mutex_unlock(&sdev->client_event_handler_mutex);
return 0;
}
@ -587,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
struct sof_ipc_event_entry *event;
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) {
@ -596,8 +585,6 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
break;
}
}
mutex_unlock(&sdev->client_event_handler_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_unregister_ipc_rx_handler, "SND_SOC_SOF_CLIENT");
@ -606,12 +593,10 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
{
struct sof_state_event_entry *event;
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->fw_state_handler_list, list)
event->callback(event->cdev, sdev->fw_state);
mutex_unlock(&sdev->client_event_handler_mutex);
}
int sof_client_register_fw_state_handler(struct sof_client_dev *cdev,
@ -631,9 +616,8 @@ int sof_client_register_fw_state_handler(struct sof_client_dev *cdev,
event->callback = callback;
/* add to list of SOF client devices */
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->client_event_handler_mutex);
list_add(&event->list, &sdev->fw_state_handler_list);
mutex_unlock(&sdev->client_event_handler_mutex);
return 0;
}
@ -644,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
struct sof_state_event_entry *event;
mutex_lock(&sdev->client_event_handler_mutex);
guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->fw_state_handler_list, list) {
if (event->cdev == cdev) {
@ -653,8 +637,6 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
break;
}
}
mutex_unlock(&sdev->client_event_handler_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_unregister_fw_state_handler, "SND_SOC_SOF_CLIENT");