From 5c19da34df029fdc29fec1bedf210af7d2c4fccf Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Mon, 12 Jan 2026 12:09:58 +0200 Subject: ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it makes sense Replace the manual mutex lock/unlock pairs with guard()/scoped_guard(). Only code refactoring, and no behavior change. Signed-off-by: Peter Ujfalusi Reviewed-by: Daniel Baluta Reviewed-by: Ranjani Sridharan Link: https://patch.msgid.link/20260112101004.7648-2-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown --- sound/soc/sof/sof-audio.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'sound/soc/sof/sof-audio.c') diff --git a/sound/soc/sof/sof-audio.c b/sound/soc/sof/sof-audio.c index a9664b4cf43f..d55ee7343f8e 100644 --- a/sound/soc/sof/sof-audio.c +++ b/sound/soc/sof/sof-audio.c @@ -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 @@ use_count_dec: 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; } -- cgit v1.2.3