ASoC: codecs: Use guard() for mutex & spin lock - part 1
Subsystems (8)
v2 cover ASoC: codecs: Use guard() for mutex & spin lock - part 1
From: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in ASoC codec drivers to use the guard() and scoped_guard() helpers.
This series is split out from a larger 78-patch series to improve reviewability and allow for incremental review:
https://lore.kernel.org/all/[email protected]/
The changes are purely refactoring and have no functional impact.
Compile-tested only.
link v1:
https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Added Reviewed-by tags from Charles and Richard.
- Incorporated Charles's review comments:
+ cs48l32: Removed the unnecessary else block so update_bits() is not called when no changes are needed.
+ cs42l43: Switched to a helper function to avoid code duplication, while keeping the guard() conversion since it eliminates 12 goto labels.
+ arizona-jack: Reworked the code to use an if/else structure, avoiding code duplication after removing the goto label.
Best regards,
Phuc
bui duc phuc (24):
ASoC: codecs: ab8500: Use guard() for mutex locks
ASoC: codecs: ak4613: Use guard() for mutex locks
ASoC: codecs: arizona-jack: Use guard() cleanup helpers
ASoC: codecs: arizona: Use guard() for mutex locks
ASoC: codecs: aw87390: Use guard() for mutex locks
ASoC: codecs: aw88081: Use guard() for mutex locks
ASoC: codecs: aw88166: Use guard() for mutex locks
ASoC: codecs: aw88261: Use guard() for mutex locks
ASoC: codecs: aw88395: Use guard() for mutex locks
ASoC: codecs: aw88399: Use guard() for mutex locks
ASoC: codecs: cros_ec_codec: Use guard() for mutex locks
ASoC: codecs: cs-amp-lib: Use guard() for mutex locks
ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
ASoC: codecs: cs42l42: Use guard() cleanup helpers
ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers
ASoC: codecs: cs42l84: Use guard() for mutex locks
ASoC: codecs: cs43130: Use guard() for mutex locks
ASoC: codecs: cs47l15: Use guard() for mutex locks
ASoC: codecs: cs47l35: Use guard() for mutex locks
ASoC: codecs: cs47l85: Use guard() for mutex locks
ASoC: codecs: cs47l90: Use guard() for mutex locks
ASoC: codecs: cs47l92: Use guard() for mutex locks
ASoC: codecs: cs48l32: Use guard() for mutex locks
ASoC: codecs: cs2072x: Use guard() for mutex locks
sound/soc/codecs/ab8500-codec.c | 12 +-- sound/soc/codecs/ak4613.c | 83 ++++++++------- sound/soc/codecs/arizona-jack.c | 116 ++++++++++----------- sound/soc/codecs/arizona.c | 26 ++--- sound/soc/codecs/aw87390.c | 10 +- sound/soc/codecs/aw88081.c | 18 ++-- sound/soc/codecs/aw88166.c | 24 ++--- sound/soc/codecs/aw88261.c | 21 ++-- sound/soc/codecs/aw88395/aw88395.c | 24 ++--- sound/soc/codecs/aw88395/aw88395_device.c | 40 +++----- sound/soc/codecs/aw88399.c | 15 +-- sound/soc/codecs/cros_ec_codec.c | 18 ++-- sound/soc/codecs/cs-amp-lib.c | 11 +- sound/soc/codecs/cs35l56-shared.c | 19 ++-- sound/soc/codecs/cs42l42.c | 54 +++++----- sound/soc/codecs/cs42l43-jack.c | 120 ++++++++++------------ sound/soc/codecs/cs42l43.c | 16 +-- sound/soc/codecs/cs42l84.c | 10 +- sound/soc/codecs/cs43130.c | 72 ++++++------- sound/soc/codecs/cs47l15.c | 11 +- sound/soc/codecs/cs47l35.c | 11 +- sound/soc/codecs/cs47l85.c | 11 +- sound/soc/codecs/cs47l90.c | 11 +- sound/soc/codecs/cs47l92.c | 11 +- sound/soc/codecs/cs48l32.c | 26 ++--- sound/soc/codecs/cx2072x.c | 5 +- 26 files changed, 346 insertions(+), 449 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/24 ASoC: codecs: ab8500: Use guard() for mutex locks
From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/ab8500-codec.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
sound/soc/codecs/ab8500-codec.c +5 -7
@@ -14,6 +14,7 @@* for ST-Ericsson. */ +#include <linux/cleanup.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h>
@@ -989,9 +990,8 @@ static int sid_status_control_get(struct snd_kcontrol *kcontrol,struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct ab8500_codec_drvdata *drvdata =dev_get_drvdata (component->dev); -mutex_lock (&drvdata->ctrl_lock); +guard (mutex)(&drvdata->ctrl_lock); ucontrol->value.enumerated.item[0 ] = drvdata->sid_status; -mutex_unlock (&drvdata->ctrl_lock);return 0 ; }
@@ -1014,7 +1014,7 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol,return -EIO ; } -mutex_lock (&drvdata->ctrl_lock); +guard (mutex)(&drvdata->ctrl_lock); sidconf =snd_soc_component_read (component,AB8500_SIDFIRCONF );if (((sidconf &BIT (AB8500_SIDFIRCONF_FIRSIDBUSY )) !=0 )) {
@@ -1025,7 +1025,8 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol, }else { status = -EBUSY ; } - goto out; +dev_dbg (component->dev,"%s: Exit\n" , __func__); +return status; }snd_soc_component_write (component,AB8500_SIDFIRADR ,0 );
@@ -1043,9 +1044,6 @@ static int sid_status_control_put(struct snd_kcontrol *kcontrol, drvdata->sid_status =SID_FIR_CONFIGURED ; -out: -mutex_unlock (&drvdata->ctrl_lock); -dev_dbg (component->dev,"%s: Exit\n" , __func__);return status;
Signature · 1 line
2.43.0
PATCH v2 2/24 ASoC: codecs: ak4613: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/ak4613.c | 83 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 43 deletions(-)
sound/soc/codecs/ak4613.c +40 -43
@@ -95,6 +95,7 @@* see * AK4613_ENABLE_TDM_TEST */ +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/i2c.h>
@@ -384,7 +385,7 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream,struct ak4613_priv *priv =snd_soc_component_get_drvdata (component);struct device *dev = component->dev; -mutex_lock (&priv->lock); +guard (mutex)(&priv->lock); priv->cnt--;if (priv->cnt <0 ) {dev_err (dev,"unexpected counter error\n" );
@@ -392,7 +393,6 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream, }if (!priv->cnt) priv->ctrl1 =0 ; -mutex_unlock (&priv->lock); } static void ak4613_hw_constraints(struct ak4613_priv *priv,
@@ -507,10 +507,9 @@ static int ak4613_dai_startup(struct snd_pcm_substream *substream,struct snd_soc_component *component = dai->component;struct ak4613_priv *priv =snd_soc_component_get_drvdata (component); -mutex_lock (&priv->lock); +guard (mutex)(&priv->lock);ak4613_hw_constraints (priv, substream); priv->cnt++; -mutex_unlock (&priv->lock);return 0 ; }
@@ -599,45 +598,47 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,*/ ret = -EINVAL ; -mutex_lock (&priv->lock); -if (priv->cnt >1 ) { -/* -* If it was already working, use current priv->ctrl1 -*/ - ret =0 ; - }else { -/* -* It is not yet working, -*/ -unsigned int channel =params_channels (params); -u8 tdm; - -/* STEREO or TDM */ -if (channel ==2 ) - tdm =AK4613_CONFIG_MODE_STEREO ; -else - tdm =AK4613_CONFIG_GET (priv,MODE ); - -for (i =ARRAY_SIZE (ak4613_iface) -1 ; i >=0 ; i--) { -const struct ak4613_interface *iface = ak4613_iface + i; - -if ((iface->fmt == fmt) && (iface->width == width)) { -/* -* Ctrl1 -* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | -* |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE| -* < tdm > < iface->dif > -*/ - priv->ctrl1 = (tdm <<6 ) | (iface->dif <<3 ); - ret =0 ; -break ; + scoped_guard(mutex, &priv->lock) { +if (priv->cnt >1 ) { +/* +* If it was already working, use current priv->ctrl1 +*/ + ret =0 ; + }else { +/* +* It is not yet working, +*/ +unsigned int channel =params_channels (params); +u8 tdm; + +/* STEREO or TDM */ +if (channel ==2 ) + tdm =AK4613_CONFIG_MODE_STEREO ; +else + tdm =AK4613_CONFIG_GET (priv,MODE ); + +for (i =ARRAY_SIZE (ak4613_iface) -1 ; i >=0 ; i--) { +const struct ak4613_interface *iface = ak4613_iface + i; + +if (iface->fmt == fmt && iface->width == width) { +/* +* Ctrl1 +* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | +* |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE| +* < tdm > < iface->dif > +*/ + priv->ctrl1 = (tdm <<6 ) | (iface->dif <<3 ); + ret =0 ; +break ; + } } } } -mutex_unlock (&priv->lock); -if (ret <0 ) - goto hw_params_end; +if (ret <0 ) { +dev_warn (dev,"unsupported data width/format combination\n" ); +return ret; + }snd_soc_component_update_bits (component,CTRL1 ,FMT_MASK , priv->ctrl1);snd_soc_component_update_bits (component,CTRL2 ,DFS_MASK , ctrl2);
@@ -645,10 +646,6 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,snd_soc_component_update_bits (component,ICTRL ,ICTRL_MASK , priv->ic);snd_soc_component_update_bits (component,OCTRL ,OCTRL_MASK , priv->oc); -hw_params_end: -if (ret <0 ) -dev_warn (dev,"unsupported data width/format combination\n" ); -return ret; }
Signature · 1 line
2.43.0
PATCH v2 3/24 ASoC: codecs: arizona-jack: Use guard() cleanup helpers
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() helpers for mutex locking and PM runtime management.
No functional change intended.
---
Changes in v2:
Reworked the code to use an if/else structure, avoiding code duplication after removing the goto label.
sound/soc/codecs/arizona-jack.c | 116 +++++++++++++++----------------- 1 file changed, 53 insertions(+), 63 deletions(-)
sound/soc/codecs/arizona-jack.c +53 -63
@@ -5,6 +5,7 @@* Copyright (C) 2012-2014 Wolfson Microelectronics plc */ +#include <linux/cleanup.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h>
@@ -707,15 +708,13 @@ static void arizona_micd_timeout_work(struct work_struct *work) struct arizona_priv, micd_timeout_work.work); -mutex_lock (&info->lock); +guard (mutex)(&info->lock);dev_dbg (info->arizona->dev,"MICD timed out, reporting HP\n" ); info->detecting = false;arizona_identify_headphone (info); - -mutex_unlock (&info->lock); }static int arizona_micd_adc_read (struct arizona_priv *info)
@@ -921,12 +920,11 @@ static void arizona_micd_detect(struct work_struct *work)cancel_delayed_work_sync (&info->micd_timeout_work); -mutex_lock (&info->lock); +guard (mutex)(&info->lock);/* If the cable was removed while measuring ignore the result */ if (!(info->jack->status &SND_JACK_MECHANICAL )) {dev_dbg (arizona->dev,"Ignoring MICDET for removed cable\n" ); -mutex_unlock (&info->lock);return ; }
@@ -936,7 +934,6 @@ static void arizona_micd_detect(struct work_struct *work)arizona_button_reading (info);pm_runtime_mark_last_busy (arizona->dev); -mutex_unlock (&info->lock); }static irqreturn_t arizona_micdet (int irq,void *data)
@@ -948,10 +945,10 @@ static irqreturn_t arizona_micdet(int irq, void *data)cancel_delayed_work_sync (&info->micd_detect_work);cancel_delayed_work_sync (&info->micd_timeout_work); -mutex_lock (&info->lock); -if (!info->detecting) - debounce =0 ; -mutex_unlock (&info->lock); + scoped_guard(mutex, &info->lock) { +if (!info->detecting) + debounce =0 ; + }if (debounce) queue_delayed_work(system_power_efficient_wq,
@@ -969,9 +966,8 @@ static void arizona_hpdet_work(struct work_struct *work) struct arizona_priv, hpdet_work.work); -mutex_lock (&info->lock); +guard (mutex)(&info->lock);arizona_start_hpdet_acc_id (info); -mutex_unlock (&info->lock); }static int arizona_hpdet_wait (struct arizona_priv *info)
@@ -1018,9 +1014,9 @@ static irqreturn_t arizona_jackdet(int irq, void *data) cancelled_hp =cancel_delayed_work_sync (&info->hpdet_work); cancelled_mic =cancel_delayed_work_sync (&info->micd_timeout_work); -pm_runtime_get_sync (arizona->dev); +guard (pm_runtime_active_auto)(arizona->dev); -mutex_lock (&info->lock); +guard (mutex)(&info->lock);if (info->micd_clamp) { mask =ARIZONA_MICD_CLAMP_STS ;
@@ -1036,8 +1032,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data) ret =regmap_read (arizona->regmap,ARIZONA_AOD_IRQ_RAW_STATUS , &val);if (ret) {dev_err (arizona->dev,"Failed to read jackdet status: %d\n" , ret); -mutex_unlock (&info->lock); -pm_runtime_put_autosuspend (arizona->dev);return IRQ_NONE ; }
@@ -1056,62 +1050,61 @@ static irqreturn_t arizona_jackdet(int irq, void *data) &info->micd_timeout_work, msecs_to_jiffies(micd_timeout)); } + }else { + info->last_jackdet = val; - goto out; - } - info->last_jackdet = val; +if (info->last_jackdet == present) { +dev_dbg (arizona->dev,"Detected jack\n" ); +snd_soc_jack_report (info->jack,SND_JACK_MECHANICAL ,SND_JACK_MECHANICAL ); -if (info->last_jackdet == present) { -dev_dbg (arizona->dev,"Detected jack\n" ); -snd_soc_jack_report (info->jack,SND_JACK_MECHANICAL ,SND_JACK_MECHANICAL ); + info->detecting = true; + info->mic = false; + info->jack_flips =0 ; - info->detecting = true; - info->mic = false; - info->jack_flips =0 ; +if (!arizona->pdata.hpdet_acc_id) { +arizona_start_mic (info); + }else { +queue_delayed_work (system_power_efficient_wq, + &info->hpdet_work, +msecs_to_jiffies (HPDET_DEBOUNCE )); + } -if (!arizona->pdata.hpdet_acc_id) { -arizona_start_mic (info); +if (info->micd_clamp || !arizona->pdata.jd_invert) +regmap_update_bits (arizona->regmap, +ARIZONA_JACK_DETECT_DEBOUNCE , +ARIZONA_MICD_CLAMP_DB | +ARIZONA_JD1_DB ,0 ); }else { -queue_delayed_work (system_power_efficient_wq, - &info->hpdet_work, -msecs_to_jiffies (HPDET_DEBOUNCE )); - } +dev_dbg (arizona->dev,"Detected jack removal\n" ); -if (info->micd_clamp || !arizona->pdata.jd_invert) -regmap_update_bits (arizona->regmap, -ARIZONA_JACK_DETECT_DEBOUNCE , -ARIZONA_MICD_CLAMP_DB | -ARIZONA_JD1_DB ,0 ); - }else { -dev_dbg (arizona->dev,"Detected jack removal\n" ); +arizona_stop_mic (info); -arizona_stop_mic (info); + info->num_hpdet_res =0 ; +for (i =0 ; i <ARRAY_SIZE (info->hpdet_res); i++) + info->hpdet_res[i] =0 ; + info->mic = false; + info->hpdet_done = false; + info->hpdet_retried = false; - info->num_hpdet_res =0 ; -for (i =0 ; i <ARRAY_SIZE (info->hpdet_res); i++) - info->hpdet_res[i] =0 ; - info->mic = false; - info->hpdet_done = false; - info->hpdet_retried = false; +snd_soc_jack_report (info->jack,0 , +ARIZONA_JACK_MASK | info->micd_button_mask); -snd_soc_jack_report (info->jack,0 ,ARIZONA_JACK_MASK | info->micd_button_mask); +/* +* If the jack was removed during a headphone detection we +* need to wait for the headphone detection to finish, as +* it can not be aborted. We don't want to be able to start +* a new headphone detection from a fresh insert until this +* one is finished. +*/ +arizona_hpdet_wait (info); -/* -* If the jack was removed during a headphone detection we -* need to wait for the headphone detection to finish, as -* it can not be aborted. We don't want to be able to start -* a new headphone detection from a fresh insert until this -* one is finished. -*/ -arizona_hpdet_wait (info); - -regmap_update_bits (arizona->regmap, -ARIZONA_JACK_DETECT_DEBOUNCE , -ARIZONA_MICD_CLAMP_DB |ARIZONA_JD1_DB , -ARIZONA_MICD_CLAMP_DB |ARIZONA_JD1_DB ); +regmap_update_bits (arizona->regmap, +ARIZONA_JACK_DETECT_DEBOUNCE , +ARIZONA_MICD_CLAMP_DB |ARIZONA_JD1_DB , +ARIZONA_MICD_CLAMP_DB |ARIZONA_JD1_DB ); + } } -out:/* Clear trig_sts to make sure DCVDD is not forced up */ regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG, ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
@@ -1119,9 +1112,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data)ARIZONA_JD1_FALL_TRIG_STS | ARIZONA_JD1_RISE_TRIG_STS); -mutex_unlock (&info->lock); - -pm_runtime_put_autosuspend (arizona->dev);return IRQ_HANDLED ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers
Quoted 9 lines · On Fri, Jul 03, 2026 at 12:53:34PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
Clean up the code using
guard()helpers for mutex locking and PM runtime management.
No functional change intended.Signed-off-by bui duc phuc <[email protected]>---
sound/soc/codecs/arizona-jack.c static irqreturn_t arizona_jackdet(int irq, void *data) · line 1116
Quoted 8 lines
sound/soc/codecs/arizona-jack.c +0
-3@@ -1119,9 +1112,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data)ARIZONA_JD1_FALL_TRIG_STS | ARIZONA_JD1_RISE_TRIG_STS); -mutex_unlock (&info->lock); - -pm_runtime_put_autosuspend (arizona->dev);return IRQ_HANDLED ;
Minor nit, this leaves a double blank line here.
Otherwise looks good to me:
Thanks,
Charles
Re: [PATCH v2 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers
Hi Charles,
Thank you for your review !
Quoted 5 lines
Minor nit, this leaves a double blank line here.
Otherwise looks good to me:
Reviewed-by Charles Keepax <[email protected]>
I will fix that minor issue and add your Reviewed-by tag in v3.
Best regards,
Phuc
PATCH v2 4/24 ASoC: codecs: arizona: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/arizona.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
sound/soc/codecs/arizona.c +11 -15
@@ -7,6 +7,7 @@* Author: Mark Brown <[email protected]> */ +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/gcd.h> #include <linux/module.h>
@@ -1158,17 +1159,16 @@ int arizona_dvfs_up(struct snd_soc_component *component, unsigned int flags)struct arizona_priv *priv =snd_soc_component_get_drvdata (component);int ret =0 ; -mutex_lock (&priv->dvfs_lock); +guard (mutex)(&priv->dvfs_lock);if (!priv->dvfs_cached && !priv->dvfs_reqs) { ret =arizona_dvfs_enable (component);if (ret) - goto err; +return ret; } priv->dvfs_reqs |= flags; -err: -mutex_unlock (&priv->dvfs_lock); +return ret; }EXPORT_SYMBOL_GPL (arizona_dvfs_up);
@@ -1179,7 +1179,7 @@ int arizona_dvfs_down(struct snd_soc_component *component, unsigned int flags)unsigned int old_reqs;int ret =0 ; -mutex_lock (&priv->dvfs_lock); +guard (mutex)(&priv->dvfs_lock); old_reqs = priv->dvfs_reqs; priv->dvfs_reqs &= ~flags;
@@ -1187,7 +1187,6 @@ int arizona_dvfs_down(struct snd_soc_component *component, unsigned int flags)if (!priv->dvfs_cached && old_reqs && !priv->dvfs_reqs) ret =arizona_dvfs_disable (component); -mutex_unlock (&priv->dvfs_lock);return ret; }EXPORT_SYMBOL_GPL (arizona_dvfs_down);
@@ -1199,7 +1198,7 @@ int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,struct arizona_priv *priv =snd_soc_component_get_drvdata (component);int ret =0 ; -mutex_lock (&priv->dvfs_lock); +guard (mutex)(&priv->dvfs_lock);switch (event) {case SND_SOC_DAPM_POST_PMU :
@@ -1222,7 +1221,6 @@ int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,break ; } -mutex_unlock (&priv->dvfs_lock);return ret; }EXPORT_SYMBOL_GPL (arizona_dvfs_sysclk_ev);
@@ -1657,13 +1655,11 @@ static void arizona_wm5102_set_dac_comp(struct snd_soc_component *component, { 0x80, 0x0 }, }; -mutex_lock (&arizona->dac_comp_lock); - - dac_comp[1 ].def = arizona->dac_comp_coeff; -if (rate >=176400 ) - dac_comp[2 ].def = arizona->dac_comp_enabled; - -mutex_unlock (&arizona->dac_comp_lock); + scoped_guard(mutex, &arizona->dac_comp_lock) { + dac_comp[1 ].def = arizona->dac_comp_coeff; +if (rate >=176400 ) + dac_comp[2 ].def = arizona->dac_comp_enabled; + } regmap_multi_reg_write(arizona->regmap, dac_comp,
Signature · 1 line
2.43.0
PATCH v2 5/24 ASoC: codecs: aw87390: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw87390.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/soc/codecs/aw87390.c +3 -7
@@ -7,6 +7,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/i2c.h> #include <linux/firmware.h> #include <linux/regmap.h>
@@ -225,11 +226,10 @@ static int aw87390_profile_set(struct snd_kcontrol *kcontrol,struct aw87390 *aw87390 =snd_soc_component_get_drvdata (codec);int ret; -mutex_lock (&aw87390->lock); +guard (mutex)(&aw87390->lock); ret =aw87390_dev_set_profile_index (aw87390->aw_pa, ucontrol->value.integer.value[0 ]);if (ret) {dev_dbg (codec->dev,"profile index does not change\n" ); -mutex_unlock (&aw87390->lock);return 0 ; }
@@ -238,8 +238,6 @@ static int aw87390_profile_set(struct snd_kcontrol *kcontrol,aw87390_power_on (aw87390->aw_pa); } -mutex_unlock (&aw87390->lock); -return 1 ; }
@@ -280,14 +278,12 @@ static int aw87390_request_firmware_file(struct aw87390 *aw87390)return ret; } -mutex_lock (&aw87390->lock); +guard (mutex)(&aw87390->lock); ret =aw88395_dev_cfg_load (aw87390->aw_pa, aw87390->aw_cfg);if (ret)dev_err (aw87390->aw_pa->dev,"aw_dev acf parse failed\n" ); -mutex_unlock (&aw87390->lock); -return ret; }
Signature · 1 line
2.43.0
PATCH v2 6/24 ASoC: codecs: aw88081: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw88081.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
sound/soc/codecs/aw88081.c +6 -12
@@ -7,6 +7,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/firmware.h> #include <linux/i2c.h> #include <linux/regmap.h>
@@ -763,9 +764,8 @@ static void aw88081_startup_work(struct work_struct *work)struct aw88081 *aw88081 = container_of(work, struct aw88081, start_work.work); -mutex_lock (&aw88081->lock); +guard (mutex)(&aw88081->lock);aw88081_start_pa (aw88081); -mutex_unlock (&aw88081->lock); }static void aw88081_start (struct aw88081 *aw88081,bool sync_start)
@@ -942,11 +942,10 @@ static int aw88081_profile_set(struct snd_kcontrol *kcontrol,int ret;/* pa stop or stopping just set profile */ -mutex_lock (&aw88081->lock); +guard (mutex)(&aw88081->lock); ret =aw88081_dev_set_profile_index (aw88081->aw_pa, ucontrol->value.integer.value[0 ]);if (ret) {dev_dbg (codec->dev,"profile index does not change" ); -mutex_unlock (&aw88081->lock);return 0 ; }
@@ -955,8 +954,6 @@ static int aw88081_profile_set(struct snd_kcontrol *kcontrol,aw88081_start (aw88081,AW88081_SYNC_START ); } -mutex_unlock (&aw88081->lock); -return 1 ; }
@@ -1165,11 +1162,9 @@ static int aw88081_request_firmware_file(struct aw88081 *aw88081)if (ret)return ret; -mutex_lock (&aw88081->lock); - ret =aw88081_dev_init (aw88081, aw88081->aw_cfg); -mutex_unlock (&aw88081->lock); +guard (mutex)(&aw88081->lock); -return ret; +return aw88081_dev_init (aw88081, aw88081->aw_cfg); } static int aw88081_playback_event(struct snd_soc_dapm_widget *w,
@@ -1178,7 +1173,7 @@ static int aw88081_playback_event(struct snd_soc_dapm_widget *w,struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm);struct aw88081 *aw88081 =snd_soc_component_get_drvdata (component); -mutex_lock (&aw88081->lock); +guard (mutex)(&aw88081->lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :aw88081_start (aw88081,AW88081_ASYNC_START );
@@ -1189,7 +1184,6 @@ static int aw88081_playback_event(struct snd_soc_dapm_widget *w,default :break ; } -mutex_unlock (&aw88081->lock);return 0 ; }
Signature · 1 line
2.43.0
PATCH v2 7/24 ASoC: codecs: aw88166: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw88166.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
sound/soc/codecs/aw88166.c +10 -14
@@ -7,6 +7,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/crc32.h> #include <linux/firmware.h> #include <linux/gpio/consumer.h>
@@ -1173,9 +1174,8 @@ static void aw88166_startup_work(struct work_struct *work)struct aw88166 *aw88166 = container_of(work, struct aw88166, start_work.work); -mutex_lock (&aw88166->lock); +guard (mutex)(&aw88166->lock);aw88166_start_pa (aw88166); -mutex_unlock (&aw88166->lock); }static void aw88166_start (struct aw88166 *aw88166,bool sync_start)
@@ -1413,11 +1413,10 @@ static int aw88166_profile_set(struct snd_kcontrol *kcontrol,struct aw88166 *aw88166 =snd_soc_component_get_drvdata (codec);int ret; -mutex_lock (&aw88166->lock); +guard (mutex)(&aw88166->lock); ret =aw88166_dev_set_profile_index (aw88166->aw_pa, ucontrol->value.integer.value[0 ]);if (ret) {dev_dbg (codec->dev,"profile index does not change" ); -mutex_unlock (&aw88166->lock);return 0 ; }
@@ -1426,8 +1425,6 @@ static int aw88166_profile_set(struct snd_kcontrol *kcontrol,aw88166_start (aw88166,AW88166_SYNC_START ); } -mutex_unlock (&aw88166->lock); -return 1 ; }
@@ -1607,12 +1604,12 @@ static int aw88166_request_firmware_file(struct aw88166 *aw88166)return ret; } -mutex_lock (&aw88166->lock); -/* aw device init */ - ret =aw88166_dev_init (aw88166, aw88166->aw_cfg); -if (ret) -dev_err (aw88166->aw_pa->dev,"dev init failed\n" ); -mutex_unlock (&aw88166->lock); + scoped_guard(mutex, &aw88166->lock) { +/* aw device init */ + ret =aw88166_dev_init (aw88166, aw88166->aw_cfg); +if (ret) +dev_err (aw88166->aw_pa->dev,"dev init failed\n" ); + }return ret; }
@@ -1639,7 +1636,7 @@ static int aw88166_playback_event(struct snd_soc_dapm_widget *w,struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm);struct aw88166 *aw88166 =snd_soc_component_get_drvdata (component); -mutex_lock (&aw88166->lock); +guard (mutex)(&aw88166->lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :aw88166_start (aw88166,AW88166_ASYNC_START );
@@ -1650,7 +1647,6 @@ static int aw88166_playback_event(struct snd_soc_dapm_widget *w,default :break ; } -mutex_unlock (&aw88166->lock);return 0 ; }
Signature · 1 line
2.43.0
PATCH v2 8/24 ASoC: codecs: aw88261: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw88261.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
sound/soc/codecs/aw88261.c +9 -12
@@ -8,6 +8,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/i2c.h> #include <linux/firmware.h> #include <linux/bitops.h>
@@ -960,11 +961,10 @@ static int aw88261_profile_set(struct snd_kcontrol *kcontrol,int ret;/* pa stop or stopping just set profile */ -mutex_lock (&aw88261->lock); +guard (mutex)(&aw88261->lock); ret =aw88261_dev_set_profile_index (aw88261->aw_pa, ucontrol->value.integer.value[0 ]);if (ret) {dev_dbg (codec->dev,"profile index does not change" ); -mutex_unlock (&aw88261->lock);return 0 ; }
@@ -973,8 +973,6 @@ static int aw88261_profile_set(struct snd_kcontrol *kcontrol,aw88261_start (aw88261); } -mutex_unlock (&aw88261->lock); -return 1 ; }
@@ -1038,7 +1036,7 @@ static int aw88261_playback_event(struct snd_soc_dapm_widget *w,struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm);struct aw88261 *aw88261 =snd_soc_component_get_drvdata (component); -mutex_lock (&aw88261->lock); +guard (mutex)(&aw88261->lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :aw88261_start (aw88261);
@@ -1049,7 +1047,6 @@ static int aw88261_playback_event(struct snd_soc_dapm_widget *w,default :break ; } -mutex_unlock (&aw88261->lock);return 0 ; }
@@ -1188,12 +1185,12 @@ static int aw88261_request_firmware_file(struct aw88261 *aw88261)return ret; } -mutex_lock (&aw88261->lock); -/* aw device init */ - ret =aw88261_dev_init (aw88261, aw88261->aw_cfg); -if (ret) -dev_err (aw88261->aw_pa->dev,"dev init failed" ); -mutex_unlock (&aw88261->lock); + scoped_guard(mutex, &aw88261->lock) { +/* aw device init */ + ret =aw88261_dev_init (aw88261, aw88261->aw_cfg); +if (ret) +dev_err (aw88261->aw_pa->dev,"dev init failed" ); + }return ret; }
Signature · 1 line
2.43.0
PATCH v2 9/24 ASoC: codecs: aw88395: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw88395/aw88395.c | 24 ++++++-------- sound/soc/codecs/aw88395/aw88395_device.c | 40 ++++++++--------------- 2 files changed, 24 insertions(+), 40 deletions(-)
sound/soc/codecs/aw88395/aw88395.c +10 -14
@@ -8,6 +8,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/firmware.h>
@@ -51,9 +52,8 @@ static void aw88395_startup_work(struct work_struct *work)struct aw88395 *aw88395 = container_of(work, struct aw88395, start_work.work); -mutex_lock (&aw88395->lock); +guard (mutex)(&aw88395->lock);aw88395_start_pa (aw88395); -mutex_unlock (&aw88395->lock); }static void aw88395_start (struct aw88395 *aw88395,bool sync_start)
@@ -224,11 +224,10 @@ static int aw88395_profile_set(struct snd_kcontrol *kcontrol,int ret;/* pa stop or stopping just set profile */ -mutex_lock (&aw88395->lock); +guard (mutex)(&aw88395->lock); ret =aw88395_dev_set_profile_index (aw88395->aw_pa, ucontrol->value.integer.value[0 ]);if (ret <0 ) {dev_dbg (codec->dev,"profile index does not change" ); -mutex_unlock (&aw88395->lock);return 0 ; }
@@ -237,8 +236,6 @@ static int aw88395_profile_set(struct snd_kcontrol *kcontrol,aw88395_start (aw88395,AW88395_SYNC_START ); } -mutex_unlock (&aw88395->lock); -return 1 ; }
@@ -366,7 +363,7 @@ static int aw88395_playback_event(struct snd_soc_dapm_widget *w,struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm);struct aw88395 *aw88395 =snd_soc_component_get_drvdata (component); -mutex_lock (&aw88395->lock); +guard (mutex)(&aw88395->lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :aw88395_start (aw88395,AW88395_ASYNC_START );
@@ -377,7 +374,6 @@ static int aw88395_playback_event(struct snd_soc_dapm_widget *w,default :break ; } -mutex_unlock (&aw88395->lock);return 0 ; }
@@ -495,12 +491,12 @@ static int aw88395_request_firmware_file(struct aw88395 *aw88395)dev_dbg (aw88395->aw_pa->dev,"%s : bin load success\n" , __func__); -mutex_lock (&aw88395->lock); -/* aw device init */ - ret =aw88395_dev_init (aw88395->aw_pa, aw88395->aw_cfg); -if (ret <0 ) -dev_err (aw88395->aw_pa->dev,"dev init failed" ); -mutex_unlock (&aw88395->lock); + scoped_guard(mutex, &aw88395->lock) { +/* aw device init */ + ret =aw88395_dev_init (aw88395->aw_pa, aw88395->aw_cfg); +if (ret <0 ) +dev_err (aw88395->aw_pa->dev,"dev init failed" ); + }return ret; }
sound/soc/codecs/aw88395/aw88395_device.c +14 -26
@@ -8,6 +8,7 @@// Author: Ben Yi <[email protected]> // +#include <linux/cleanup.h> #include <linux/crc32.h> #include <linux/i2c.h> #include <linux/minmax.h>
@@ -70,7 +71,7 @@ int aw_dev_dsp_write(struct aw_device *aw_dev,u32 reg_value;int ret; -mutex_lock (&aw_dev->dsp_lock); +guard (mutex)(&aw_dev->dsp_lock);switch (data_type) {case AW_DSP_16_DATA : ret =aw_dev_dsp_write_16bit (aw_dev, dsp_addr, dsp_data);
@@ -93,7 +94,6 @@ int aw_dev_dsp_write(struct aw_device *aw_dev,/* clear dsp chip select state*/ if (regmap_read (aw_dev->regmap,AW88395_ID_REG , ®_value))dev_err (aw_dev->dev,"%s fail to clear chip state. Err=%d\n" , __func__, ret); -mutex_unlock (&aw_dev->dsp_lock);return ret; }
@@ -156,7 +156,7 @@ int aw_dev_dsp_read(struct aw_device *aw_dev,u32 reg_value;int ret; -mutex_lock (&aw_dev->dsp_lock); +guard (mutex)(&aw_dev->dsp_lock);switch (data_type) {case AW_DSP_16_DATA : ret =aw_dev_dsp_read_16bit (aw_dev, dsp_addr, dsp_data);
@@ -179,7 +179,6 @@ int aw_dev_dsp_read(struct aw_device *aw_dev,/* clear dsp chip select state*/ if (regmap_read (aw_dev->regmap,AW88395_ID_REG , ®_value))dev_err (aw_dev->dev,"%s fail to clear chip state. Err=%d\n" , __func__, ret); -mutex_unlock (&aw_dev->dsp_lock);return ret; }
@@ -1110,42 +1109,36 @@ static int aw_dev_dsp_update_container(struct aw_device *aw_dev,#ifdef AW88395_DSP_I2C_WRITES u32 tmp_len; -mutex_lock (&aw_dev->dsp_lock); +guard (mutex)(&aw_dev->dsp_lock); ret =regmap_write (aw_dev->regmap,AW88395_DSPMADD_REG , base);if (ret) - goto error_operation; +return ret;for (i =0 ; i < len; i +=AW88395_MAX_RAM_WRITE_BYTE_SIZE ) { tmp_len =min (len - i,AW88395_MAX_RAM_WRITE_BYTE_SIZE ); ret =regmap_raw_write (aw_dev->regmap,AW88395_DSPMDAT_REG , &data[i], tmp_len);if (ret) - goto error_operation; +return ret; } -mutex_unlock (&aw_dev->dsp_lock);#else __be16 reg_val; -mutex_lock (&aw_dev->dsp_lock); +guard (mutex)(&aw_dev->dsp_lock);/* i2c write */ ret =regmap_write (aw_dev->regmap,AW88395_DSPMADD_REG , base);if (ret) - goto error_operation; +return ret;for (i =0 ; i < len; i +=2 ) { reg_val =cpu_to_be16p ((u16 *)(data + i)); ret =regmap_write (aw_dev->regmap,AW88395_DSPMDAT_REG , (u16 )reg_val);if (ret) - goto error_operation; +return ret; } -mutex_unlock (&aw_dev->dsp_lock);#endif return 0 ; - -error_operation: -mutex_unlock (&aw_dev->dsp_lock); -return ret; } static int aw_dev_dsp_update_fw(struct aw_device *aw_dev,
@@ -1231,14 +1224,14 @@ static int aw_dev_check_sram(struct aw_device *aw_dev) {unsigned int reg_val; -mutex_lock (&aw_dev->dsp_lock); +guard (mutex)(&aw_dev->dsp_lock);/* check the odd bits of reg 0x40 */ regmap_write (aw_dev->regmap,AW88395_DSPMADD_REG ,AW88395_DSP_ODD_NUM_BIT_TEST );regmap_read (aw_dev->regmap,AW88395_DSPMADD_REG , ®_val);if (reg_val !=AW88395_DSP_ODD_NUM_BIT_TEST ) {dev_err (aw_dev->dev,"check reg 0x40 odd bit failed, read[0x%x] != write[0x%x]" , reg_val,AW88395_DSP_ODD_NUM_BIT_TEST ); - goto error; +return -EPERM ; }/* check the even bits of reg 0x40 */
@@ -1247,7 +1240,7 @@ static int aw_dev_check_sram(struct aw_device *aw_dev)if (reg_val !=AW88395_DSP_EVEN_NUM_BIT_TEST ) {dev_err (aw_dev->dev,"check reg 0x40 even bit failed, read[0x%x] != write[0x%x]" , reg_val,AW88395_DSP_EVEN_NUM_BIT_TEST ); - goto error; +return -EPERM ; }/* check dsp_fw_base_addr */
@@ -1256,7 +1249,7 @@ static int aw_dev_check_sram(struct aw_device *aw_dev)if (reg_val !=AW88395_DSP_EVEN_NUM_BIT_TEST ) {dev_err (aw_dev->dev,"check dsp fw addr failed, read[0x%x] != write[0x%x]" , reg_val,AW88395_DSP_EVEN_NUM_BIT_TEST ); - goto error; +return -EPERM ; }/* check dsp_cfg_base_addr */
@@ -1265,15 +1258,10 @@ static int aw_dev_check_sram(struct aw_device *aw_dev)if (reg_val !=AW88395_DSP_ODD_NUM_BIT_TEST ) {dev_err (aw_dev->dev,"check dsp cfg failed, read[0x%x] != write[0x%x]" , reg_val,AW88395_DSP_ODD_NUM_BIT_TEST ); - goto error; +return -EPERM ; } -mutex_unlock (&aw_dev->dsp_lock);return 0 ; - -error: -mutex_unlock (&aw_dev->dsp_lock); -return -EPERM ; }int aw88395_dev_fw_update (struct aw_device *aw_dev,bool up_dsp_fw_en,bool force_up_en)
Signature · 1 line
2.43.0
PATCH v2 10/24 ASoC: codecs: aw88399: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/aw88399.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
sound/soc/codecs/aw88399.c +5 -10
@@ -7,6 +7,7 @@// Author: Weidong Wang <[email protected]> // +#include <linux/cleanup.h> #include <linux/crc32.h> #include <linux/gpio/consumer.h> #include <linux/i2c.h>
@@ -1140,9 +1141,8 @@ static void aw88399_startup_work(struct work_struct *work)struct aw88399 *aw88399 = container_of(work, struct aw88399, start_work.work); -mutex_lock (&aw88399->lock); +guard (mutex)(&aw88399->lock);aw88399_start_pa (aw88399); -mutex_unlock (&aw88399->lock); }static void aw88399_start (struct aw88399 *aw88399,bool sync_start)
@@ -1702,11 +1702,10 @@ static int aw88399_profile_set(struct snd_kcontrol *kcontrol,struct aw88399 *aw88399 =snd_soc_component_get_drvdata (codec);int ret; -mutex_lock (&aw88399->lock); +guard (mutex)(&aw88399->lock); ret =aw88399_dev_set_profile_index (aw88399->aw_pa, ucontrol->value.integer.value[0 ]);if (ret) {dev_dbg (codec->dev,"profile index does not change" ); -mutex_unlock (&aw88399->lock);return 0 ; }
@@ -1715,8 +1714,6 @@ static int aw88399_profile_set(struct snd_kcontrol *kcontrol,aw88399_start (aw88399,AW88399_SYNC_START ); } -mutex_unlock (&aw88399->lock); -return 1 ; }
@@ -1939,12 +1936,11 @@ static int aw88399_request_firmware_file(struct aw88399 *aw88399)return ret; } -mutex_lock (&aw88399->lock); +guard (mutex)(&aw88399->lock);/* aw device init */ ret =aw88399_dev_init (aw88399, aw88399->aw_cfg);if (ret)dev_err (aw88399->aw_pa->dev,"dev init failed" ); -mutex_unlock (&aw88399->lock);return ret; }
@@ -1975,7 +1971,7 @@ static int aw88399_playback_event(struct snd_soc_dapm_widget *w,struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm);struct aw88399 *aw88399 =snd_soc_component_get_drvdata (component); -mutex_lock (&aw88399->lock); +guard (mutex)(&aw88399->lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :aw88399_start (aw88399,AW88399_ASYNC_START );
@@ -1986,7 +1982,6 @@ static int aw88399_playback_event(struct snd_soc_dapm_widget *w,default :break ; } -mutex_unlock (&aw88399->lock);return 0 ; }
Signature · 1 line
2.43.0
PATCH v2 11/24 ASoC: codecs: cros_ec_codec: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cros_ec_codec.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
sound/soc/codecs/cros_ec_codec.c +8 -10
@@ -12,6 +12,7 @@#include <linux/acpi.h> #include <linux/delay.h> #include <linux/device.h> +#include <linux/cleanup.h> #include <linux/io.h> #include <linux/jiffies.h> #include <linux/kernel.h>
@@ -608,10 +609,10 @@ static void wov_copy_work(struct work_struct *w) container_of(w, struct cros_ec_codec_priv, wov_copy_work.work);int ret; -mutex_lock (&priv->wov_dma_lock); +guard (mutex)(&priv->wov_dma_lock);if (!priv->wov_substream) {dev_warn (priv->dev,"no pcm substream\n" ); - goto leave; +return ; }if (ec_codec_capable (priv,EC_CODEC_CAP_WOV_AUDIO_SHM ))
@@ -624,8 +625,6 @@ static void wov_copy_work(struct work_struct *w) msecs_to_jiffies(10)); else if (ret) dev_err(priv->dev, "failed to read audio data\n"); -leave: -mutex_unlock (&priv->wov_dma_lock); } static int wov_enable_get(struct snd_kcontrol *kcontrol,
@@ -895,12 +894,11 @@ static int wov_pcm_hw_params(struct snd_soc_component *component,struct cros_ec_codec_priv *priv =snd_soc_component_get_drvdata (component); -mutex_lock (&priv->wov_dma_lock); +guard (mutex)(&priv->wov_dma_lock); priv->wov_substream = substream; priv->wov_rp = priv->wov_wp =0 ; priv->wov_dma_offset =0 ; priv->wov_burst_read = true; -mutex_unlock (&priv->wov_dma_lock);return 0 ; }
@@ -911,10 +909,10 @@ static int wov_pcm_hw_free(struct snd_soc_component *component,struct cros_ec_codec_priv *priv =snd_soc_component_get_drvdata (component); -mutex_lock (&priv->wov_dma_lock); -wov_queue_dequeue (priv,wov_queue_size (priv)); - priv->wov_substream =NULL ; -mutex_unlock (&priv->wov_dma_lock); + scoped_guard(mutex, &priv->wov_dma_lock) { +wov_queue_dequeue (priv,wov_queue_size (priv)); + priv->wov_substream =NULL ; + }cancel_delayed_work_sync (&priv->wov_copy_work);
Signature · 1 line
2.43.0
PATCH v2 12/24 ASoC: codecs: cs-amp-lib: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs-amp-lib.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
sound/soc/codecs/cs-amp-lib.c +7 -4
@@ -7,6 +7,7 @@#include <asm/byteorder.h> #include <kunit/static_stub.h> +#include <linux/cleanup.h> #include <linux/debugfs.h> #include <linux/dev_printk.h> #include <linux/efi.h>
@@ -83,10 +84,12 @@ static int cs_amp_write_cal_coeff(struct cs_dsp *dsp,KUNIT_STATIC_STUB_REDIRECT (cs_amp_write_cal_coeff, dsp, controls, ctl_name, val);if (IS_REACHABLE (CONFIG_FW_CS_DSP )) { -mutex_lock (&dsp->pwr_lock); - cs_ctl =cs_dsp_get_ctl (dsp, ctl_name, controls->mem_region, controls->alg_id); - ret =cs_dsp_coeff_write_ctrl (cs_ctl,0 , &beval,sizeof (beval)); -mutex_unlock (&dsp->pwr_lock); + scoped_guard(mutex, &dsp->pwr_lock) { + cs_ctl =cs_dsp_get_ctl (dsp, ctl_name, + controls->mem_region, + controls->alg_id); + ret =cs_dsp_coeff_write_ctrl (cs_ctl,0 , &beval,sizeof (beval)); + }if (ret <0 ) {dev_err (dsp->dev,"Failed to write to '%s': %d\n" , ctl_name, ret);
Signature · 1 line
2.43.0
PATCH v2 13/24 ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
In reply to [email protected]From: bui duc phuc <[email protected]>
Convert the interrupt handler to use guard(mutex) for automatic mutex unlocking and PM_RUNTIME_ACQUIRE_IF_ENABLED() to manage the runtime PM reference through scope-based cleanup.
This removes the explicit cleanup paths while preserving the existing behavior.
--- sound/soc/codecs/cs35l56-shared.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
sound/soc/codecs/cs35l56-shared.c +7 -12
@@ -645,18 +645,19 @@ irqreturn_t cs35l56_irq(int irq, void *data)if (!cs35l56_base->init_done)return IRQ_NONE ; -mutex_lock (&cs35l56_base->irq_lock); +guard (mutex)(&cs35l56_base->irq_lock); - rv =pm_runtime_resume_and_get (cs35l56_base->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED (cs35l56_base->dev, pm); + rv =PM_RUNTIME_ACQUIRE_ERR (&pm);if (rv <0 ) {dev_err (cs35l56_base->dev,"irq: failed to get pm_runtime: %d\n" , rv); - goto err_unlock; +return ret; }regmap_read (cs35l56_base->regmap,CS35L56_IRQ1_STATUS , &val);if ((val &CS35L56_IRQ1_STS_MASK ) ==0 ) {dev_dbg (cs35l56_base->dev,"Spurious IRQ: no pending interrupt\n" ); - goto err; +return ret; }/* Ack interrupts */
@@ -680,7 +681,7 @@ irqreturn_t cs35l56_irq(int irq, void *data)/* Check to see if unmasked bits are active */ if (!status1 && !status8 && !status20) - goto err; +return ret;if (status1 &CS35L56_AMP_SHORT_ERR_EINT1_MASK )dev_crit (cs35l56_base->dev,"Amp short error\n" );
@@ -688,14 +689,8 @@ irqreturn_t cs35l56_irq(int irq, void *data)if (status8 &CS35L56_TEMP_ERR_EINT1_MASK )dev_crit (cs35l56_base->dev,"Overtemp error\n" ); - ret =IRQ_HANDLED ; +return IRQ_HANDLED ; -err: -pm_runtime_put (cs35l56_base->dev); -err_unlock: -mutex_unlock (&cs35l56_base->irq_lock); - -return ret; }EXPORT_SYMBOL_NS_GPL (cs35l56_irq,"SND_SOC_CS35L56_SHARED" );
Signature · 1 line
2.43.0
Richard Fitzgerald
maintainerRe: [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
Quoted 22 lines · On 03/07/2026 6:53 am, [email protected] wrote:
From: bui duc phuc <[email protected]>
Convert the interrupt handler to use guard(mutex) for automatic mutex unlocking and
PM_RUNTIME_ACQUIRE_IF_ENABLED()to manage the runtime PM reference through scope-based cleanup.
This removes the explicit cleanup paths while preserving the existing behavior.Signed-off-by bui duc phuc <[email protected]>--- sound/soc/codecs/cs35l56-shared.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)sound/soc/codecs/cs35l56-shared.c +0
-1@@ -645,18 +645,19 @@ irqreturn_t cs35l56_irq(int irq, void *data)if (!cs35l56_base->init_done)return IRQ_NONE ; -mutex_lock (&cs35l56_base->irq_lock);
sound/soc/codecs/cs35l56-shared.c irqreturn_t cs35l56_irq(int irq, void *data) · line 655
Quoted 10 lines
sound/soc/codecs/cs35l56-shared.c +4
-2+guard (mutex)(&cs35l56_base->irq_lock); - rv =pm_runtime_resume_and_get (cs35l56_base->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED (cs35l56_base->dev, pm); + rv =PM_RUNTIME_ACQUIRE_ERR (&pm);if (rv <0 ) {dev_err (cs35l56_base->dev,"irq: failed to get pm_runtime: %d\n" , rv); - goto err_unlock; +return ret; }
Should change all the error returns to directly return IRQ_NONE. It looks like a bug that it checks rv but returns ret.
The reason for ret was so the error and success cases could use common exit code to call pm_runtime_put() and mutex_unlock().
But this isn't needed now.
The local ret variable can be deleted.
Quoted 34 lines
sound/soc/codecs/cs35l56-shared.c +3
-9regmap_read (cs35l56_base->regmap,CS35L56_IRQ1_STATUS , &val);if ((val &CS35L56_IRQ1_STS_MASK ) ==0 ) {dev_dbg (cs35l56_base->dev,"Spurious IRQ: no pending interrupt\n" ); - goto err; +return ret; }/* Ack interrupts */ @@ -680,7 +681,7 @@ irqreturn_t cs35l56_irq(int irq, void *data)/* Check to see if unmasked bits are active */ if (!status1 && !status8 && !status20) - goto err; +return ret;if (status1 &CS35L56_AMP_SHORT_ERR_EINT1_MASK )dev_crit (cs35l56_base->dev,"Amp short error\n" );@@ -688,14 +689,8 @@ irqreturn_t cs35l56_irq(int irq, void *data)if (status8 &CS35L56_TEMP_ERR_EINT1_MASK )dev_crit (cs35l56_base->dev,"Overtemp error\n" ); - ret =IRQ_HANDLED ; +return IRQ_HANDLED ; -err: -pm_runtime_put (cs35l56_base->dev); -err_unlock: -mutex_unlock (&cs35l56_base->irq_lock); - -return ret; }EXPORT_SYMBOL_NS_GPL (cs35l56_irq,"SND_SOC_CS35L56_SHARED" );
Re: [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
In reply to [email protected]On 7/3/2026 7:53 AM, [email protected] wrote:
...
Quoted 4 lines
sound/soc/codecs/cs35l56-shared.c +0
-0@@ -688,14 +689,8 @@ irqreturn_t cs35l56_irq(int irq, void *data)if (status8 &CS35L56_TEMP_ERR_EINT1_MASK )dev_crit (cs35l56_base->dev,"Overtemp error\n" );
sound/soc/codecs/cs35l56-shared.c irqreturn_t cs35l56_irq(int irq, void *data) · line 694
Quoted 10 lines
sound/soc/codecs/cs35l56-shared.c +1
-7- ret =IRQ_HANDLED ; +return IRQ_HANDLED ; -err: -pm_runtime_put (cs35l56_base->dev); -err_unlock: -mutex_unlock (&cs35l56_base->irq_lock); - -return ret; }
Nitpick: this will leave a superfluous newline.
Re: [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
Hi Cezary, Richard,
Thanks to both of you for the reviews!
Quoted 11 lines
sound/soc/codecs/cs35l56-shared.c irqreturn_t cs35l56_irq(int irq, void *data) · line 694
Quoted 10 lines
sound/soc/codecs/cs35l56-shared.c +1
-7- ret =IRQ_HANDLED ; +return IRQ_HANDLED ; -err: -pm_runtime_put (cs35l56_base->dev); -err_unlock: -mutex_unlock (&cs35l56_base->irq_lock); - -return ret; }Nitpick: this will leave a superfluous newline.
You're right. I'll remove the extra blank line.
Quoted 1 line
It looks like a bug that it checks rv but returns ret.
I'm not sure I fully understand what you meant by that comment. This conversion preserves the existing behavior, so although checking rv and returning ret may look a bit odd, I don't think it changes the behavior or introduces a bug.
Quoted 2 lines
The local ret variable can be deleted.
Should change all the error returns to directly returnIRQ_NONE.
As you suggested,
I'll remove the ret variable entirely and return IRQ_NONE / IRQ_HANDLED directly.
Best regards,
Phuc
Richard Fitzgerald
maintainerRe: [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
Quoted 16 lines · Bui Duc Phuc
Hi Cezary, Richard,
Thanks to both of you for the reviews!
Quoted 11 lines
sound/soc/codecs/cs35l56-shared.c irqreturn_t cs35l56_irq(int irq, void *data) · line 694
Quoted 10 lines
sound/soc/codecs/cs35l56-shared.c +1
-7- ret =IRQ_HANDLED ; +return IRQ_HANDLED ; -err: -pm_runtime_put (cs35l56_base->dev); -err_unlock: -mutex_unlock (&cs35l56_base->irq_lock); - -return ret; }Nitpick: this will leave a superfluous newline.
Quoted 9 lines
You're right. I'll remove the extra blank line.
Quoted 1 line
It looks like a bug that it checks rv but returns ret.
I'm not sure I fully understand what you meant by that comment. This conversion preserves the existing behavior, so although checking rv and returning ret may look a bit odd, I don't think it changes the behavior or introduces a bug.
I mean the code is correct but it looks wrong. Because it tests for an error in rv but then returns a value in ret.
This can be cleaned up now. ret isn't needed because it can return IRQ_NONE in all these places.
Quoted 9 lines
Quoted 2 lines
The local ret variable can be deleted.
Should change all the error returns to directly returnIRQ_NONE.As you suggested,
I'll remove the ret variable entirely and returnIRQ_NONE/IRQ_HANDLEDdirectly.Best regards,
Phuc
Re: [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers
Hi Richard,
Quoted 7 lines
I mean the code is correct but it looks wrong. Because it tests for an error in rv but then returns a value in ret.
This can be cleaned up now. ret isn't needed because it can return
IRQ_NONEin all these places.
Got it, thanks for clarifying.
Best regards,
Phuc
PATCH v2 14/24 ASoC: codecs: cs42l42: Use guard() cleanup helpers
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() helpers for mutex locking and PM runtime management.
No functional change intended.
--- sound/soc/codecs/cs42l42.c | 54 +++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 30 deletions(-)
sound/soc/codecs/cs42l42.c +24 -30
@@ -9,6 +9,7 @@* Author: Michael White <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/types.h>
@@ -565,7 +566,7 @@ static int cs42l42_set_jack(struct snd_soc_component *component, struct snd_soc_struct cs42l42_private *cs42l42 =snd_soc_component_get_drvdata (component);/* Prevent race with interrupt handler */ -mutex_lock (&cs42l42->irq_lock); +guard (mutex)(&cs42l42->irq_lock); cs42l42->jack = jk;if (jk) {
@@ -581,7 +582,6 @@ static int cs42l42_set_jack(struct snd_soc_component *component, struct snd_soc_break ; } } -mutex_unlock (&cs42l42->irq_lock);return 0 ; }
@@ -1668,13 +1668,10 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)unsigned int current_button_status;unsigned int i; -pm_runtime_get_sync (cs42l42->dev); -mutex_lock (&cs42l42->irq_lock); -if (cs42l42->suspended || !cs42l42->init_done) { -mutex_unlock (&cs42l42->irq_lock); -pm_runtime_put_autosuspend (cs42l42->dev); +guard (pm_runtime_active_auto)(cs42l42->dev); +guard (mutex)(&cs42l42->irq_lock); +if (cs42l42->suspended || !cs42l42->init_done)return IRQ_NONE ; - }/* Read sticky registers to clear interurpt */ for (i =0 ; i <ARRAY_SIZE (stickies); i++) {
@@ -1774,9 +1771,6 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data) } } -mutex_unlock (&cs42l42->irq_lock); -pm_runtime_put_autosuspend (cs42l42->dev); -return IRQ_HANDLED ; }EXPORT_SYMBOL_NS_GPL (cs42l42_irq_thread,"SND_SOC_CS42L42_CORE" );
@@ -2163,22 +2157,22 @@ int cs42l42_suspend(struct device *dev)* future interrupts. This ensures a safe disable if the interrupt * is shared. */ -mutex_lock (&cs42l42->irq_lock); - cs42l42->suspended = true; + scoped_guard(mutex, &cs42l42->irq_lock) { + cs42l42->suspended = true; -/* Save register values that will be overwritten by shutdown sequence */ -for (i =0 ; i <ARRAY_SIZE (cs42l42_shutdown_seq); ++i) { -regmap_read (cs42l42->regmap, cs42l42_shutdown_seq[i].reg, ®); - save_regs[i] = (u8 )reg; - } +/* Save register values that will be overwritten by shutdown sequence */ +for (i =0 ; i <ARRAY_SIZE (cs42l42_shutdown_seq); ++i) { +regmap_read (cs42l42->regmap, cs42l42_shutdown_seq[i].reg, ®); + save_regs[i] = (u8 )reg; + } -/* Shutdown codec */ -regmap_multi_reg_write (cs42l42->regmap, - cs42l42_shutdown_seq, -ARRAY_SIZE (cs42l42_shutdown_seq)); +/* Shutdown codec */ +regmap_multi_reg_write (cs42l42->regmap, + cs42l42_shutdown_seq, +ARRAY_SIZE (cs42l42_shutdown_seq)); -/* All interrupt sources are now disabled */ -mutex_unlock (&cs42l42->irq_lock); +/* All interrupt sources are now disabled */ + }/* Wait for power-down complete */ msleep (CS42L42_PDN_DONE_TIME_MS );
@@ -2250,13 +2244,13 @@ void cs42l42_resume_restore(struct device *dev)regcache_cache_only (cs42l42->regmap, false);regcache_mark_dirty (cs42l42->regmap); -mutex_lock (&cs42l42->irq_lock); -/* Sync LATCH_TO_VP first so the VP domain registers sync correctly */ -regcache_sync_region (cs42l42->regmap,CS42L42_MIC_DET_CTL1 ,CS42L42_MIC_DET_CTL1 ); -regcache_sync (cs42l42->regmap); + scoped_guard(mutex, &cs42l42->irq_lock) { +/* Sync LATCH_TO_VP first so the VP domain registers sync correctly */ +regcache_sync_region (cs42l42->regmap,CS42L42_MIC_DET_CTL1 ,CS42L42_MIC_DET_CTL1 ); +regcache_sync (cs42l42->regmap); - cs42l42->suspended = false; -mutex_unlock (&cs42l42->irq_lock); + cs42l42->suspended = false; + }dev_dbg (dev,"System resumed\n" ); }
Signature · 1 line
2.43.0
PATCH v2 15/24 ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers
In reply to [email protected]From: bui duc phuc <[email protected]>
Convert mutex locking to guard(mutex) and replace explicit runtime PM handling with runtime PM scope helpers.
This simplifies the control flow by removing explicit cleanup paths and unnecessary 'goto' labels.
---
Changes in v2:
Switched to a helper function to avoid code duplication, while keeping the guard() conversion since it eliminates 12 goto labels.
sound/soc/codecs/cs42l43-jack.c | 120 ++++++++++++++------------------ sound/soc/codecs/cs42l43.c | 16 ++--- 2 files changed, 58 insertions(+), 78 deletions(-)
sound/soc/codecs/cs42l43-jack.c +53 -67
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. #include <linux/build_bug.h> +#include <linux/cleanup.h> #include <linux/completion.h> #include <linux/delay.h> #include <linux/errno.h>
@@ -67,6 +68,21 @@ static int cs42l43_find_index(struct cs42l43_codec *priv, const char * const proreturn -EINVAL ; } +static void cs42l43_apply_accdet_config (struct cs42l43_codec *priv, +unsigned int autocontrol, +unsigned int pdncntl) +{ +struct cs42l43 *cs42l43 = priv->core; + +regmap_update_bits (cs42l43->regmap,CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL , +CS42L43_JACKDET_MODE_MASK |CS42L43_S0_AUTO_ADCMUTE_DISABLE_MASK | +CS42L43_HSBIAS_SENSE_TRIP_MASK , autocontrol); +regmap_update_bits (cs42l43->regmap,CS42L43_PDNCNTL , +CS42L43_RING_SENSE_EN_MASK , pdncntl); + +dev_dbg (priv->dev,"Successfully configured accessory detect\n" ); +} +int cs42l43_set_jack (struct snd_soc_component *component,struct snd_soc_jack *jack,void *d) {
@@ -80,31 +96,34 @@ int cs42l43_set_jack(struct snd_soc_component *component,dev_dbg (priv->dev,"Configure accessory detect\n" ); - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for jack config: %d\n" , ret);return ret; } -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock); priv->jack_hp = jack; -if (!jack) - goto done; +if (!jack) { +cs42l43_apply_accdet_config (priv, autocontrol, pdncntl); +return 0 ; + } ret =device_property_count_u32 (cs42l43->dev,"cirrus,buttons-ohms" );if (ret != -EINVAL ) {if (ret <0 ) {dev_err (priv->dev,"Property cirrus,buttons-ohms malformed: %d\n" , ret); - goto error; +return ret; }if (ret >CS42L43_N_BUTTONS ) { ret = -EINVAL ;dev_err (priv->dev,"Property cirrus,buttons-ohms too many entries\n" ); - goto error; +return ret; } ret = device_property_read_u32_array(cs42l43->dev, "cirrus,buttons-ohms",
@@ -112,7 +131,7 @@ int cs42l43_set_jack(struct snd_soc_component *component,if (ret <0 ) {dev_err (priv->dev,"Property cirrus,button-ohms malformed: %d\n" , ret); - goto error; +return ret; } }else { priv->buttons[0 ] =70 ;
@@ -124,7 +143,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, ret =cs42l43_find_index (priv,"cirrus,detect-us" ,50000 , &priv->detect_us, cs42l43_accdet_us,ARRAY_SIZE (cs42l43_accdet_us));if (ret <0 ) - goto error; +return ret; hs2 |= ret <<CS42L43_AUTO_HSDET_TIME_SHIFT ;
@@ -134,7 +153,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, &priv->bias_ramp_ms, cs42l43_accdet_ramp_ms, ARRAY_SIZE(cs42l43_accdet_ramp_ms));if (ret <0 ) - goto error; +return ret; hs2 |= ret <<CS42L43_HSBIAS_RAMP_SHIFT ;
@@ -142,7 +161,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, &priv->bias_sense_ua, cs42l43_accdet_bias_sense, ARRAY_SIZE(cs42l43_accdet_bias_sense));if (ret <0 ) - goto error; +return ret;if (priv->bias_sense_ua) autocontrol |= ret <<CS42L43_HSBIAS_SENSE_TRIP_SHIFT ;
@@ -154,7 +173,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, &priv->tip_debounce_ms);if (ret <0 && ret != -EINVAL ) {dev_err (priv->dev,"Property cirrus,tip-debounce-ms malformed: %d\n" , ret); - goto error; +return ret; }/* This tip sense invert is set normally, as TIPSENSE_INV already inverted */
@@ -170,7 +189,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, &priv->tip_fall_db_ms, cs42l43_accdet_db_ms, ARRAY_SIZE(cs42l43_accdet_db_ms));if (ret <0 ) - goto error; +return ret; tip_deb |= ret <<CS42L43_TIPSENSE_FALLING_DB_TIME_SHIFT ;
@@ -178,7 +197,7 @@ int cs42l43_set_jack(struct snd_soc_component *component, &priv->tip_rise_db_ms, cs42l43_accdet_db_ms, ARRAY_SIZE(cs42l43_accdet_db_ms));if (ret <0 ) - goto error; +return ret; tip_deb |= ret <<CS42L43_TIPSENSE_RISING_DB_TIME_SHIFT ;
@@ -199,7 +218,7 @@ int cs42l43_set_jack(struct snd_soc_component *component,NULL , cs42l43_accdet_db_ms, ARRAY_SIZE(cs42l43_accdet_db_ms));if (ret <0 ) - goto error; +return ret; ring_deb |= ret <<CS42L43_RINGSENSE_FALLING_DB_TIME_SHIFT ;
@@ -207,7 +226,7 @@ int cs42l43_set_jack(struct snd_soc_component *component,NULL , cs42l43_accdet_db_ms, ARRAY_SIZE(cs42l43_accdet_db_ms));if (ret <0 ) - goto error; +return ret; ring_deb |= ret <<CS42L43_RINGSENSE_RISING_DB_TIME_SHIFT ; pdncntl |=CS42L43_RING_SENSE_EN_MASK ;
@@ -228,23 +247,9 @@ int cs42l43_set_jack(struct snd_soc_component *component,CS42L43_HSBIAS_RAMP_MASK |CS42L43_HSDET_MODE_MASK | CS42L43_AUTO_HSDET_TIME_MASK, hs2); -done: - ret =0 ; - -regmap_update_bits (cs42l43->regmap,CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL , -CS42L43_JACKDET_MODE_MASK |CS42L43_S0_AUTO_ADCMUTE_DISABLE_MASK | -CS42L43_HSBIAS_SENSE_TRIP_MASK , autocontrol); -regmap_update_bits (cs42l43->regmap,CS42L43_PDNCNTL , -CS42L43_RING_SENSE_EN_MASK , pdncntl); - -dev_dbg (priv->dev,"Successfully configured accessory detect\n" ); - -error: -mutex_unlock (&priv->jack_lock); - -pm_runtime_put_autosuspend (priv->dev); +cs42l43_apply_accdet_config (priv, autocontrol, pdncntl); -return ret; +return 0 ; }static void cs42l43_start_hs_bias (struct cs42l43_codec *priv,bool type_detect)
@@ -374,17 +379,18 @@ irqreturn_t cs42l43_button_press(int irq, void *data)unsigned int val =0 ;int i, ret; - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for button press: %d\n" , ret);return iret; } -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock);if (!priv->button_detect_running) {dev_dbg (priv->dev,"Spurious button press IRQ\n" ); - goto error; +return iret; }// Wait for 2 full cycles of comb filter to ensure good reading
@@ -395,12 +401,12 @@ irqreturn_t cs42l43_button_press(int irq, void *data)/* Bail if jack removed, the button is irrelevant and likely invalid */ if (!cs42l43_jack_present (priv)) {dev_dbg (priv->dev,"Button ignored due to removal\n" ); - goto error; +return iret; }if (val &CS42L43_HSBIAS_CLAMP_STS_MASK ) {dev_dbg (priv->dev,"Button ignored due to bias sense\n" ); - goto error; +return iret; } val = (val &CS42L43_HSDET_DC_STS_MASK ) >>CS42L43_HSDET_DC_STS_SHIFT ;
@@ -423,14 +429,7 @@ irqreturn_t cs42l43_button_press(int irq, void *data)snd_soc_jack_report (priv->jack_hp, buttons,CS42L43_JACK_BUTTONS ); - iret =IRQ_HANDLED ; - -error: -mutex_unlock (&priv->jack_lock); - -pm_runtime_put_autosuspend (priv->dev); - -return iret; +return IRQ_HANDLED ; }irqreturn_t cs42l43_button_release (int irq,void *data)
@@ -439,13 +438,14 @@ irqreturn_t cs42l43_button_release(int irq, void *data)irqreturn_t iret =IRQ_NONE ;int ret; - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for button release: %d\n" , ret);return iret; } -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock);if (priv->button_detect_running) {dev_dbg (priv->dev,"Button release IRQ\n" );
@@ -457,10 +457,6 @@ irqreturn_t cs42l43_button_release(int irq, void *data)dev_dbg (priv->dev,"Spurious button release IRQ\n" ); } -mutex_unlock (&priv->jack_lock); - -pm_runtime_put_autosuspend (priv->dev); -return iret; }
@@ -471,13 +467,14 @@ void cs42l43_bias_sense_timeout(struct work_struct *work)struct cs42l43 *cs42l43 = priv->core;int ret; - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for bias sense: %d\n" , ret);return ; } -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock);if (cs42l43_jack_present (priv) && priv->button_detect_running) {dev_dbg (priv->dev,"Bias sense timeout out, restore bias\n" );
@@ -490,10 +487,6 @@ void cs42l43_bias_sense_timeout(struct work_struct *work)CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK , CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK); } - -mutex_unlock (&priv->jack_lock); - -pm_runtime_put_autosuspend (priv->dev); }static const struct reg_sequence cs42l43_3pole_patch[] = {
@@ -895,9 +888,8 @@ int cs42l43_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ustruct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct cs42l43_codec *priv =snd_soc_component_get_drvdata (component); -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock); ucontrol->value.integer.value[0 ] = priv->jack_override; -mutex_unlock (&priv->jack_lock);return 0 ; }
@@ -913,17 +905,13 @@ int cs42l43_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uif (override >= e->items)return -EINVAL ; -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock); -if (!cs42l43_jack_present (priv)) { -mutex_unlock (&priv->jack_lock); +if (!cs42l43_jack_present (priv))return -EBUSY ; - } -if (override == priv->jack_override) { -mutex_unlock (&priv->jack_lock); +if (override == priv->jack_override)return 0 ; - } priv->jack_override = override;
@@ -983,7 +971,5 @@ int cs42l43_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u cs42l43_jack_override_modes[override].report); } -mutex_unlock (&priv->jack_lock); -return 1 ; }
sound/soc/codecs/cs42l43.c +5 -11
@@ -8,6 +8,7 @@#include <linux/bitops.h> #include <linux/bits.h> #include <linux/build_bug.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/device.h> #include <linux/err.h>
@@ -1208,14 +1209,12 @@ static void cs42l43_spk_vu_sync(struct cs42l43_codec *priv) {struct cs42l43 *cs42l43 = priv->core; -mutex_lock (&priv->spk_vu_lock); +guard (mutex)(&priv->spk_vu_lock);regmap_update_bits (cs42l43->regmap,CS42L43_INTP_VOLUME_CTRL1 ,CS42L43_AMP1_2_VU_MASK ,CS42L43_AMP1_2_VU_MASK );regmap_update_bits (cs42l43->regmap,CS42L43_INTP_VOLUME_CTRL1 ,CS42L43_AMP1_2_VU_MASK ,0 ); - -mutex_unlock (&priv->spk_vu_lock); }static int cs42l43_shutter_get (struct cs42l43_codec *priv,unsigned int shift)
@@ -1602,7 +1601,7 @@ static int cs42l43_pll_ev(struct snd_soc_dapm_widget *w,struct cs42l43 *cs42l43 = priv->core;int ret; -mutex_lock (&cs42l43->pll_lock); +guard (mutex)(&cs42l43->pll_lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :
@@ -1627,8 +1626,6 @@ static int cs42l43_pll_ev(struct snd_soc_dapm_widget *w,break ; } -mutex_unlock (&cs42l43->pll_lock); -return ret; }
@@ -2566,13 +2563,10 @@ static int cs42l43_set_sysclk(struct snd_soc_component *component, int clk_id, {struct cs42l43_codec *priv =snd_soc_component_get_drvdata (component);struct cs42l43 *cs42l43 = priv->core; -int ret; -mutex_lock (&cs42l43->pll_lock); - ret =cs42l43_set_pll (priv, src, freq); -mutex_unlock (&cs42l43->pll_lock); +guard (mutex)(&cs42l43->pll_lock); -return ret; +return cs42l43_set_pll (priv, src, freq); }static int cs42l43_component_probe (struct snd_soc_component *component)
Signature · 1 line
2.43.0
Charles Keepax
maintainerRe: [PATCH v2 15/24] ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers
Quoted 10 lines · On Fri, Jul 03, 2026 at 12:53:46PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
Convert mutex locking to guard(mutex) and replace explicit runtime PM handling with runtime PM scope helpers.
This simplifies the control flow by removing explicit cleanup paths and unnecessary 'goto' labels.Signed-off-by bui duc phuc <[email protected]>---
sound/soc/codecs/cs42l43-jack.c irqreturn_t cs42l43_button_press(int irq, void *data) · line 386
Quoted 9 lines
sound/soc/codecs/cs42l43-jack.c +2
-1@@ -374,17 +379,18 @@ irqreturn_t cs42l43_button_press(int irq, void *data)unsigned int val =0 ;int i, ret; - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for button press: %d\n" , ret);return iret;
iret only really made sense with the goto, might as well drop the variable and return IRQ_NONE directly.
Quoted 13 lines
sound/soc/codecs/cs42l43-jack.c +2
-2} -mutex_lock (&priv->jack_lock); +guard (mutex)(&priv->jack_lock);if (!priv->button_detect_running) {dev_dbg (priv->dev,"Spurious button press IRQ\n" ); - goto error; +return iret; }irqreturn_t cs42l43_button_release (int irq,void *data)
sound/soc/codecs/cs42l43-jack.c irqreturn_t cs42l43_button_release(int irq, void *data) · line 445
Quoted 9 lines
sound/soc/codecs/cs42l43-jack.c +2
-1@@ -439,13 +438,14 @@ irqreturn_t cs42l43_button_release(int irq, void *data)irqreturn_t iret =IRQ_NONE ;int ret; - ret =pm_runtime_resume_and_get (priv->dev); +PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (priv->dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm);if (ret) {dev_err (priv->dev,"Failed to resume for button release: %d\n" , ret);return iret;
Same in cs42l43_button_release().
Thanks,
Charles
Re: [PATCH v2 15/24] ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers
Hi Charles,
Thank you for your review!
Quoted 7 lines
iret only really made sense with the goto, might as well drop the variable and return
IRQ_NONEdirectly.Same in
cs42l43_button_release().
I'll address your comments and send a v3.
Best regards,
Phuc
PATCH v2 16/24 ASoC: codecs: cs42l84: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs42l84.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/soc/codecs/cs42l84.c +3 -7
@@ -10,6 +10,7 @@#include <linux/bitfield.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h>
@@ -281,10 +282,9 @@ static int cs42l84_set_jack(struct snd_soc_component *component, struct snd_soc_struct cs42l84_private *cs42l84 =snd_soc_component_get_drvdata (component);/* Prevent race with interrupt handler */ -mutex_lock (&cs42l84->irq_lock); +guard (mutex)(&cs42l84->irq_lock); cs42l84->jack = jk;snd_soc_jack_report (jk, cs42l84->hs_type,SND_JACK_HEADSET ); -mutex_unlock (&cs42l84->irq_lock);return 0 ; }
@@ -831,7 +831,7 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)u8 current_ring_state;int i; -mutex_lock (&cs42l84->irq_lock); +guard (mutex)(&cs42l84->irq_lock);/* Read sticky registers to clear interrupt */ for (i =0 ; i <ARRAY_SIZE (stickies); i++) { regmap_read(cs42l84->regmap, irq_params_table[i].status_addr,
@@ -902,8 +902,6 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)break ; } -mutex_unlock (&cs42l84->irq_lock); -return IRQ_HANDLED ; }
@@ -919,8 +917,6 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data) } } -mutex_unlock (&cs42l84->irq_lock); -return IRQ_HANDLED ; }
Signature · 1 line
2.43.0
PATCH v2 17/24 ASoC: codecs: cs43130: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs43130.c | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-)
sound/soc/codecs/cs43130.c +36 -36
@@ -6,6 +6,7 @@* * Authors: Li Xu <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h>
@@ -818,26 +819,26 @@ static int cs43130_dsd_hw_params(struct snd_pcm_substream *substream,unsigned int required_clk;u8 dsd_speed; -mutex_lock (&cs43130->clk_mutex); -if (!cs43130->clk_req) { -/* no DAI is currently using clk */ -if (!(CS43130_MCLK_22M %params_rate (params))) - required_clk =CS43130_MCLK_22M ; -else - required_clk =CS43130_MCLK_24M ; + scoped_guard(mutex, &cs43130->clk_mutex) { +if (!cs43130->clk_req) { +/* no DAI is currently using clk */ +if (!(CS43130_MCLK_22M %params_rate (params))) + required_clk =CS43130_MCLK_22M ; +else + required_clk =CS43130_MCLK_24M ; + +cs43130_set_pll (component,0 ,0 , cs43130->mclk, required_clk); +if (cs43130->pll_bypass) +cs43130_change_clksrc (component,CS43130_MCLK_SRC_EXT ); +else +cs43130_change_clksrc (component,CS43130_MCLK_SRC_PLL ); + } -cs43130_set_pll (component,0 ,0 , cs43130->mclk, required_clk); -if (cs43130->pll_bypass) -cs43130_change_clksrc (component,CS43130_MCLK_SRC_EXT ); -else -cs43130_change_clksrc (component,CS43130_MCLK_SRC_PLL ); + cs43130->clk_req++; +if (cs43130->clk_req ==2 ) +cs43130_pcm_dsd_mix (true, cs43130->regmap); } - cs43130->clk_req++; -if (cs43130->clk_req ==2 ) -cs43130_pcm_dsd_mix (true, cs43130->regmap); -mutex_unlock (&cs43130->clk_mutex); -switch (params_rate (params)) {case 176400 : dsd_speed =0 ;
@@ -881,26 +882,26 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream,unsigned int required_clk;u8 dsd_speed; -mutex_lock (&cs43130->clk_mutex); -if (!cs43130->clk_req) { -/* no DAI is currently using clk */ -if (!(CS43130_MCLK_22M %params_rate (params))) - required_clk =CS43130_MCLK_22M ; -else - required_clk =CS43130_MCLK_24M ; + scoped_guard(mutex, &cs43130->clk_mutex) { +if (!cs43130->clk_req) { +/* no DAI is currently using clk */ +if (!(CS43130_MCLK_22M %params_rate (params))) + required_clk =CS43130_MCLK_22M ; +else + required_clk =CS43130_MCLK_24M ; + +cs43130_set_pll (component,0 ,0 , cs43130->mclk, required_clk); +if (cs43130->pll_bypass) +cs43130_change_clksrc (component,CS43130_MCLK_SRC_EXT ); +else +cs43130_change_clksrc (component,CS43130_MCLK_SRC_PLL ); + } -cs43130_set_pll (component,0 ,0 , cs43130->mclk, required_clk); -if (cs43130->pll_bypass) -cs43130_change_clksrc (component,CS43130_MCLK_SRC_EXT ); -else -cs43130_change_clksrc (component,CS43130_MCLK_SRC_PLL ); + cs43130->clk_req++; +if (cs43130->clk_req ==2 ) +cs43130_pcm_dsd_mix (true, cs43130->regmap); } - cs43130->clk_req++; -if (cs43130->clk_req ==2 ) -cs43130_pcm_dsd_mix (true, cs43130->regmap); -mutex_unlock (&cs43130->clk_mutex); -switch (dai->id) {case CS43130_ASP_DOP_DAI :case CS43130_XSP_DOP_DAI :
@@ -988,14 +989,13 @@ static int cs43130_hw_free(struct snd_pcm_substream *substream,struct snd_soc_component *component = dai->component;struct cs43130_private *cs43130 =snd_soc_component_get_drvdata (component); -mutex_lock (&cs43130->clk_mutex); +guard (mutex)(&cs43130->clk_mutex); cs43130->clk_req--;if (!cs43130->clk_req) {/* no DAI is currently using clk */ cs43130_change_clksrc (component,CS43130_MCLK_SRC_RCO );cs43130_pcm_dsd_mix (false, cs43130->regmap); } -mutex_unlock (&cs43130->clk_mutex);return 0 ; }
Signature · 1 line
2.43.0
Re: [PATCH v2 17/24] ASoC: codecs: cs43130: Use guard() for mutex locks
Quoted 7 lines · On Fri, Jul 03, 2026 at 12:53:48PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
Clean up the code using
guard()for mutex locks.
Merely code refactoring, and no behavior change.Signed-off-by bui duc phuc <[email protected]>---
Thanks,
Charles
PATCH v2 18/24 ASoC: codecs: cs47l15: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs47l15.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
sound/soc/codecs/cs47l15.c +5 -6
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/device.h>
@@ -1285,9 +1286,8 @@ static int cs47l15_component_probe(struct snd_soc_component *component)snd_soc_component_init_regmap (component, madera->regmap); -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =snd_soc_component_to_dapm (component); -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = snd_soc_component_to_dapm(component); ret =madera_init_inputs (component);if (ret)
@@ -1317,9 +1317,8 @@ static void cs47l15_component_remove(struct snd_soc_component *component)struct cs47l15 *cs47l15 =snd_soc_component_get_drvdata (component);struct madera *madera = cs47l15->core.madera; -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =NULL ; -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = NULL;wm_adsp2_component_remove (&cs47l15->core.adsp[0 ], component); }
Signature · 1 line
2.43.0
PATCH v2 19/24 ASoC: codecs: cs47l35: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs47l35.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
sound/soc/codecs/cs47l35.c +5 -6
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/init.h>
@@ -1566,9 +1567,8 @@ static int cs47l35_component_probe(struct snd_soc_component *component)snd_soc_component_init_regmap (component, madera->regmap); -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =snd_soc_component_to_dapm (component); -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = snd_soc_component_to_dapm(component); ret =madera_init_inputs (component);if (ret)
@@ -1600,9 +1600,8 @@ static void cs47l35_component_remove(struct snd_soc_component *component)struct madera *madera = cs47l35->core.madera;int i; -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =NULL ; -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = NULL;for (i =0 ; i <CS47L35_NUM_ADSP ; i++)wm_adsp2_component_remove (&cs47l35->core.adsp[i], component);
Signature · 1 line
2.43.0
PATCH v2 20/24 ASoC: codecs: cs47l85: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs47l85.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
sound/soc/codecs/cs47l85.c +5 -6
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/device.h>
@@ -2504,9 +2505,8 @@ static int cs47l85_component_probe(struct snd_soc_component *component)snd_soc_component_init_regmap (component, madera->regmap); -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =snd_soc_component_to_dapm (component); -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = snd_soc_component_to_dapm(component); ret =madera_init_inputs (component);if (ret)
@@ -2537,9 +2537,8 @@ static void cs47l85_component_remove(struct snd_soc_component *component)struct madera *madera = cs47l85->core.madera;int i; -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =NULL ; -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = NULL;for (i =0 ; i <CS47L85_NUM_ADSP ; i++)wm_adsp2_component_remove (&cs47l85->core.adsp[i], component);
Signature · 1 line
2.43.0
PATCH v2 21/24 ASoC: codecs: cs47l90: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs47l90.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
sound/soc/codecs/cs47l90.c +5 -6
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/device.h>
@@ -2423,9 +2424,8 @@ static int cs47l90_component_probe(struct snd_soc_component *component)snd_soc_component_init_regmap (component, madera->regmap); -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =snd_soc_component_to_dapm (component); -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = snd_soc_component_to_dapm(component); ret =madera_init_inputs (component);if (ret)
@@ -2456,9 +2456,8 @@ static void cs47l90_component_remove(struct snd_soc_component *component)struct madera *madera = cs47l90->core.madera;int i; -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =NULL ; -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = NULL;for (i =0 ; i <CS47L90_NUM_ADSP ; i++)wm_adsp2_component_remove (&cs47l90->core.adsp[i], component);
Signature · 1 line
2.43.0
PATCH v2 22/24 ASoC: codecs: cs47l92: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cs47l92.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
sound/soc/codecs/cs47l92.c +5 -6
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/device.h>
@@ -1892,9 +1893,8 @@ static int cs47l92_component_probe(struct snd_soc_component *component)snd_soc_component_init_regmap (component, madera->regmap); -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =snd_soc_component_to_dapm (component); -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = snd_soc_component_to_dapm(component); ret =madera_init_inputs (component);if (ret)
@@ -1922,9 +1922,8 @@ static void cs47l92_component_remove(struct snd_soc_component *component)struct cs47l92 *cs47l92 =snd_soc_component_get_drvdata (component);struct madera *madera = cs47l92->core.madera; -mutex_lock (&madera->dapm_ptr_lock); - madera->dapm =NULL ; -mutex_unlock (&madera->dapm_ptr_lock); +scoped_guard (mutex, &madera->dapm_ptr_lock) + madera->dapm = NULL;wm_adsp2_component_remove (&cs47l92->core.adsp[0 ], component); }
Signature · 1 line
2.43.0
PATCH v2 23/24 ASoC: codecs: cs48l32: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
---
Changes in v2:
Removed the unnecessary else block so update_bits() is not called when no changes are needed.
sound/soc/codecs/cs48l32.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
sound/soc/codecs/cs48l32.c +10 -16
@@ -8,6 +8,7 @@#include <dt-bindings/sound/cs48l32.h> #include <linux/array_size.h> #include <linux/build_bug.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/container_of.h> #include <linux/delay.h>
@@ -236,15 +237,13 @@ static int cs48l32_rate_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_vint ret;/* Prevent any mixer mux changes while we do this */ -mutex_lock (&cs48l32_codec->rate_lock); +guard (mutex)(&cs48l32_codec->rate_lock);/* The write must be guarded by a number of SYSCLK cycles */ cs48l32_spin_sysclk (cs48l32_codec); ret =snd_soc_put_enum_double (kcontrol, ucontrol);cs48l32_spin_sysclk (cs48l32_codec); -mutex_unlock (&cs48l32_codec->rate_lock); -return ret; }
@@ -2242,7 +2241,6 @@ static int cs48l32_dai_set_sysclk(struct snd_soc_dai *dai,struct cs48l32_dai_priv *dai_priv = &cs48l32_codec->dai[dai->id -1 ];unsigned int base = dai->driver->base;unsigned int current_asp_rate, target_asp_rate; -bool change_rate_domain = false;int ret;if (clk_id == dai_priv->clk)
@@ -2284,19 +2282,15 @@ static int cs48l32_dai_set_sysclk(struct snd_soc_dai *dai,if ((current_asp_rate &CS48L32_ASP_RATE_MASK ) != (target_asp_rate &CS48L32_ASP_RATE_MASK )) { - change_rate_domain = true; - -mutex_lock (&cs48l32_codec->rate_lock);/* Guard the rate change with SYSCLK cycles */ -cs48l32_spin_sysclk (cs48l32_codec); - } - -snd_soc_component_update_bits (component, base +CS48L32_ASP_CONTROL1 , -CS48L32_ASP_RATE_MASK , target_asp_rate); - -if (change_rate_domain) { -cs48l32_spin_sysclk (cs48l32_codec); -mutex_unlock (&cs48l32_codec->rate_lock); + scoped_guard(mutex, &cs48l32_codec->rate_lock) { +cs48l32_spin_sysclk (cs48l32_codec); +snd_soc_component_update_bits (component, + base +CS48L32_ASP_CONTROL1 , +CS48L32_ASP_RATE_MASK , + target_asp_rate); +cs48l32_spin_sysclk (cs48l32_codec); + } } }
Signature · 1 line
2.43.0
Re: [PATCH v2 23/24] ASoC: codecs: cs48l32: Use guard() for mutex locks
Quoted 7 lines · On Fri, Jul 03, 2026 at 12:53:54PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
Clean up the code using
guard()for mutex locks.
Merely code refactoring, and no behavior change.Signed-off-by bui duc phuc <[email protected]>---
Thanks,
Charles
PATCH v2 24/24 ASoC: codecs: cs2072x: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/codecs/cx2072x.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
sound/soc/codecs/cx2072x.c +2 -3
@@ -9,6 +9,7 @@// #include <linux/acpi.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/gpio.h>
@@ -1408,7 +1409,7 @@ static int cx2072x_jack_status_check(void *data)unsigned int type =0 ;int state =0 ; -mutex_lock (&cx2072x->lock); +guard (mutex)(&cx2072x->lock);regmap_read (cx2072x->regmap,CX2072X_PORTA_PIN_SENSE , &jack); jack = jack >>24 ;
@@ -1434,8 +1435,6 @@ static int cx2072x_jack_status_check(void *data)/* clear interrupt */ regmap_write (cx2072x->regmap,CX2072X_UM_INTERRUPT_CRTL_E ,0x12 <<24 ); -mutex_unlock (&cx2072x->lock); -dev_dbg (codec->dev,"CX2072X_HSDETECT type=0x%X,Jack state = %x\n" , type, state);return state;
Signature · 1 line
2.43.0
On 7/3/2026 7:53 AM, [email protected] wrote:
...
Quoted 17 lines
bui duc phuc (24):
ASoC: codecs: ab8500: Useguard()for mutex locks
ASoC: codecs: ak4613: Useguard()for mutex locks
ASoC: codecs: arizona-jack: Useguard()cleanup helpers
ASoC: codecs: arizona: Useguard()for mutex locks
ASoC: codecs: aw87390: Useguard()for mutex locks
ASoC: codecs: aw88081: Useguard()for mutex locks
ASoC: codecs: aw88166: Useguard()for mutex locks
ASoC: codecs: aw88261: Useguard()for mutex locks
ASoC: codecs: aw88395: Useguard()for mutex locks
ASoC: codecs: aw88399: Useguard()for mutex locks
ASoC: codecs:cros_ec_codec: Useguard()for mutex locks
ASoC: codecs: cs-amp-lib: Useguard()for mutex locks
ASoC: codecs: cs35l56: Useguard()and PM runtime scope helpers
ASoC: codecs: cs42l42: Useguard()cleanup helpers
ASoC: codecs: cs42l43: Useguard()and PM runtime scope helpers
ASoC: codecs: cs42l84: Useguard()for mutex locks
Quoted 8 lines
ASoC: codecs: cs43130: Use
guard()for mutex locks
ASoC: codecs: cs47l15: Useguard()for mutex locks
ASoC: codecs: cs47l35: Useguard()for mutex locks
ASoC: codecs: cs47l85: Useguard()for mutex locks
ASoC: codecs: cs47l90: Useguard()for mutex locks
ASoC: codecs: cs47l92: Useguard()for mutex locks
ASoC: codecs: cs48l32: Useguard()for mutex locks
ASoC: codecs: cs2072x: Useguard()for mutex locks
Hi Phuc,
All the guard()-alone patches look good, the ones with PM runtime look monstrous - much harder to review. Especially in 'cs42l43' and cs42l43_apply_accdet_config() case, I'd split the cleanup.
However, I'm not the one who will run the functional tests for these and from review-perspective, the patchset overall looks OK:
Hi Cezary,
Thanks for your review and for the Reviewed-by tag.
Quoted 4 lines
However, I'm not the one who will run the functional tests for these and from review-perspective, the patchset overall looks OK:
Reviewed-by Cezary Rojewski <[email protected]>
I'll add it to the next revision.
Best regards,
Phuc