ASoC: codecs: Use guard() for mutex & spin locks - part 2
Subsystems (12)
v3 cover ASoC: codecs: Use guard() for mutex & spin locks - part 2
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 is part 2 of a larger 78-patch conversion series. Part 1 (24 patches) has already been posted, while this series contains the next 27 patches to keep the review manageable.
https://lore.kernel.org/all/[email protected]/
The changes are purely refactoring and have no functional impact. Compile-tested only.
Changes in v3:
- Rebased onto the latest broonie/for-next.
Changes in v2:
- Add Reviewed-by tags from Charles and Herve.
- Address Herve's review comments.
Link v2:
https://lore.kernel.org/all/[email protected]/
Link v1 :
https://lore.kernel.org/all/[email protected]/
Best regards,
Phuc
bui duc phuc (27):
ASoC: codecs: da7213: Use guard() for mutex locks
ASoC: codecs: da7219: Use guard() for mutex locks
ASoC: codecs: es8316: Use guard() for mutex locks
ASoC: codecs: es8326: Use guard() for mutex locks
ASoC: codecs: es9356: Use guard() for mutex locks
ASoC: codecs: fs210x: Use guard() for mutex locks
ASoC: codecs: hdac_hdmi: Use guard() for mutex locks
ASoC: codecs: hdmi-codec: Use guard() for mutex locks
ASoC: codecs: idt821034: Use guard() for mutex locks
ASoC: codecs: lpass-macro: Use guard() for mutex locks
ASoC: codecs: madera: Use guard() for mutex locks
ASoC: codecs: max98095: Use guard() for mutex locks
ASoC: codecs: mt6359-accdet: Use guard() for mutex locks
ASoC: codecs: pcm512x: Use guard() for mutex locks
ASoC: codecs: pcm6240: Use guard() for mutex locks
ASoC: codecs: peb2466: Use guard() for mutex locks
ASoC: codecs: rt5514-spi: Use guard() for mutex locks
ASoC: codecs: rt5645: Use guard() for mutex locks
ASoC: codecs: rt5665: Use guard() for mutex locks
ASoC: codecs: rt5668: Use guard() for mutex locks
ASoC: codecs: rt5677: Use guard() for mutex locks
ASoC: codecs: rt5682: Use guard() for mutex locks
ASoC: codecs: rt700: Use guard() for mutex locks
ASoC: codecs: rt711: Use guard() for mutex locks
ASoC: codecs: rt712: Use guard() for mutex locks
ASoC: codecs: rt721: Use guard() for mutex locks
ASoC: codecs: rt722: Use guard() for mutex locks
sound/soc/codecs/da7213.c | 37 ++---- sound/soc/codecs/da7219.c | 62 +++------- sound/soc/codecs/es8316.c | 31 +++-- sound/soc/codecs/es8326.c | 30 +++-- sound/soc/codecs/es9356.c | 29 ++--- sound/soc/codecs/fs210x.c | 89 +++++--------- sound/soc/codecs/hdac_hdmi.c | 117 +++++++++---------- sound/soc/codecs/hdmi-codec.c | 15 +-- sound/soc/codecs/idt821034.c | 144 +++++++++-------------- sound/soc/codecs/lpass-macro-common.c | 12 +- sound/soc/codecs/madera.c | 39 +++---- sound/soc/codecs/max98095.c | 35 +++--- sound/soc/codecs/mt6359-accdet.c | 13 +-- sound/soc/codecs/pcm512x.c | 19 +-- sound/soc/codecs/pcm6240.c | 25 ++-- sound/soc/codecs/peb2466.c | 16 +-- sound/soc/codecs/rt5514-spi.c | 21 ++-- sound/soc/codecs/rt5645.c | 160 +++++++++++++------------- sound/soc/codecs/rt5665.c | 15 ++- sound/soc/codecs/rt5668.c | 10 +- sound/soc/codecs/rt5677-spi.c | 36 +++--- sound/soc/codecs/rt5677.c | 75 ++++++------ sound/soc/codecs/rt5682-sdw.c | 24 ++-- sound/soc/codecs/rt5682.c | 5 +- sound/soc/codecs/rt5682s.c | 17 +-- sound/soc/codecs/rt700-sdw.c | 14 +-- sound/soc/codecs/rt711-sdca-sdw.c | 29 ++--- sound/soc/codecs/rt711-sdca.c | 5 +- sound/soc/codecs/rt711-sdw.c | 24 ++-- sound/soc/codecs/rt711.c | 50 ++++---- sound/soc/codecs/rt712-sdca-sdw.c | 30 ++--- sound/soc/codecs/rt712-sdca.c | 5 +- sound/soc/codecs/rt721-sdca-sdw.c | 29 ++--- sound/soc/codecs/rt721-sdca.c | 5 +- sound/soc/codecs/rt722-sdca-sdw.c | 29 ++--- sound/soc/codecs/rt722-sdca.c | 4 +- 36 files changed, 569 insertions(+), 731 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/27 ASoC: codecs: da7213: 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/da7213.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-)
sound/soc/codecs/da7213.c +12 -25
@@ -11,6 +11,7 @@#include <linux/acpi.h> #include <linux/of.h> #include <linux/property.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/i2c.h>
@@ -216,13 +217,10 @@ static int da7213_volsw_locked_get(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7213_priv *da7213 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7213->ctrl_lock); - ret =snd_soc_get_volsw (kcontrol, ucontrol); -mutex_unlock (&da7213->ctrl_lock); +guard (mutex)(&da7213->ctrl_lock); -return ret; +return snd_soc_get_volsw (kcontrol, ucontrol); } static int da7213_volsw_locked_put(struct snd_kcontrol *kcontrol,
@@ -230,13 +228,10 @@ static int da7213_volsw_locked_put(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7213_priv *da7213 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7213->ctrl_lock); - ret =snd_soc_put_volsw (kcontrol, ucontrol); -mutex_unlock (&da7213->ctrl_lock); +guard (mutex)(&da7213->ctrl_lock); -return ret; +return snd_soc_put_volsw (kcontrol, ucontrol); } static int da7213_enum_locked_get(struct snd_kcontrol *kcontrol,
@@ -244,13 +239,10 @@ static int da7213_enum_locked_get(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7213_priv *da7213 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7213->ctrl_lock); - ret =snd_soc_get_enum_double (kcontrol, ucontrol); -mutex_unlock (&da7213->ctrl_lock); +guard (mutex)(&da7213->ctrl_lock); -return ret; +return snd_soc_get_enum_double (kcontrol, ucontrol); } static int da7213_enum_locked_put(struct snd_kcontrol *kcontrol,
@@ -258,13 +250,10 @@ static int da7213_enum_locked_put(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7213_priv *da7213 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7213->ctrl_lock); - ret =snd_soc_put_enum_double (kcontrol, ucontrol); -mutex_unlock (&da7213->ctrl_lock); +guard (mutex)(&da7213->ctrl_lock); -return ret; +return snd_soc_put_enum_double (kcontrol, ucontrol); }/* ALC */
@@ -465,9 +454,8 @@ static int da7213_tonegen_freq_get(struct snd_kcontrol *kcontrol,__le16 val;int ret; -mutex_lock (&da7213->ctrl_lock); - ret =regmap_raw_read (da7213->regmap, reg, &val,sizeof (val)); -mutex_unlock (&da7213->ctrl_lock); +scoped_guard (mutex, &da7213->ctrl_lock) + ret = regmap_raw_read(da7213->regmap, reg, &val, sizeof(val));if (ret)return ret;
@@ -499,12 +487,11 @@ static int da7213_tonegen_freq_put(struct snd_kcontrol *kcontrol,*/ val_new =cpu_to_le16 (ucontrol->value.integer.value[0 ]); -mutex_lock (&da7213->ctrl_lock); +guard (mutex)(&da7213->ctrl_lock); ret =regmap_raw_read (da7213->regmap, reg, &val_old,sizeof (val_old));if (ret ==0 && (val_old != val_new)) ret =regmap_raw_write (da7213->regmap, reg, &val_new,sizeof (val_new)); -mutex_unlock (&da7213->ctrl_lock);if (ret <0 )return ret;
Signature · 1 line
2.43.0
PATCH v3 2/27 ASoC: codecs: da7219: 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/da7219.c | 62 ++++++++++++--------------------------- 1 file changed, 19 insertions(+), 43 deletions(-)
sound/soc/codecs/da7219.c +19 -43
@@ -8,6 +8,7 @@*/ #include <linux/acpi.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/clkdev.h> #include <linux/clk-provider.h>
@@ -256,13 +257,10 @@ static int da7219_volsw_locked_get(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7219->ctrl_lock); - ret =snd_soc_get_volsw (kcontrol, ucontrol); -mutex_unlock (&da7219->ctrl_lock); +guard (mutex)(&da7219->ctrl_lock); -return ret; +return snd_soc_get_volsw (kcontrol, ucontrol); } static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol,
@@ -270,13 +268,10 @@ static int da7219_volsw_locked_put(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7219->ctrl_lock); - ret =snd_soc_put_volsw (kcontrol, ucontrol); -mutex_unlock (&da7219->ctrl_lock); +guard (mutex)(&da7219->ctrl_lock); -return ret; +return snd_soc_put_volsw (kcontrol, ucontrol); } static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol,
@@ -284,13 +279,10 @@ static int da7219_enum_locked_get(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7219->ctrl_lock); - ret =snd_soc_get_enum_double (kcontrol, ucontrol); -mutex_unlock (&da7219->ctrl_lock); +guard (mutex)(&da7219->ctrl_lock); -return ret; +return snd_soc_get_enum_double (kcontrol, ucontrol); } static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol,
@@ -298,13 +290,10 @@ static int da7219_enum_locked_put(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7219->ctrl_lock); - ret =snd_soc_put_enum_double (kcontrol, ucontrol); -mutex_unlock (&da7219->ctrl_lock); +guard (mutex)(&da7219->ctrl_lock); -return ret; +return snd_soc_put_enum_double (kcontrol, ucontrol); }/* ALC */
@@ -422,9 +411,8 @@ static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol,__le16 val;int ret; -mutex_lock (&da7219->ctrl_lock); - ret =regmap_raw_read (da7219->regmap, reg, &val,sizeof (val)); -mutex_unlock (&da7219->ctrl_lock); +scoped_guard (mutex, &da7219->ctrl_lock) + ret = regmap_raw_read(da7219->regmap, reg, &val, sizeof(val));if (ret)return ret;
@@ -456,12 +444,11 @@ static int da7219_tonegen_freq_put(struct snd_kcontrol *kcontrol,*/ val_new =cpu_to_le16 (ucontrol->value.integer.value[0 ]); -mutex_lock (&da7219->ctrl_lock); +guard (mutex)(&da7219->ctrl_lock); ret =regmap_raw_read (da7219->regmap, reg, &val_old,sizeof (val_old));if (ret ==0 && (val_old != val_new)) ret =regmap_raw_write (da7219->regmap, reg, - &val_new,sizeof (val_new)); -mutex_unlock (&da7219->ctrl_lock); + &val_new,sizeof (val_new));if (ret <0 )return ret;
@@ -1167,15 +1154,12 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component);int ret =0 ; -mutex_lock (&da7219->pll_lock); +guard (mutex)(&da7219->pll_lock); -if ((da7219->clk_src == clk_id) && (da7219->mclk_rate == freq)) { -mutex_unlock (&da7219->pll_lock); +if (da7219->clk_src == clk_id && da7219->mclk_rate == freq)return 0 ; - } -if ((freq <2000000 ) || (freq >54000000 )) { -mutex_unlock (&da7219->pll_lock); +if (freq <2000000 || freq >54000000 ) {dev_err (codec_dai->dev,"Unsupported MCLK value %d\n" , freq);return -EINVAL ;
@@ -1193,7 +1177,6 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,break ;default :dev_err (codec_dai->dev,"Unknown clock source %d\n" , clk_id); -mutex_unlock (&da7219->pll_lock);return -EINVAL ; }
@@ -1203,17 +1186,13 @@ static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai, freq =clk_round_rate (da7219->mclk, freq); ret =clk_set_rate (da7219->mclk, freq);if (ret) { -dev_err (codec_dai->dev,"Failed to set clock rate %d\n" , - freq); -mutex_unlock (&da7219->pll_lock); +dev_err (codec_dai->dev,"Failed to set clock rate %d\n" , freq);return ret; } } da7219->mclk_rate = freq; -mutex_unlock (&da7219->pll_lock); -return 0 ; }
@@ -1296,13 +1275,10 @@ static int da7219_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, {struct snd_soc_component *component = codec_dai->component;struct da7219_priv *da7219 =snd_soc_component_get_drvdata (component); -int ret; -mutex_lock (&da7219->pll_lock); - ret =da7219_set_pll (component, source, fout); -mutex_unlock (&da7219->pll_lock); +guard (mutex)(&da7219->pll_lock); -return ret; +return da7219_set_pll (component, source, fout); }static int da7219_set_dai_fmt (struct snd_soc_dai *codec_dai,unsigned int fmt)
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 3 lines · On Thu, Jul 09, 2026 at 11:58:35AM +0700, [email protected] wrote:
bui duc phuc (27):
ASoC: codecs: da7213: Useguard()for mutex locks
ASoC: codecs: da7219: Useguard()for mutex locks
Only the first two of these seem to have come through which has rather confused things?
Hi Mark,
Sorry for the confusion.
Quoted 8 lines · On Thu, Jul 09, 2026 at 11:58:35AM +0700, [email protected] wrote:
Quoted 4 lines
bui duc phuc (27):
ASoC: codecs: da7213: Useguard()for mutex locks
ASoC: codecs: da7219: Useguard()for mutex locksOnly the first two of these seem to have come through which has rather confused things?
I've hit my email sending limit. I will send the remaining 25 parts after 24 hours
to ensure they all go through.
Best regards,
Phuc
PATCH v3 3/27 ASoC: codecs: es8316: 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/es8316.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
sound/soc/codecs/es8316.c +13 -18
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/acpi.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/i2c.h>
@@ -620,15 +621,15 @@ static irqreturn_t es8316_irq(int irq, void *data)struct snd_soc_component *comp = es8316->component;unsigned int flags; -mutex_lock (&es8316->lock); +guard (mutex)(&es8316->lock);regmap_read (es8316->regmap,ES8316_GPIO_FLAG , &flags);if (flags ==0x00 ) - goto out;/* Powered-down / reset */ +return IRQ_HANDLED ;/* Powered-down / reset */ /* Catch spurious IRQ before set_jack is called */ if (!es8316->jack) - goto out; +return IRQ_HANDLED ;if (es8316->jd_inverted) flags ^=ES8316_GPIO_FLAG_HP_NOT_INSERTED ;
@@ -681,8 +682,6 @@ static irqreturn_t es8316_irq(int irq, void *data) } } -out: -mutex_unlock (&es8316->lock);return IRQ_HANDLED ; }
@@ -699,18 +698,16 @@ static void es8316_enable_jack_detect(struct snd_soc_component *component, es8316->jd_inverted =device_property_read_bool (component->dev,"everest,jack-detect-inverted" ); -mutex_lock (&es8316->lock); + scoped_guard(mutex, &es8316->lock) { + es8316->jack = jack; - es8316->jack = jack; - -if (es8316->jack->status &SND_JACK_MICROPHONE ) -es8316_enable_micbias_for_mic_gnd_short_detect (component); - -snd_soc_component_update_bits (component,ES8316_GPIO_DEBOUNCE , -ES8316_GPIO_ENABLE_INTERRUPT , -ES8316_GPIO_ENABLE_INTERRUPT ); +if (es8316->jack->status &SND_JACK_MICROPHONE ) +es8316_enable_micbias_for_mic_gnd_short_detect (component); -mutex_unlock (&es8316->lock); +snd_soc_component_update_bits (component,ES8316_GPIO_DEBOUNCE , +ES8316_GPIO_ENABLE_INTERRUPT , +ES8316_GPIO_ENABLE_INTERRUPT ); + }/* Enable irq and sync initial jack state */ enable_irq (es8316->irq);
@@ -726,7 +723,7 @@ static void es8316_disable_jack_detect(struct snd_soc_component *component)disable_irq (es8316->irq); -mutex_lock (&es8316->lock); +guard (mutex)(&es8316->lock);snd_soc_component_update_bits (component,ES8316_GPIO_DEBOUNCE ,ES8316_GPIO_ENABLE_INTERRUPT ,0 );
@@ -737,8 +734,6 @@ static void es8316_disable_jack_detect(struct snd_soc_component *component) } es8316->jack =NULL ; - -mutex_unlock (&es8316->lock); } static int es8316_set_jack(struct snd_soc_component *component,
Signature · 1 line
2.43.0
PATCH v3 4/27 ASoC: codecs: es8326: 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/es8326.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
sound/soc/codecs/es8326.c +13 -17
@@ -6,6 +6,7 @@// Authors: David Yang <[email protected]> // +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/i2c.h> #include <linux/interrupt.h>
@@ -790,7 +791,7 @@ static void es8326_jack_button_handler(struct work_struct *work)if (!(es8326->jack->status &SND_JACK_HEADSET ))/* Jack unplugged */ return ; -mutex_lock (&es8326->lock); +guard (mutex)(&es8326->lock); iface =snd_soc_component_read (comp,ES8326_HPDET_STA );switch (iface) {case 0x93 :
@@ -845,7 +846,6 @@ static void es8326_jack_button_handler(struct work_struct *work) }es8326_disable_micbias (es8326->component); } -mutex_unlock (&es8326->lock); }static void es8326_jack_detect_handler (struct work_struct *work)
@@ -855,7 +855,7 @@ static void es8326_jack_detect_handler(struct work_struct *work)struct snd_soc_component *comp = es8326->component;unsigned int iface; -mutex_lock (&es8326->lock); +guard (mutex)(&es8326->lock); iface =snd_soc_component_read (comp,ES8326_HPDET_STA );dev_dbg (comp->dev,"gpio flag %#04x" , iface);
@@ -873,7 +873,7 @@ static void es8326_jack_detect_handler(struct work_struct *work)regmap_update_bits (es8326->regmap,ES8326_HPDET_TYPE ,ES8326_HP_DET_JACK_POL , (es8326->jd_inverted ? ~es8326->jack_pol : es8326->jack_pol)); - goto exit; +return ; }if ((iface &ES8326_HPINSERT_FLAG ) ==0 ) {
@@ -930,7 +930,7 @@ static void es8326_jack_detect_handler(struct work_struct *work)queue_delayed_work (system_dfl_wq, &es8326->jack_detect_work,msecs_to_jiffies (400 )); es8326->hp =1 ; - goto exit; +return ; }if (es8326->jack->status &SND_JACK_HEADSET ) {/* detect button */
@@ -939,7 +939,7 @@ static void es8326_jack_detect_handler(struct work_struct *work) (ES8326_INT_SRC_PIN9 | ES8326_INT_SRC_BUTTON));es8326_enable_micbias (es8326->component);queue_delayed_work (system_dfl_wq, &es8326->button_press_work,10 ); - goto exit; +return ; }if ((iface &ES8326_HPBUTTON_FLAG ) ==0x01 ) {dev_dbg (comp->dev,"Headphone detected\n" );
@@ -958,8 +958,6 @@ static void es8326_jack_detect_handler(struct work_struct *work)usleep_range (10000 ,15000 ); } } -exit: -mutex_unlock (&es8326->lock); }static irqreturn_t es8326_irq (int irq,void *dev_id)
@@ -1200,13 +1198,12 @@ static void es8326_enable_jack_detect(struct snd_soc_component *component, {struct es8326_priv *es8326 =snd_soc_component_get_drvdata (component); -mutex_lock (&es8326->lock); -if (es8326->jd_inverted) -snd_soc_component_update_bits (component,ES8326_HPDET_TYPE , -ES8326_HP_DET_JACK_POL , ~es8326->jack_pol); - es8326->jack = jack; - -mutex_unlock (&es8326->lock); + scoped_guard(mutex, &es8326->lock) { +if (es8326->jd_inverted) +snd_soc_component_update_bits (component,ES8326_HPDET_TYPE , +ES8326_HP_DET_JACK_POL , ~es8326->jack_pol); + es8326->jack = jack; + }es8326_irq (es8326->irq, es8326); }
@@ -1219,13 +1216,12 @@ static void es8326_disable_jack_detect(struct snd_soc_component *component)return ;/* Already disabled (or never enabled) */ cancel_delayed_work_sync (&es8326->jack_detect_work); -mutex_lock (&es8326->lock); +guard (mutex)(&es8326->lock);if (es8326->jack->status &SND_JACK_MICROPHONE ) {es8326_disable_micbias (component);snd_soc_jack_report (es8326->jack,0 ,SND_JACK_HEADSET ); } es8326->jack =NULL ; -mutex_unlock (&es8326->lock); } static int es8326_set_jack(struct snd_soc_component *component,
Signature · 1 line
2.43.0
PATCH v3 5/27 ASoC: codecs: es9356: 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/es9356.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
sound/soc/codecs/es9356.c +16 -13
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/module.h> #include <linux/soundwire/sdw.h>
@@ -500,16 +501,19 @@ static int es9356_power_state(struct snd_soc_dai *dai, unsigned char ps, unsigne }/* power state changes are not independent across functions */ -mutex_lock (&es9356->pde_lock); - ret =es9356_pde_transition_delay (es9356, func, pde_entity, ps?ps0:ps3); -if (ret) { -regmap_write (es9356->regmap, -SDW_SDCA_CTL (func, pde_entity,ES9356_SDCA_CTL_REQ_POWER_STATE ,0 ), ps?ps3:ps0); -es9356_pde_transition_delay (es9356, func, pde_entity, ps?ps3:ps0); - }else -dev_dbg (component->dev,"%s PDE is already %d\n" , __func__, ps?ps0:ps3); - -mutex_unlock (&es9356->pde_lock); + scoped_guard(mutex, &es9356->pde_lock) { + ret =es9356_pde_transition_delay (es9356, func, pde_entity, ps ? ps0 : ps3); +if (ret) { +regmap_write (es9356->regmap, +SDW_SDCA_CTL (func, pde_entity, +ES9356_SDCA_CTL_REQ_POWER_STATE ,0 ), + ps ? ps3 : ps0); +es9356_pde_transition_delay (es9356, func, pde_entity, ps ? ps3 : ps0); + }else { +dev_dbg (component->dev,"%s PDE is already %d\n" , __func__, + ps ? ps0 : ps3); + } + }if (rate) regmap_write(es9356->regmap,
@@ -1091,9 +1095,8 @@ static int es9356_sdca_dev_system_suspend(struct device *dev) {struct es9356_sdw_priv *es9356 =dev_get_drvdata (dev); -mutex_lock (&es9356->disable_irq_lock); - es9356->disable_irq = true; -mutex_unlock (&es9356->disable_irq_lock); +scoped_guard (mutex, &es9356->disable_irq_lock) + es9356->disable_irq = true;return es9356_sdca_dev_suspend (dev); }
Signature · 1 line
2.43.0
PATCH v3 6/27 ASoC: codecs: fs210x: 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/fs210x.c | 89 ++++++++++++++------------------------- 1 file changed, 31 insertions(+), 58 deletions(-)
sound/soc/codecs/fs210x.c +31 -58
@@ -4,6 +4,7 @@// // Copyright (C) 2016-2025 Shanghai FourSemi Semiconductor Co.,Ltd. +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/i2c.h>
@@ -770,9 +771,8 @@ static int fs210x_dai_hw_params(struct snd_pcm_substream *substream,if (fs210x->devid ==FS2105S_DEVICE_ID && fs210x->srate ==16000 )return -EOPNOTSUPP ; -mutex_lock (&fs210x->lock); - ret =fs210x_set_hw_params (fs210x); -mutex_unlock (&fs210x->lock); +scoped_guard (mutex, &fs210x->lock) + ret = fs210x_set_hw_params(fs210x);if (ret)dev_err (fs210x->dev,"Failed to set hw params: %d\n" , ret);
@@ -789,15 +789,11 @@ static int fs210x_dai_mute(struct snd_soc_dai *dai, int mute, int stream) fs210x =snd_soc_component_get_drvdata (dai->component); -mutex_lock (&fs210x->lock); - -if (!fs210x->is_inited || fs210x->is_suspended) { -mutex_unlock (&fs210x->lock); -return 0 ; + scoped_guard(mutex, &fs210x->lock) { +if (!fs210x->is_inited || fs210x->is_suspended) +return 0 ; } -mutex_unlock (&fs210x->lock); -if (mute) {cancel_delayed_work_sync (&fs210x->fault_check_work);cancel_delayed_work_sync (&fs210x->start_work);
@@ -816,15 +812,11 @@ static int fs210x_dai_trigger(struct snd_pcm_substream *substream, fs210x =snd_soc_component_get_drvdata (dai->component); -mutex_lock (&fs210x->lock); - -if (!fs210x->is_inited || fs210x->is_suspended || fs210x->is_playing) { -mutex_unlock (&fs210x->lock); -return 0 ; + scoped_guard(mutex, &fs210x->lock) { +if (!fs210x->is_inited || fs210x->is_suspended || fs210x->is_playing) +return 0 ; } -mutex_unlock (&fs210x->lock); -switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -852,13 +844,11 @@ static void fs210x_start_work(struct work_struct *work) fs210x = container_of(work, struct fs210x_priv, start_work.work); -mutex_lock (&fs210x->lock); +guard (mutex)(&fs210x->lock); ret =fs210x_dev_play (fs210x);if (ret)dev_err (fs210x->dev,"Failed to start playing: %d\n" , ret); - -mutex_unlock (&fs210x->lock); }static void fs210x_fault_check_work (struct work_struct *work)
@@ -869,15 +859,13 @@ static void fs210x_fault_check_work(struct work_struct *work) fs210x = container_of(work, struct fs210x_priv, fault_check_work.work); -mutex_lock (&fs210x->lock); + scoped_guard(mutex, &fs210x->lock) { +if (!fs210x->is_inited || fs210x->is_suspended || !fs210x->is_playing) +return ; -if (!fs210x->is_inited || fs210x->is_suspended || !fs210x->is_playing) { -mutex_unlock (&fs210x->lock); -return ; + ret =fs210x_reg_read (fs210x,FS210X_05H_ANASTAT , &status); } - ret =fs210x_reg_read (fs210x,FS210X_05H_ANASTAT , &status); -mutex_unlock (&fs210x->lock);if (ret)return ;
@@ -990,7 +978,7 @@ static int fs210x_effect_scene_get(struct snd_kcontrol *kcontrol,if (fs210x->scene_id <1 )return -EINVAL ; -mutex_lock (&fs210x->lock); +guard (mutex)(&fs210x->lock);/* * FS210x has scene(s) as below: * init scene: id = 0
@@ -999,7 +987,6 @@ static int fs210x_effect_scene_get(struct snd_kcontrol *kcontrol,*/ index = fs210x->scene_id -1 ; ucontrol->value.integer.value[0 ] = index; -mutex_unlock (&fs210x->lock);return 0 ; }
@@ -1018,7 +1005,7 @@ static int fs210x_effect_scene_put(struct snd_kcontrol *kcontrol,return -EINVAL ; } -mutex_lock (&fs210x->lock); +guard (mutex)(&fs210x->lock);/* * FS210x has scene(s) as below:
@@ -1028,17 +1015,14 @@ static int fs210x_effect_scene_put(struct snd_kcontrol *kcontrol,*/ scene_id = ucontrol->value.integer.value[0 ] +1 ; scene_count = fs210x->amp_lib.scene_count -1 ;/* Skip init scene */ -if (scene_id <1 || scene_id > scene_count) { -mutex_unlock (&fs210x->lock); +if (scene_id <1 || scene_id > scene_count)return -ERANGE ; - }if (scene_id != fs210x->scene_id) is_changed = true;if (fs210x->is_suspended) { fs210x->scene_id = scene_id; -mutex_unlock (&fs210x->lock);return is_changed; }
@@ -1046,8 +1030,6 @@ static int fs210x_effect_scene_put(struct snd_kcontrol *kcontrol,if (ret)dev_err (fs210x->dev,"Failed to set scene: %d\n" , ret); -mutex_unlock (&fs210x->lock); -if (!ret && is_changed)return 1 ;
@@ -1061,12 +1043,10 @@ static int fs210x_playback_event(struct snd_soc_dapm_widget *w,struct fs210x_priv *fs210x =snd_soc_component_get_drvdata (cmpnt);int ret =0 ; -mutex_lock (&fs210x->lock); +guard (mutex)(&fs210x->lock); -if (fs210x->is_suspended) { -mutex_unlock (&fs210x->lock); +if (fs210x->is_suspended)return 0 ; - }switch (event) {case SND_SOC_DAPM_PRE_PMU :
@@ -1087,8 +1067,6 @@ static int fs210x_playback_event(struct snd_soc_dapm_widget *w,break ; } -mutex_unlock (&fs210x->lock); -return ret; }
@@ -1219,11 +1197,9 @@ static int fs210x_probe(struct snd_soc_component *cmpnt)if (ret)return ret; -mutex_lock (&fs210x->lock); - ret =fs210x_init_chip (fs210x); -mutex_unlock (&fs210x->lock); +guard (mutex)(&fs210x->lock); -return ret; +return fs210x_init_chip (fs210x); }static void fs210x_remove (struct snd_soc_component *cmpnt)
@@ -1250,15 +1226,15 @@ static int fs210x_suspend(struct snd_soc_component *cmpnt)regcache_cache_only (fs210x->regmap, true); -mutex_lock (&fs210x->lock); - fs210x->cur_scene =NULL ; - fs210x->is_inited = false; - fs210x->is_playing = false; - fs210x->is_suspended = true; + scoped_guard(mutex, &fs210x->lock) { + fs210x->cur_scene =NULL ; + fs210x->is_inited = false; + fs210x->is_playing = false; + fs210x->is_suspended = true; -gpiod_set_value_cansleep (fs210x->gpio_sdz,1 );/* Active */ -fsleep (30000 );/* >= 30ms */ -mutex_unlock (&fs210x->lock); +gpiod_set_value_cansleep (fs210x->gpio_sdz,1 );/* Active */ +fsleep (30000 );/* >= 30ms */ + }cancel_delayed_work_sync (&fs210x->start_work);cancel_delayed_work_sync (&fs210x->fault_check_work);
@@ -1287,14 +1263,11 @@ static int fs210x_resume(struct snd_soc_component *cmpnt) return ret; } -mutex_lock (&fs210x->lock); +guard (mutex)(&fs210x->lock); fs210x->is_suspended = false; - ret =fs210x_init_chip (fs210x); -mutex_unlock (&fs210x->lock); - -return ret; +return fs210x_init_chip (fs210x); }#else #define fs210x_suspend NULL
Signature · 1 line
2.43.0
PATCH v3 7/27 ASoC: codecs: hdac_hdmi: 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/hdac_hdmi.c | 117 +++++++++++++++++------------------ 1 file changed, 57 insertions(+), 60 deletions(-)
sound/soc/codecs/hdac_hdmi.c +57 -60
@@ -10,6 +10,7 @@* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include <linux/cleanup.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/module.h>
@@ -537,10 +538,11 @@ static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(continue ;list_for_each_entry (port, &pcm->port_list, head) { -mutex_lock (&pcm->lock); - ret =hdac_hdmi_query_port_connlist (hdev, - port->pin, port); -mutex_unlock (&pcm->lock); + scoped_guard(mutex, &pcm->lock) { + ret =hdac_hdmi_query_port_connlist (hdev, + port->pin, + port); + }if (ret <0 )continue ;
@@ -640,11 +642,11 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream, pcm =hdac_hdmi_get_pcm_from_cvt (hdmi, dai_map->cvt);if (pcm) { -mutex_lock (&pcm->lock); - pcm->chmap_set = false; -memset (pcm->chmap,0 ,sizeof (pcm->chmap)); - pcm->channels =0 ; -mutex_unlock (&pcm->lock); + scoped_guard(mutex, &pcm->lock) { + pcm->chmap_set = false; +memset (pcm->chmap,0 ,sizeof (pcm->chmap)); + pcm->channels =0 ; + } }if (dai_map->port)
@@ -922,7 +924,7 @@ static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,if (port ==NULL )return -EINVAL ; -mutex_lock (&hdmi->pin_mutex); +guard (mutex)(&hdmi->pin_mutex);list_for_each_entry (pcm, &hdmi->pcm_list, head) {if (list_empty (&pcm->port_list))continue ;
@@ -945,12 +947,10 @@ static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,list_add_tail (&port->head, &pcm->port_list);if (port->eld.monitor_present && port->eld.eld_valid) {hdac_hdmi_jack_report_sync (pcm, port, true); -mutex_unlock (&hdmi->pin_mutex);return ret; } } } -mutex_unlock (&hdmi->pin_mutex);return ret; }
@@ -1274,67 +1274,65 @@ static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,* In case of non MST pin, get_eld info API expectes port * to be -1. */ -mutex_lock (&hdmi->pin_mutex); - port->eld.monitor_present = false; + scoped_guard(mutex, &hdmi->pin_mutex) { + port->eld.monitor_present = false; -if (pin->mst_capable) - port_id = port->id; +if (pin->mst_capable) + port_id = port->id; - size =snd_hdac_acomp_get_eld (hdev, pin->nid, port_id, - &port->eld.monitor_present, - port->eld.eld_buffer, -ELD_MAX_SIZE ); + size =snd_hdac_acomp_get_eld (hdev, pin->nid, port_id, + &port->eld.monitor_present, + port->eld.eld_buffer, +ELD_MAX_SIZE ); -if (size >0 ) { - size =min (size,ELD_MAX_SIZE ); -if (hdac_hdmi_parse_eld (hdev, port) <0 ) - size = -EINVAL ; - } - - eld_valid = port->eld.eld_valid; +if (size >0 ) { + size =min (size,ELD_MAX_SIZE ); +if (hdac_hdmi_parse_eld (hdev, port) <0 ) + size = -EINVAL ; + } -if (size >0 ) { - port->eld.eld_valid = true; - port->eld.eld_size = size; - }else { - port->eld.eld_valid = false; - port->eld.eld_size =0 ; - } + eld_valid = port->eld.eld_valid; - eld_changed = (eld_valid != port->eld.eld_valid); +if (size >0 ) { + port->eld.eld_valid = true; + port->eld.eld_size = size; + }else { + port->eld.eld_valid = false; + port->eld.eld_size =0 ; + } - pcm =hdac_hdmi_get_pcm (hdev, port); + eld_changed = (eld_valid != port->eld.eld_valid); -if (!port->eld.monitor_present || !port->eld.eld_valid) { + pcm =hdac_hdmi_get_pcm (hdev, port); -dev_dbg (&hdev->dev,"%s: disconnect for pin:port %d:%d\n" , - __func__, pin->nid, port->id); +if (!port->eld.monitor_present || !port->eld.eld_valid) { -/* -* PCMs are not registered during device probe, so don't -* report jack here. It will be done in usermode mux -* control select. -*/ -if (pcm) { -hdac_hdmi_jack_report (pcm, port, false); -schedule_work (&port->dapm_work); - } +dev_dbg (&hdev->dev,"%s: disconnect for pin:port %d:%d\n" , + __func__, pin->nid, port->id); -mutex_unlock (&hdmi->pin_mutex); -return ; - } +/* +* PCMs are not registered during device probe, so don't +* report jack here. It will be done in usermode mux +* control select. +*/ +if (pcm) { +hdac_hdmi_jack_report (pcm, port, false); +schedule_work (&port->dapm_work); + } -if (port->eld.monitor_present && port->eld.eld_valid) { -if (pcm) { -hdac_hdmi_jack_report (pcm, port, true); -schedule_work (&port->dapm_work); +return ; } -print_hex_dump_debug ("ELD: " ,DUMP_PREFIX_OFFSET ,16 ,1 , - port->eld.eld_buffer, port->eld.eld_size, false); +if (port->eld.monitor_present && port->eld.eld_valid) { +if (pcm) { +hdac_hdmi_jack_report (pcm, port, true); +schedule_work (&port->dapm_work); + } +print_hex_dump_debug ("ELD: " ,DUMP_PREFIX_OFFSET ,16 ,1 , + port->eld.eld_buffer, port->eld.eld_size, false); + } } -mutex_unlock (&hdmi->pin_mutex);if (eld_changed && pcm) snd_ctl_notify(hdmi->card,
@@ -1795,13 +1793,12 @@ static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,if (list_empty (&pcm->port_list))return ; -mutex_lock (&pcm->lock); +guard (mutex)(&pcm->lock); pcm->chmap_set = true;memcpy (pcm->chmap, chmap,ARRAY_SIZE (pcm->chmap));list_for_each_entry (port, &pcm->port_list, head)if (prepared)hdac_hdmi_setup_audio_infoframe (hdev, pcm, port); -mutex_unlock (&pcm->lock); }static bool is_hdac_hdmi_pcm_attached (struct hdac_device *hdev,int pcm_idx)
Signature · 1 line
2.43.0
PATCH v3 8/27 ASoC: codecs: hdmi-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/hdmi-codec.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
sound/soc/codecs/hdmi-codec.c +6 -9
@@ -4,6 +4,7 @@* Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/ * Author: Jyri Sarha <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/string.h> #include <sound/core.h>
@@ -452,31 +453,30 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,if (!((has_playback && tx) || (has_capture && !tx)))return 0 ; -mutex_lock (&hcp->lock); +guard (mutex)(&hcp->lock);if (hcp->busy) {dev_err (dai->dev,"Only one simultaneous stream supported!\n" ); -mutex_unlock (&hcp->lock);return -EINVAL ; }if (hcp->hcd.ops->audio_startup) { ret = hcp->hcd.ops->audio_startup (dai->dev->parent, hcp->hcd.data);if (ret) - goto err; +return ret; }if (tx && hcp->hcd.ops->get_eld) { ret = hcp->hcd.ops->get_eld (dai->dev->parent, hcp->hcd.data, hcp->eld,sizeof (hcp->eld));if (ret) - goto err; +return ret;snd_parse_eld (dai->dev, &hcp->eld_parsed, hcp->eld,sizeof (hcp->eld)); ret =snd_pcm_hw_constraint_eld (substream->runtime, hcp->eld);if (ret) - goto err; +return ret;/* Select chmap supported */ hdmi_codec_eld_chmap (hcp);
@@ -484,8 +484,6 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream, hcp->busy = true; -err: -mutex_unlock (&hcp->lock);return ret; }
@@ -503,9 +501,8 @@ static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, hcp->chmap_idx =HDMI_CODEC_CHMAP_IDX_UNKNOWN ; hcp->hcd.ops->audio_shutdown (dai->dev->parent, hcp->hcd.data); -mutex_lock (&hcp->lock); +guard (mutex)(&hcp->lock); hcp->busy = false; -mutex_unlock (&hcp->lock); } static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai,
Signature · 1 line
2.43.0
PATCH v3 9/27 ASoC: codecs: idt821034: 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:
- Remove temporary variables and return directly
from the functions.
sound/soc/codecs/idt821034.c | 144 ++++++++++++++--------------------- 1 file changed, 57 insertions(+), 87 deletions(-)
sound/soc/codecs/idt821034.c +57 -87
@@ -7,6 +7,7 @@// Author: Herve Codina <[email protected]> #include <linux/bitrev.h> +#include <linux/cleanup.h> #include <linux/gpio/driver.h> #include <linux/module.h> #include <linux/slab.h>
@@ -413,12 +414,12 @@ static int idt821034_kctrl_gain_get(struct snd_kcontrol *kcontrol, ch =IDT821034_ID_GET_CHAN (mc->reg); -mutex_lock (&idt821034->mutex); -if (IDT821034_ID_IS_OUT (mc->reg)) - val = idt821034->amps.ch[ch].amp_out.gain; -else - val = idt821034->amps.ch[ch].amp_in.gain; -mutex_unlock (&idt821034->mutex); + scoped_guard(mutex, &idt821034->mutex) { +if (IDT821034_ID_IS_OUT (mc->reg)) + val = idt821034->amps.ch[ch].amp_out.gain; +else + val = idt821034->amps.ch[ch].amp_in.gain; + } ucontrol->value.integer.value[0 ] = val & mask;if (invert)
@@ -456,7 +457,7 @@ static int idt821034_kctrl_gain_put(struct snd_kcontrol *kcontrol, ch =IDT821034_ID_GET_CHAN (mc->reg); -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex);if (IDT821034_ID_IS_OUT (mc->reg)) { amp = &idt821034->amps.ch[ch].amp_out;
@@ -466,22 +467,18 @@ static int idt821034_kctrl_gain_put(struct snd_kcontrol *kcontrol, gain_type =IDT821034_GAIN_TX ; } -if (amp->gain == val) { - ret =0 ; - goto end; - } +if (amp->gain == val) +return 0 ;if (!amp->is_muted) { ret =idt821034_set_gain_channel (idt821034, ch, gain_type, val);if (ret) - goto end; +return ret; } amp->gain = val; - ret =1 ;/* The value changed */ -end: -mutex_unlock (&idt821034->mutex); -return ret; + +return 1 ; } static int idt821034_kctrl_mute_get(struct snd_kcontrol *kcontrol,
@@ -495,11 +492,11 @@ static int idt821034_kctrl_mute_get(struct snd_kcontrol *kcontrol, ch =IDT821034_ID_GET_CHAN (id); -mutex_lock (&idt821034->mutex); - is_muted =IDT821034_ID_IS_OUT (id) ? - idt821034->amps.ch[ch].amp_out.is_muted : - idt821034->amps.ch[ch].amp_in.is_muted; -mutex_unlock (&idt821034->mutex); + scoped_guard(mutex, &idt821034->mutex) { + is_muted =IDT821034_ID_IS_OUT (id) ? + idt821034->amps.ch[ch].amp_out.is_muted : + idt821034->amps.ch[ch].amp_in.is_muted; + } ucontrol->value.integer.value[0 ] = !is_muted;
@@ -521,7 +518,7 @@ static int idt821034_kctrl_mute_put(struct snd_kcontrol *kcontrol, ch =IDT821034_ID_GET_CHAN (id); is_mute = !ucontrol->value.integer.value[0 ]; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex);if (IDT821034_ID_IS_OUT (id)) { amp = &idt821034->amps.ch[ch].amp_out;
@@ -531,21 +528,17 @@ static int idt821034_kctrl_mute_put(struct snd_kcontrol *kcontrol, gain_type =IDT821034_GAIN_TX ; } -if (amp->is_muted == is_mute) { - ret =0 ; - goto end; - } +if (amp->is_muted == is_mute) +return 0 ; ret =idt821034_set_gain_channel (idt821034, ch, gain_type, is_mute ?0 : amp->gain);if (ret) - goto end; +return ret; amp->is_muted = is_mute; - ret =1 ;/* The value changed */ -end: -mutex_unlock (&idt821034->mutex); -return ret; + +return 1 ; } static const DECLARE_TLV_DB_LINEAR(idt821034_gain_in, -300, 1300);
@@ -623,24 +616,20 @@ static int idt821034_power_event(struct snd_soc_dapm_widget *w,struct idt821034 *idt821034 =snd_soc_component_get_drvdata (component);unsigned int id = w->shift;u8 power, mask; -int ret;u8 ch; ch =IDT821034_ID_GET_CHAN (id); mask =IDT821034_ID_IS_OUT (id) ?IDT821034_CONF_PWRUP_RX :IDT821034_CONF_PWRUP_TX ; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); power =idt821034_get_channel_power (idt821034, ch);if (SND_SOC_DAPM_EVENT_ON (event)) power |= mask;else power &= ~mask; - ret =idt821034_set_channel_power (idt821034, ch, power); - -mutex_unlock (&idt821034->mutex); -return ret; +return idt821034_set_channel_power (idt821034, ch, power); }static const struct snd_soc_dapm_widget idt821034_dapm_widgets[] = {
@@ -717,9 +706,9 @@ static int idt821034_dai_set_tdm_slot(struct snd_soc_dai *dai, ch =0 ;while (mask && ch <IDT821034_NB_CHANNEL ) {if (mask &0x1 ) { -mutex_lock (&idt821034->mutex); - ret =idt821034_set_channel_ts (idt821034, ch,IDT821034_CH_RX , slot); -mutex_unlock (&idt821034->mutex); +scoped_guard (mutex, &idt821034->mutex) + ret = idt821034_set_channel_ts(idt821034, ch, +IDT821034_CH_RX , slot);if (ret) {dev_err (dai->dev,"ch%u set tx tdm slot failed (%d)\n" , ch, ret);
@@ -742,9 +731,9 @@ static int idt821034_dai_set_tdm_slot(struct snd_soc_dai *dai, ch =0 ;while (mask && ch <IDT821034_NB_CHANNEL ) {if (mask &0x1 ) { -mutex_lock (&idt821034->mutex); - ret =idt821034_set_channel_ts (idt821034, ch,IDT821034_CH_TX , slot); -mutex_unlock (&idt821034->mutex); +scoped_guard (mutex, &idt821034->mutex) + ret = idt821034_set_channel_ts(idt821034, ch, +IDT821034_CH_TX , slot);if (ret) {dev_err (dai->dev,"ch%u set rx tdm slot failed (%d)\n" , ch, ret);
@@ -769,9 +758,8 @@ static int idt821034_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {struct idt821034 *idt821034 =snd_soc_component_get_drvdata (dai->component);u8 conf; -int ret; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); conf =idt821034_get_codec_conf (idt821034);
@@ -785,13 +773,10 @@ static int idt821034_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)default :dev_err (dai->dev,"Unsupported DAI format 0x%x\n" , fmt &SND_SOC_DAIFMT_FORMAT_MASK ); - ret = -EINVAL ; - goto end; +return -EINVAL ; } - ret =idt821034_set_codec_conf (idt821034, conf); -end: -mutex_unlock (&idt821034->mutex); -return ret; + +return idt821034_set_codec_conf (idt821034, conf); } static int idt821034_dai_hw_params(struct snd_pcm_substream *substream,
@@ -800,9 +785,8 @@ static int idt821034_dai_hw_params(struct snd_pcm_substream *substream, {struct idt821034 *idt821034 =snd_soc_component_get_drvdata (dai->component);u8 conf; -int ret; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); conf =idt821034_get_codec_conf (idt821034);
@@ -816,13 +800,10 @@ static int idt821034_dai_hw_params(struct snd_pcm_substream *substream,default :dev_err (dai->dev,"Unsupported PCM format 0x%x\n" ,params_format (params)); - ret = -EINVAL ; - goto end; +return -EINVAL ; } - ret =idt821034_set_codec_conf (idt821034, conf); -end: -mutex_unlock (&idt821034->mutex); -return ret; + +return idt821034_set_codec_conf (idt821034, conf); }static const unsigned int idt821034_sample_bits[] = {8 };
@@ -897,11 +878,11 @@ static int idt821034_reset_audio(struct idt821034 *idt821034)int ret;u8 i; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); ret =idt821034_set_codec_conf (idt821034,0 );if (ret) - goto end; +return ret;for (i =0 ; i <IDT821034_NB_CHANNEL ; i++) { idt821034->amps.ch[i].amp_out.gain =IDT821034_GAIN_OUT_INIT_RAW ;
@@ -909,24 +890,21 @@ static int idt821034_reset_audio(struct idt821034 *idt821034) ret =idt821034_set_gain_channel (idt821034, i,IDT821034_GAIN_RX , idt821034->amps.ch[i].amp_out.gain);if (ret) - goto end; +return ret; idt821034->amps.ch[i].amp_in.gain =IDT821034_GAIN_IN_INIT_RAW ; idt821034->amps.ch[i].amp_in.is_muted = false; ret =idt821034_set_gain_channel (idt821034, i,IDT821034_GAIN_TX , idt821034->amps.ch[i].amp_in.gain);if (ret) - goto end; +return ret; ret =idt821034_set_channel_power (idt821034, i,0 );if (ret) - goto end; +return ret; } - ret =0 ; -end: -mutex_unlock (&idt821034->mutex); -return ret; +return 0 ; }static int idt821034_component_probe (struct snd_soc_component *component)
@@ -965,7 +943,7 @@ static int idt821034_chip_gpio_set(struct gpio_chip *c, unsigned int offset,u8 slic_raw;int ret; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); slic_raw =idt821034_get_written_slic_raw (idt821034, ch);if (val)
@@ -974,8 +952,6 @@ static int idt821034_chip_gpio_set(struct gpio_chip *c, unsigned int offset, slic_raw &= ~mask; ret =idt821034_write_slic_raw (idt821034, ch, slic_raw); -mutex_unlock (&idt821034->mutex); -if (ret)dev_err (&idt821034->spi->dev,"set gpio %d (%u, 0x%x) failed (%d)\n" , offset, ch, mask, ret);
@@ -991,9 +967,8 @@ static int idt821034_chip_gpio_get(struct gpio_chip *c, unsigned int offset)u8 slic_raw;int ret; -mutex_lock (&idt821034->mutex); - ret =idt821034_read_slic_raw (idt821034, ch, &slic_raw); -mutex_unlock (&idt821034->mutex); +scoped_guard (mutex, &idt821034->mutex) + ret = idt821034_read_slic_raw(idt821034, ch, &slic_raw);if (ret) {dev_err (&idt821034->spi->dev,"get gpio %d (%u, 0x%x) failed (%d)\n" , offset, ch, mask, ret);
@@ -1015,9 +990,8 @@ static int idt821034_chip_get_direction(struct gpio_chip *c, unsigned int offsetstruct idt821034 *idt821034 =gpiochip_get_data (c);u8 slic_dir; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); slic_dir =idt821034_get_slic_conf (idt821034, ch); -mutex_unlock (&idt821034->mutex);return slic_dir & mask ?GPIO_LINE_DIRECTION_IN :GPIO_LINE_DIRECTION_OUT ; }
@@ -1034,7 +1008,7 @@ static int idt821034_chip_direction_input(struct gpio_chip *c, unsigned int offsif (mask & ~(IDT821034_SLIC_IO1_IN |IDT821034_SLIC_IO0_IN ))return -EPERM ; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); slic_conf =idt821034_get_slic_conf (idt821034, ch) | mask;
@@ -1044,7 +1018,6 @@ static int idt821034_chip_direction_input(struct gpio_chip *c, unsigned int offs offset, ch, mask, ret); } -mutex_unlock (&idt821034->mutex);return ret; }
@@ -1060,7 +1033,7 @@ static int idt821034_chip_direction_output(struct gpio_chip *c, unsigned int offif (ret)return ret; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex); slic_conf =idt821034_get_slic_conf (idt821034, ch) & ~mask;
@@ -1070,7 +1043,6 @@ static int idt821034_chip_direction_output(struct gpio_chip *c, unsigned int off offset, ch, mask, ret); } -mutex_unlock (&idt821034->mutex);return ret; }
@@ -1079,24 +1051,22 @@ static int idt821034_reset_gpio(struct idt821034 *idt821034)int ret;u8 i; -mutex_lock (&idt821034->mutex); +guard (mutex)(&idt821034->mutex);/* IO0 and IO1 as input for all channels and output IO set to 0 */ for (i =0 ; i <IDT821034_NB_CHANNEL ; i++) { ret =idt821034_set_slic_conf (idt821034, i,IDT821034_SLIC_IO1_IN |IDT821034_SLIC_IO0_IN );if (ret) - goto end; +return ret; ret =idt821034_write_slic_raw (idt821034, i,0 );if (ret) - goto end; +return ret; } - ret =0 ; -end: -mutex_unlock (&idt821034->mutex); -return ret; + +return 0 ; }static int idt821034_gpio_init (struct idt821034 *idt821034)
Signature · 1 line
2.43.0
PATCH v3 10/27 ASoC: codecs: lpass-macro: 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/lpass-macro-common.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
sound/soc/codecs/lpass-macro-common.c +4 -8
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2022, The Linux Foundation. All rights reserved. +#include <linux/cleanup.h> #include <linux/export.h> #include <linux/module.h> #include <linux/init.h>
@@ -71,21 +72,16 @@ EXPORT_SYMBOL_GPL(lpass_macro_pds_exit);void lpass_macro_set_codec_version (enum lpass_codec_version version) { -mutex_lock (&lpass_codec_mutex); +guard (mutex)(&lpass_codec_mutex); lpass_codec_version = version; -mutex_unlock (&lpass_codec_mutex); }EXPORT_SYMBOL_GPL (lpass_macro_set_codec_version);enum lpass_codec_version lpass_macro_get_codec_version (void ) { -enum lpass_codec_version ver; +guard (mutex)(&lpass_codec_mutex); -mutex_lock (&lpass_codec_mutex); - ver = lpass_codec_version; -mutex_unlock (&lpass_codec_mutex); - -return ver; +return lpass_codec_version; }EXPORT_SYMBOL_GPL (lpass_macro_get_codec_version);
Signature · 1 line
2.43.0
PATCH v3 11/27 ASoC: codecs: madera: 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:
- Add Reviewed-by tags from Charles
- Remove the temporary ret variable and return directly in madera_adsp_rate_put().
sound/soc/codecs/madera.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-)
sound/soc/codecs/madera.c +13 -26
@@ -6,6 +6,7 @@// Cirrus Logic International Semiconductor Ltd. // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/gcd.h> #include <linux/module.h>
@@ -513,7 +514,7 @@ int madera_domain_clk_ev(struct snd_soc_dapm_widget *w,* We can't rely on the DAPM mutex for locking because we need a lock * that can safely be called in hw_params */ -mutex_lock (&priv->rate_lock); +guard (mutex)(&priv->rate_lock);switch (event) {case SND_SOC_DAPM_PRE_PMU :
@@ -532,8 +533,6 @@ int madera_domain_clk_ev(struct snd_soc_dapm_widget *w,madera_debug_dump_domain_groups (priv); -mutex_unlock (&priv->rate_lock); -return 0 ; }EXPORT_SYMBOL_GPL (madera_domain_clk_ev);
@@ -875,9 +874,8 @@ static int madera_adsp_rate_get(struct snd_kcontrol *kcontrol,const int adsp_num = e->shift_l;int item; -mutex_lock (&priv->rate_lock); - cached_rate = priv->adsp_rate_cache[adsp_num]; -mutex_unlock (&priv->rate_lock); + scoped_guard(mutex, &priv->rate_lock) + cached_rate = priv->adsp_rate_cache[adsp_num]; item =snd_soc_enum_val_to_item (e, cached_rate); ucontrol->value.enumerated.item[0 ] = item;
@@ -893,7 +891,6 @@ static int madera_adsp_rate_put(struct snd_kcontrol *kcontrol,struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;const int adsp_num = e->shift_l;const unsigned int item = ucontrol->value.enumerated.item[0 ]; -int ret =0 ;if (item >= e->items)return -EINVAL ;
@@ -903,22 +900,20 @@ static int madera_adsp_rate_put(struct snd_kcontrol *kcontrol,* maintain consistent behaviour that rate domains cannot be changed * while in use since this is a hardware requirement */ -mutex_lock (&priv->rate_lock); +guard (mutex)(&priv->rate_lock);if (!madera_can_change_grp_rate (priv, priv->adsp[adsp_num].cs_dsp.base)) {dev_warn (priv->madera->dev,"Cannot change '%s' while in use by active audio paths\n" , kcontrol->id.name); - ret = -EBUSY ; +return -EBUSY ; }else if (priv->adsp_rate_cache[adsp_num] != e->values[item]) {/* Volatile register so defer until the codec is powered up */ priv->adsp_rate_cache[adsp_num] = e->values[item]; - ret =1 ; +return 1 ; } -mutex_unlock (&priv->rate_lock); - -return ret; +return 0 ; }static const struct soc_enum madera_adsp_rate_enum[] = {
@@ -1061,15 +1056,13 @@ int madera_rate_put(struct snd_kcontrol *kcontrol,* Prevent the domain powering up while we're checking whether it's * safe to change rate domain */ -mutex_lock (&priv->rate_lock); +guard (mutex)(&priv->rate_lock); val =snd_soc_component_read (component, e->reg); val >>= e->shift_l; val &= e->mask; -if (snd_soc_enum_item_to_val (e, item) == val) { - ret =0 ; - goto out; - } +if (snd_soc_enum_item_to_val (e, item) == val) +return 0 ;if (!madera_can_change_grp_rate (priv, e->reg)) { dev_warn(priv->madera->dev,
@@ -1082,8 +1075,6 @@ int madera_rate_put(struct snd_kcontrol *kcontrol, ret =snd_soc_put_enum_double (kcontrol, ucontrol);madera_spin_sysclk (priv); } -out: -mutex_unlock (&priv->rate_lock);return ret; }
@@ -3041,12 +3032,11 @@ static int madera_hw_params_rate(struct snd_pcm_substream *substream,if ((cur &MADERA_AIF1_RATE_MASK ) == (tar &MADERA_AIF1_RATE_MASK ))return 0 ; -mutex_lock (&priv->rate_lock); +guard (mutex)(&priv->rate_lock);if (!madera_can_change_grp_rate (priv, base +MADERA_AIF_RATE_CTRL )) {madera_aif_warn (dai,"Cannot change rate while active\n" ); - ret = -EBUSY ; - goto out; +return -EBUSY ; }/* Guard the rate change with SYSCLK cycles */
@@ -3055,9 +3045,6 @@ static int madera_hw_params_rate(struct snd_pcm_substream *substream, MADERA_AIF1_RATE_MASK, tar);madera_spin_sysclk (priv); -out: -mutex_unlock (&priv->rate_lock); -return ret; }
Signature · 1 line
2.43.0
PATCH v3 12/27 ASoC: codecs: max98095: 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/max98095.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
sound/soc/codecs/max98095.c +20 -15
@@ -5,6 +5,7 @@* Copyright 2011 Maxim Integrated Products */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h>
@@ -1532,15 +1533,17 @@ static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol, regsave =snd_soc_component_read (component,M98095_088_CFG_LEVEL );snd_soc_component_update_bits (component,M98095_088_CFG_LEVEL , regmask,0 ); -mutex_lock (&max98095->lock); -snd_soc_component_update_bits (component,M98095_00F_HOST_CFG ,M98095_SEG ,M98095_SEG ); -m98095_eq_band (component, channel,0 , coef_set->band1); -m98095_eq_band (component, channel,1 , coef_set->band2); -m98095_eq_band (component, channel,2 , coef_set->band3); -m98095_eq_band (component, channel,3 , coef_set->band4); -m98095_eq_band (component, channel,4 , coef_set->band5); -snd_soc_component_update_bits (component,M98095_00F_HOST_CFG ,M98095_SEG ,0 ); -mutex_unlock (&max98095->lock); + scoped_guard(mutex, &max98095->lock) { +snd_soc_component_update_bits (component,M98095_00F_HOST_CFG , +M98095_SEG ,M98095_SEG ); +m98095_eq_band (component, channel,0 , coef_set->band1); +m98095_eq_band (component, channel,1 , coef_set->band2); +m98095_eq_band (component, channel,2 , coef_set->band3); +m98095_eq_band (component, channel,3 , coef_set->band4); +m98095_eq_band (component, channel,4 , coef_set->band5); +snd_soc_component_update_bits (component,M98095_00F_HOST_CFG , +M98095_SEG ,0 ); + }/* Restore the original on/off state */ snd_soc_component_update_bits (component,M98095_088_CFG_LEVEL , regmask, regsave);
@@ -1683,12 +1686,14 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol, regsave =snd_soc_component_read (component,M98095_088_CFG_LEVEL );snd_soc_component_update_bits (component,M98095_088_CFG_LEVEL , regmask,0 ); -mutex_lock (&max98095->lock); -snd_soc_component_update_bits (component,M98095_00F_HOST_CFG ,M98095_SEG ,M98095_SEG ); -m98095_biquad_band (component, channel,0 , coef_set->band1); -m98095_biquad_band (component, channel,1 , coef_set->band2); -snd_soc_component_update_bits (component,M98095_00F_HOST_CFG ,M98095_SEG ,0 ); -mutex_unlock (&max98095->lock); + scoped_guard(mutex, &max98095->lock) { +snd_soc_component_update_bits (component,M98095_00F_HOST_CFG , +M98095_SEG ,M98095_SEG ); +m98095_biquad_band (component, channel,0 , coef_set->band1); +m98095_biquad_band (component, channel,1 , coef_set->band2); +snd_soc_component_update_bits (component,M98095_00F_HOST_CFG , +M98095_SEG ,0 ); + }/* Restore the original on/off state */ snd_soc_component_update_bits (component,M98095_088_CFG_LEVEL , regmask, regsave);
Signature · 1 line
2.43.0
PATCH v3 13/27 ASoC: codecs: mt6359-accdet: 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/mt6359-accdet.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
sound/soc/codecs/mt6359-accdet.c +4 -9
@@ -6,6 +6,7 @@// Author: Argus Lin <[email protected]> // +#include <linux/cleanup.h> #include <linux/of.h> #include <linux/input.h> #include <linux/kthread.h>
@@ -398,14 +399,13 @@ static void mt6359_accdet_work(struct work_struct *work)struct mt6359_accdet *priv = container_of(work, struct mt6359_accdet, accdet_work); -mutex_lock (&priv->res_lock); +guard (mutex)(&priv->res_lock); priv->pre_accdet_status = priv->accdet_status;check_jack_btn_type (priv);if (priv->jack_plugged && priv->pre_accdet_status != priv->accdet_status)mt6359_accdet_jack_report (priv); -mutex_unlock (&priv->res_lock); }static void mt6359_accdet_jd_work (struct work_struct *work)
@@ -416,7 +416,7 @@ static void mt6359_accdet_jd_work(struct work_struct *work)struct mt6359_accdet *priv = container_of(work, struct mt6359_accdet, jd_work); -mutex_lock (&priv->res_lock); +guard (mutex)(&priv->res_lock);if (priv->jd_sts ==M_PLUG_IN ) { priv->jack_plugged = true;
@@ -450,7 +450,6 @@ static void mt6359_accdet_jd_work(struct work_struct *work)if (priv->caps &ACCDET_PMIC_EINT_IRQ )recover_eint_setting (priv); -mutex_unlock (&priv->res_lock); }static irqreturn_t mt6359_accdet_irq (int irq,void *data)
@@ -459,7 +458,7 @@ static irqreturn_t mt6359_accdet_irq(int irq, void *data)unsigned int irq_val =0 , val =0 , value =0 ;int ret; -mutex_lock (&priv->res_lock); +guard (mutex)(&priv->res_lock);regmap_read (priv->regmap,ACCDET_IRQ_ADDR , &irq_val);if (irq_val &ACCDET_IRQ_MASK_SFT ) {
@@ -474,7 +473,6 @@ static irqreturn_t mt6359_accdet_irq(int irq, void *data) 1000);if (ret) {dev_err (priv->dev,"%s(), ret %d\n" , __func__, ret); -mutex_unlock (&priv->res_lock);return IRQ_NONE ; } regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
@@ -498,7 +496,6 @@ static irqreturn_t mt6359_accdet_irq(int irq, void *data)if (ret) {dev_err (priv->dev,"%s(), ret %d\n" , __func__, ret); -mutex_unlock (&priv->res_lock);return IRQ_NONE ; } regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
@@ -521,7 +518,6 @@ static irqreturn_t mt6359_accdet_irq(int irq, void *data)if (ret) {dev_err (priv->dev,"%s(), ret %d\n" , __func__, ret); -mutex_unlock (&priv->res_lock);return IRQ_NONE ; } regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
@@ -540,7 +536,6 @@ static irqreturn_t mt6359_accdet_irq(int irq, void *data)queue_work (priv->jd_workqueue, &priv->jd_work); } -mutex_unlock (&priv->res_lock);return IRQ_HANDLED ; }
Signature · 1 line
2.43.0
PATCH v3 14/27 ASoC: codecs: pcm512x: 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/pcm512x.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
sound/soc/codecs/pcm512x.c +6 -13
@@ -6,7 +6,7 @@* Copyright 2014 Linaro Ltd */ - +#include <linux/cleanup.h> #include <linux/init.h> #include <linux/module.h> #include <linux/clk.h>
@@ -399,10 +399,9 @@ static int pcm512x_digital_playback_switch_get(struct snd_kcontrol *kcontrol,struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);struct pcm512x_priv *pcm512x =snd_soc_component_get_drvdata (component); -mutex_lock (&pcm512x->mutex); +guard (mutex)(&pcm512x->mutex); ucontrol->value.integer.value[0 ] = !(pcm512x->mute &0x4 ); ucontrol->value.integer.value[1 ] = !(pcm512x->mute &0x2 ); -mutex_unlock (&pcm512x->mutex);return 0 ; }
@@ -414,7 +413,7 @@ static int pcm512x_digital_playback_switch_put(struct snd_kcontrol *kcontrol,struct pcm512x_priv *pcm512x =snd_soc_component_get_drvdata (component);int ret, changed =0 ; -mutex_lock (&pcm512x->mutex); +guard (mutex)(&pcm512x->mutex);if ((pcm512x->mute &0x4 ) == (ucontrol->value.integer.value[0 ] <<2 )) { pcm512x->mute ^=0x4 ;
@@ -430,13 +429,10 @@ static int pcm512x_digital_playback_switch_put(struct snd_kcontrol *kcontrol,if (ret !=0 ) {dev_err (component->dev,"Failed to update digital mute: %d\n" , ret); -mutex_unlock (&pcm512x->mutex);return ret; } } -mutex_unlock (&pcm512x->mutex); -return changed; }
@@ -1465,7 +1461,7 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction)int ret;unsigned int mute_det; -mutex_lock (&pcm512x->mutex); +guard (mutex)(&pcm512x->mutex);if (mute) { pcm512x->mute |=0x1 ;
@@ -1475,7 +1471,7 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction)if (ret !=0 ) {dev_err (component->dev,"Failed to set digital mute: %d\n" , ret); - goto unlock; +return ret; } regmap_read_poll_timeout(pcm512x->regmap,
@@ -1488,7 +1484,7 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction)if (ret !=0 ) {dev_err (component->dev,"Failed to update digital mute: %d\n" , ret); - goto unlock; +return ret; } regmap_read_poll_timeout(pcm512x->regmap,
@@ -1499,9 +1495,6 @@ static int pcm512x_mute(struct snd_soc_dai *dai, int mute, int direction) 200, 10000); } -unlock: -mutex_unlock (&pcm512x->mutex); -return ret; }
Signature · 1 line
2.43.0
PATCH v3 15/27 ASoC: codecs: pcm6240: 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/pcm6240.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
sound/soc/codecs/pcm6240.c +12 -13
@@ -12,6 +12,7 @@// Author: Shenghao Ding <[email protected]> // +#include <linux/cleanup.h> #include <linux/unaligned.h> #include <linux/firmware.h> #include <linux/gpio/consumer.h>
@@ -605,7 +606,7 @@ static int pcmdev_get_volsw(struct snd_kcontrol *kcontrol,unsigned int reg = mc->reg;unsigned int val; -mutex_lock (&pcm_dev->codec_lock); +guard (mutex)(&pcm_dev->codec_lock);if (pcm_dev->chip_id ==PCM1690 ) { ret = pcmdev_dev_read(pcm_dev, dev_no, PCM1690_REG_MODE_CTRL,
@@ -613,18 +614,18 @@ static int pcmdev_get_volsw(struct snd_kcontrol *kcontrol,if (ret) {dev_err (pcm_dev->dev,"%s: read mode err=%d\n" , __func__, ret); - goto out; +return ret; } val &=PCM1690_REG_MODE_CTRL_DAMS_MSK ;/* Set to wide-range mode, before using vol ctrl. */ if (!val && vol_ctrl_type ==PCMDEV_PCM1690_VOL_CTRL ) { ucontrol->value.integer.value[0 ] =-25500 ; - goto out; +return ret; }/* Set to fine mode, before using fine vol ctrl. */ if (val && vol_ctrl_type ==PCMDEV_PCM1690_FINE_VOL_CTRL ) { ucontrol->value.integer.value[0 ] =-12750 ; - goto out; +return ret; } }
@@ -632,15 +633,14 @@ static int pcmdev_get_volsw(struct snd_kcontrol *kcontrol,if (ret) {dev_err (pcm_dev->dev,"%s: read err=%d\n" , __func__, ret); - goto out; +return ret; } val = (val >> shift) & mask; val = (val > max) ? max : val; val = mc->invert ? max - val : val; ucontrol->value.integer.value[0 ] = val; -out: -mutex_unlock (&pcm_dev->codec_lock); +return ret; }
@@ -678,7 +678,7 @@ static int pcmdev_put_volsw(struct snd_kcontrol *kcontrol,unsigned int val, val_mask;unsigned int reg = mc->reg; -mutex_lock (&pcm_dev->codec_lock); +guard (mutex)(&pcm_dev->codec_lock); val = ucontrol->value.integer.value[0 ] & mask; val = (val > max) ? max : val; val = mc->invert ? max - val : val;
@@ -702,7 +702,7 @@ static int pcmdev_put_volsw(struct snd_kcontrol *kcontrol, __func__, rc); else rc =1 ; -mutex_unlock (&pcm_dev->codec_lock); +return rc; }
@@ -1645,9 +1645,8 @@ static void pcmdevice_comp_remove(struct snd_soc_component *codec)if (!pcm_dev)return ; -mutex_lock (&pcm_dev->codec_lock); +guard (mutex)(&pcm_dev->codec_lock);pcmdevice_config_info_remove (pcm_dev); -mutex_unlock (&pcm_dev->codec_lock); }static const struct snd_soc_dapm_widget pcmdevice_dapm_widgets[] = {
@@ -1890,9 +1889,9 @@ static int pcmdevice_mute(struct snd_soc_dai *dai, int mute, int stream)else block_type =PCMDEVICE_BIN_BLK_PRE_POWER_UP ; -mutex_lock (&pcm_dev->codec_lock); +guard (mutex)(&pcm_dev->codec_lock);pcmdevice_select_cfg_blk (pcm_dev, pcm_dev->cur_conf, block_type); -mutex_unlock (&pcm_dev->codec_lock); +return 0 ; }
Signature · 1 line
2.43.0
PATCH v3 16/27 ASoC: codecs: peb2466: 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/peb2466.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
sound/soc/codecs/peb2466.c +6 -10
@@ -6,6 +6,7 @@// // Author: Herve Codina <[email protected]> +#include <linux/cleanup.h> #include <linux/unaligned.h> #include <linux/clk.h> #include <linux/firmware.h>
@@ -1704,13 +1705,11 @@ static int peb2466_chip_gpio_update_bits(struct peb2466 *peb2466, unsigned int x* So, a specific cache value is used. */ -mutex_lock (&peb2466->gpio.lock); +guard (mutex)(&peb2466->gpio.lock); cache =peb2466_chip_gpio_get_cache (peb2466, xr_reg); -if (!cache) { - ret = -EINVAL ; - goto end; - } +if (!cache) +return -EINVAL ; tmp = *cache; tmp &= ~mask;
@@ -1718,14 +1717,11 @@ static int peb2466_chip_gpio_update_bits(struct peb2466 *peb2466, unsigned int x ret =regmap_write (peb2466->regmap, xr_reg, tmp);if (ret) - goto end; +return ret; *cache = tmp; - ret =0 ; -end: -mutex_unlock (&peb2466->gpio.lock); -return ret; +return 0 ; } static int peb2466_chip_gpio_set(struct gpio_chip *c, unsigned int offset,
Signature · 1 line
2.43.0
PATCH v3 17/27 ASoC: codecs: rt5514-spi: 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/rt5514-spi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
sound/soc/codecs/rt5514-spi.c +8 -13
@@ -6,6 +6,7 @@* Author: Oder Chiou <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/input.h> #include <linux/spi/spi.h>
@@ -79,17 +80,17 @@ static void rt5514_spi_copy_work(struct work_struct *work)unsigned int cur_wp, remain_data;u8 buf[8 ]; -mutex_lock (&rt5514_dsp->dma_lock); +guard (mutex)(&rt5514_dsp->dma_lock);if (!rt5514_dsp->substream) {dev_err (rt5514_dsp->dev,"No pcm substream\n" ); - goto done; +return ; } runtime = rt5514_dsp->substream->runtime; period_bytes =snd_pcm_lib_period_bytes (rt5514_dsp->substream);if (!period_bytes) {schedule_delayed_work (&rt5514_dsp->copy_work,5 ); - goto done; +return ; }if (rt5514_dsp->buf_size % period_bytes)
@@ -111,7 +112,7 @@ static void rt5514_spi_copy_work(struct work_struct *work)if (remain_data < period_bytes) {schedule_delayed_work (&rt5514_dsp->copy_work,5 ); - goto done; +return ; } }
@@ -146,9 +147,6 @@ static void rt5514_spi_copy_work(struct work_struct *work)snd_pcm_period_elapsed (rt5514_dsp->substream);schedule_delayed_work (&rt5514_dsp->copy_work,5 ); - -done: -mutex_unlock (&rt5514_dsp->dma_lock); }static void rt5514_schedule_copy (struct rt5514_dsp *rt5514_dsp)
@@ -216,7 +214,7 @@ static int rt5514_spi_hw_params(struct snd_soc_component *component,snd_soc_component_get_drvdata (component);u8 buf[8 ]; -mutex_lock (&rt5514_dsp->dma_lock); +guard (mutex)(&rt5514_dsp->dma_lock); rt5514_dsp->substream = substream; rt5514_dsp->dma_offset =0 ;
@@ -225,8 +223,6 @@ static int rt5514_spi_hw_params(struct snd_soc_component *component,if (buf[0 ] &RT5514_IRQ_STATUS_BIT )rt5514_schedule_copy (rt5514_dsp); -mutex_unlock (&rt5514_dsp->dma_lock); -return 0 ; }
@@ -236,9 +232,8 @@ static int rt5514_spi_hw_free(struct snd_soc_component *component,struct rt5514_dsp *rt5514_dsp =snd_soc_component_get_drvdata (component); -mutex_lock (&rt5514_dsp->dma_lock); - rt5514_dsp->substream =NULL ; -mutex_unlock (&rt5514_dsp->dma_lock); +scoped_guard (mutex, &rt5514_dsp->dma_lock) + rt5514_dsp->substream = NULL;cancel_delayed_work_sync (&rt5514_dsp->copy_work);
Signature · 1 line
2.43.0
PATCH v3 18/27 ASoC: codecs: rt5645: 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/rt5645.c | 160 +++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 81 deletions(-)
sound/soc/codecs/rt5645.c +79 -81
@@ -6,6 +6,7 @@* Author: Bard Liao <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -3323,93 +3324,90 @@ static void rt5645_jack_detect_work(struct work_struct *work)if (!rt5645->component)return ; -mutex_lock (&rt5645->jd_mutex); - -switch (rt5645->pdata.jd_mode) { -case 0 :/* Not using rt5645 JD */ -if (rt5645->gpiod_hp_det) { - gpio_state =gpiod_get_value (rt5645->gpiod_hp_det); -if (rt5645->pdata.inv_hp_pol) - gpio_state ^=1 ; -dev_dbg (rt5645->component->dev,"gpio_state = %d\n" , - gpio_state); - report =rt5645_jack_detect (rt5645->component, gpio_state); + scoped_guard(mutex, &rt5645->jd_mutex) { +switch (rt5645->pdata.jd_mode) { +case 0 :/* Not using rt5645 JD */ +if (rt5645->gpiod_hp_det) { + gpio_state =gpiod_get_value (rt5645->gpiod_hp_det); +if (rt5645->pdata.inv_hp_pol) + gpio_state ^=1 ; +dev_dbg (rt5645->component->dev,"gpio_state = %d\n" , + gpio_state); + report =rt5645_jack_detect (rt5645->component, gpio_state); + } +snd_soc_jack_report (rt5645->hp_jack, + report,SND_JACK_HEADPHONE ); +snd_soc_jack_report (rt5645->mic_jack, + report,SND_JACK_MICROPHONE ); +return ; +case 4 : + val =snd_soc_component_read (rt5645->component,RT5645_A_JD_CTRL1 ) &0x0020 ; +break ; +default :/* read rt5645 jd1_1 status */ + val =snd_soc_component_read (rt5645->component,RT5645_INT_IRQ_ST ) &0x1000 ; +break ; } -snd_soc_jack_report (rt5645->hp_jack, - report,SND_JACK_HEADPHONE ); -snd_soc_jack_report (rt5645->mic_jack, - report,SND_JACK_MICROPHONE ); -mutex_unlock (&rt5645->jd_mutex); -return ; -case 4 : - val =snd_soc_component_read (rt5645->component,RT5645_A_JD_CTRL1 ) &0x0020 ; -break ; -default :/* read rt5645 jd1_1 status */ - val =snd_soc_component_read (rt5645->component,RT5645_INT_IRQ_ST ) &0x1000 ; -break ; - - } -if (!val && (rt5645->jack_type ==0 )) {/* jack in */ - report =rt5645_jack_detect (rt5645->component,1 ); - }else if (!val && rt5645->jack_type ==SND_JACK_HEADSET ) { -/* for push button and jack out */ - btn_type =0 ; -if (snd_soc_component_read (rt5645->component,RT5645_INT_IRQ_ST ) &0x4 ) { -/* button pressed */ - report =SND_JACK_HEADSET ; - btn_type =rt5645_button_detect (rt5645->component); -/* rt5650 can report three kinds of button behavior, -one click, double click and hold. However, -currently we will report button pressed/released -event. So all the three button behaviors are -treated as button pressed. */ -switch (btn_type) { -case 0x8000 : -case 0x4000 : -case 0x2000 : - report |=SND_JACK_BTN_0 ; -break ; -case 0x1000 : -case 0x0800 : -case 0x0400 : - report |=SND_JACK_BTN_1 ; -break ; -case 0x0200 : -case 0x0100 : -case 0x0080 : - report |=SND_JACK_BTN_2 ; -break ; -case 0x0040 : -case 0x0020 : -case 0x0010 : - report |=SND_JACK_BTN_3 ; -break ; -case 0x0000 :/* unpressed */ -break ; -default : -dev_err (rt5645->component->dev, -"Unexpected button code 0x%04x\n" , - btn_type); -break ; +if (!val && rt5645->jack_type ==0 ) {/* jack in */ + report =rt5645_jack_detect (rt5645->component,1 ); + }else if (!val && rt5645->jack_type ==SND_JACK_HEADSET ) { +/* for push button and jack out */ + btn_type =0 ; +if (snd_soc_component_read (rt5645->component,RT5645_INT_IRQ_ST ) &0x4 ) { +/* button pressed */ + report =SND_JACK_HEADSET ; + btn_type =rt5645_button_detect (rt5645->component); +/* +* rt5650 can report three kinds of button behavior, +* one click, double click and hold. However, +* currently we will report button pressed/released +* event. So all the three button behaviors are +* treated as button pressed. +*/ +switch (btn_type) { +case 0x8000 : +case 0x4000 : +case 0x2000 : + report |=SND_JACK_BTN_0 ; +break ; +case 0x1000 : +case 0x0800 : +case 0x0400 : + report |=SND_JACK_BTN_1 ; +break ; +case 0x0200 : +case 0x0100 : +case 0x0080 : + report |=SND_JACK_BTN_2 ; +break ; +case 0x0040 : +case 0x0020 : +case 0x0010 : + report |=SND_JACK_BTN_3 ; +break ; +case 0x0000 :/* unpressed */ +break ; +default : +dev_err (rt5645->component->dev, +"Unexpected button code 0x%04x\n" , + btn_type); +break ; + } } +if (btn_type ==0 )/* button release */ + report = rt5645->jack_type; +else +mod_timer (&rt5645->btn_check_timer, +msecs_to_jiffies (100 )); + }else { +/* jack out */ + report =0 ; +snd_soc_component_update_bits (rt5645->component, +RT5645_INT_IRQ_ST ,0x1 ,0x0 ); +rt5645_jack_detect (rt5645->component,0 ); } -if (btn_type ==0 )/* button release */ - report = rt5645->jack_type; -else { -mod_timer (&rt5645->btn_check_timer, -msecs_to_jiffies (100 )); - } - }else { -/* jack out */ - report =0 ; -snd_soc_component_update_bits (rt5645->component, -RT5645_INT_IRQ_ST ,0x1 ,0x0 ); -rt5645_jack_detect (rt5645->component,0 ); } -mutex_unlock (&rt5645->jd_mutex); -snd_soc_jack_report (rt5645->hp_jack, report,SND_JACK_HEADPHONE );snd_soc_jack_report (rt5645->mic_jack, report,SND_JACK_MICROPHONE );if (rt5645->en_button_func)
Signature · 1 line
2.43.0
PATCH v3 19/27 ASoC: codecs: rt5665: 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/rt5665.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
sound/soc/codecs/rt5665.c +7 -8
@@ -6,6 +6,7 @@* Author: Bard Liao <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -1208,7 +1209,7 @@ static void rt5665_jack_detect_handler(struct work_struct *work)usleep_range (10000 ,15000 ); } -mutex_lock (&rt5665->calibrate_mutex); +guard (mutex)(&rt5665->calibrate_mutex); val =snd_soc_component_read (rt5665->component,RT5665_AJD1_CTRL ) &0x0010 ;if (!val) {
@@ -1274,8 +1275,6 @@ static void rt5665_jack_detect_handler(struct work_struct *work)schedule_delayed_work (&rt5665->jd_check_work,0 ); else cancel_delayed_work_sync(&rt5665->jd_check_work); - -mutex_unlock (&rt5665->calibrate_mutex); }static const char *const rt5665_clk_sync[] = {
@@ -4564,7 +4563,7 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665) {int value, count; -mutex_lock (&rt5665->calibrate_mutex); +guard (mutex)(&rt5665->calibrate_mutex);regcache_cache_bypass (rt5665->regmap, true);
@@ -4601,7 +4600,8 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)pr_err ("HP Calibration Failure\n" );regmap_write (rt5665->regmap,RT5665_RESET ,0 );regcache_cache_bypass (rt5665->regmap, false); - goto out_unlock; + rt5665->calibration_done = true; +return ; } count++;
@@ -4620,7 +4620,8 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)pr_err ("MONO Calibration Failure\n" );regmap_write (rt5665->regmap,RT5665_RESET ,0 );regcache_cache_bypass (rt5665->regmap, false); - goto out_unlock; + rt5665->calibration_done = true; +return ; } count++;
@@ -4635,9 +4636,7 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)regmap_write (rt5665->regmap,RT5665_BIAS_CUR_CTRL_8 ,0xa602 );regmap_write (rt5665->regmap,RT5665_ASRC_8 ,0x0120 ); -out_unlock: rt5665->calibration_done = true; -mutex_unlock (&rt5665->calibrate_mutex); }static void rt5665_calibrate_handler (struct work_struct *work)
Signature · 1 line
2.43.0
PATCH v3 20/27 ASoC: codecs: rt5668: 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/rt5668.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/soc/codecs/rt5668.c +3 -7
@@ -6,6 +6,7 @@* Author: Bard Liao <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -986,7 +987,7 @@ static void rt5668_jack_detect_handler(struct work_struct *work)return ; } -mutex_lock (&rt5668->calibrate_mutex); +guard (mutex)(&rt5668->calibrate_mutex); val =snd_soc_component_read (rt5668->component,RT5668_AJD1_CTRL ) &RT5668_JDH_RS_MASK ;
@@ -1053,8 +1054,6 @@ static void rt5668_jack_detect_handler(struct work_struct *work)schedule_delayed_work (&rt5668->jd_check_work,0 ); else cancel_delayed_work_sync(&rt5668->jd_check_work); - -mutex_unlock (&rt5668->calibrate_mutex); }static const struct snd_kcontrol_new rt5668_snd_controls[] = {
@@ -2356,7 +2355,7 @@ static void rt5668_calibrate(struct rt5668_priv *rt5668) {int value, count; -mutex_lock (&rt5668->calibrate_mutex); +guard (mutex)(&rt5668->calibrate_mutex);rt5668_reset (rt5668->regmap);regmap_write (rt5668->regmap,RT5668_PWR_ANLG_1 ,0xa2bf );
@@ -2400,9 +2399,6 @@ static void rt5668_calibrate(struct rt5668_priv *rt5668)/* restore settings */ regmap_write (rt5668->regmap,RT5668_STO1_ADC_MIXER ,0xc0c4 );regmap_write (rt5668->regmap,RT5668_PWR_DIG_1 ,0x0000 ); - -mutex_unlock (&rt5668->calibrate_mutex); - }static int rt5668_i2c_probe (struct i2c_client *i2c)
Signature · 1 line
2.43.0
PATCH v3 21/27 ASoC: codecs: rt5677: 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/rt5677-spi.c | 36 +++++++---------- sound/soc/codecs/rt5677.c | 75 ++++++++++++++++------------------- 2 files changed, 49 insertions(+), 62 deletions(-)
sound/soc/codecs/rt5677-spi.c +15 -21
@@ -6,6 +6,7 @@* Author: Oder Chiou <[email protected]> */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/input.h> #include <linux/spi/spi.h>
@@ -133,9 +134,8 @@ static int rt5677_spi_hw_params(struct rt5677_dsp *rt5677_dsp =snd_soc_component_get_drvdata (component); -mutex_lock (&rt5677_dsp->dma_lock); +guard (mutex)(&rt5677_dsp->dma_lock); rt5677_dsp->substream = substream; -mutex_unlock (&rt5677_dsp->dma_lock);return 0 ; }
@@ -147,9 +147,8 @@ static int rt5677_spi_hw_free(struct rt5677_dsp *rt5677_dsp =snd_soc_component_get_drvdata (component); -mutex_lock (&rt5677_dsp->dma_lock); +guard (mutex)(&rt5677_dsp->dma_lock); rt5677_dsp->substream =NULL ; -mutex_unlock (&rt5677_dsp->dma_lock);return 0 ; }
@@ -311,17 +310,17 @@ static void rt5677_spi_copy_work(struct work_struct *work)int ret =0 ;/* Ensure runtime->dma_area buffer does not go away while copying. */ -mutex_lock (&rt5677_dsp->dma_lock); +guard (mutex)(&rt5677_dsp->dma_lock);if (!rt5677_dsp->substream) {dev_err (rt5677_dsp->dev,"No pcm substream\n" ); - goto done; +return ; } runtime = rt5677_dsp->substream->runtime;if (rt5677_spi_mic_write_offset (&mic_write_offset)) {dev_err (rt5677_dsp->dev,"No mic_write_offset\n" ); - goto done; +return ; }/* If this is the first time that we've asked for streaming data after
@@ -355,7 +354,7 @@ static void rt5677_spi_copy_work(struct work_struct *work) ret =rt5677_spi_copy (rt5677_dsp, copy_bytes);if (ret) {dev_err (rt5677_dsp->dev,"Copy failed %d\n" , ret); - goto done; +return ; } rt5677_dsp->avail_bytes += copy_bytes;if (rt5677_dsp->avail_bytes >= period_bytes) {
@@ -367,8 +366,6 @@ static void rt5677_spi_copy_work(struct work_struct *work) delay =bytes_to_frames (runtime, period_bytes) / runtime->rate;schedule_delayed_work (&rt5677_dsp->copy_work,secs_to_jiffies (delay)); -done: -mutex_unlock (&rt5677_dsp->dma_lock); } static int rt5677_spi_pcm_new(struct snd_soc_component *component,
@@ -507,10 +504,8 @@ int rt5677_spi_read(u32 addr, void *rxbuf, size_t len) header[3 ] = ((addr + offset) &0x0000ff00 ) >>8 ; header[4 ] = ((addr + offset) &0x000000ff ) >>0 ; -mutex_lock (&spi_mutex); - status |=spi_sync (g_spi, &m); -mutex_unlock (&spi_mutex); - +scoped_guard (mutex, &spi_mutex) + status |= spi_sync(g_spi, &m);/* Copy data back to caller buffer */ rt5677_spi_reverse (cb + offset, len - offset, body, t[1 ].len);
@@ -564,9 +559,8 @@ int rt5677_spi_write(u32 addr, const void *txbuf, size_t len) offset += t.len; t.len +=RT5677_SPI_HEADER +1 ; -mutex_lock (&spi_mutex); - status |=spi_sync (g_spi, &m); -mutex_unlock (&spi_mutex); +scoped_guard (mutex, &spi_mutex) + status |= spi_sync(g_spi, &m); }return status; }
@@ -591,10 +585,10 @@ void rt5677_spi_hotword_detected(void)return ; } -mutex_lock (&rt5677_dsp->dma_lock); -dev_info (rt5677_dsp->dev,"Hotword detected\n" ); - rt5677_dsp->new_hotword = true; -mutex_unlock (&rt5677_dsp->dma_lock); + scoped_guard(mutex, &rt5677_dsp->dma_lock) { +dev_info (rt5677_dsp->dev,"Hotword detected\n" ); + rt5677_dsp->new_hotword = true; + }schedule_delayed_work (&rt5677_dsp->copy_work,0 ); }
sound/soc/codecs/rt5677.c +34 -41
180 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 22/27 ASoC: codecs: rt5682: 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/rt5682-sdw.c | 24 ++++++++++++------------ sound/soc/codecs/rt5682.c | 5 ++--- sound/soc/codecs/rt5682s.c | 17 +++++------------ 3 files changed, 19 insertions(+), 27 deletions(-)
sound/soc/codecs/rt5682-sdw.c +12 -12
@@ -6,6 +6,7 @@// Author: Oder Chiou <[email protected]> // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -660,12 +661,11 @@ static int rt5682_interrupt_callback(struct sdw_slave *slave,dev_dbg (&slave->dev,"%s control_port_stat=%x" , __func__, status->control_port); -mutex_lock (&rt5682->disable_irq_lock); +guard (mutex)(&rt5682->disable_irq_lock);if (status->control_port &0x4 && !rt5682->disable_irq) {mod_delayed_work (system_power_efficient_wq, &rt5682->jack_detect_work,msecs_to_jiffies (rt5682->irq_work_delay_time)); } -mutex_unlock (&rt5682->disable_irq_lock);return 0 ; }
@@ -736,11 +736,11 @@ static int rt5682_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt5682->disable_irq_lock); - rt5682->disable_irq = true; - ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , -SDW_SCP_INT1_IMPL_DEF ,0 ); -mutex_unlock (&rt5682->disable_irq_lock); + scoped_guard(mutex, &rt5682->disable_irq_lock) { + rt5682->disable_irq = true; + ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , +SDW_SCP_INT1_IMPL_DEF ,0 ); + }if (ret <0 ) {/* log but don't prevent suspend from happening */
@@ -760,12 +760,12 @@ static int rt5682_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt5682->disable_irq_lock); -if (rt5682->disable_irq == true) { -sdw_write_no_pm (slave,SDW_SCP_INTMASK1 ,SDW_SCP_INT1_IMPL_DEF ); - rt5682->disable_irq = false; + scoped_guard(mutex, &rt5682->disable_irq_lock) { +if (rt5682->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_INTMASK1 ,SDW_SCP_INT1_IMPL_DEF ); + rt5682->disable_irq = false; + } } -mutex_unlock (&rt5682->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT5682_PROBE_TIMEOUT );
sound/soc/codecs/rt5682.c +2 -3
@@ -6,6 +6,7 @@// Author: Bard Liao <[email protected]> // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -3125,7 +3126,7 @@ void rt5682_calibrate(struct rt5682_priv *rt5682) {int value, count; -mutex_lock (&rt5682->calibrate_mutex); +guard (mutex)(&rt5682->calibrate_mutex);rt5682_reset (rt5682);regmap_write (rt5682->regmap,RT5682_I2C_CTRL ,0x000f );
@@ -3175,8 +3176,6 @@ void rt5682_calibrate(struct rt5682_priv *rt5682)regmap_write (rt5682->regmap,RT5682_CALIB_ADC_CTRL ,0x2005 );regmap_write (rt5682->regmap,RT5682_STO1_ADC_MIXER ,0xc0c4 );regmap_write (rt5682->regmap,RT5682_CAL_REC ,0x0c0c ); - -mutex_unlock (&rt5682->calibrate_mutex); }EXPORT_SYMBOL_GPL (rt5682_calibrate);
sound/soc/codecs/rt5682s.c +5 -12
@@ -6,6 +6,7 @@// Author: Derek Fang <[email protected]> // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h>
@@ -648,7 +649,7 @@ static void rt5682s_sar_power_mode(struct snd_soc_component *component, int mode {struct rt5682s_priv *rt5682s =snd_soc_component_get_drvdata (component); -mutex_lock (&rt5682s->sar_mutex); +guard (mutex)(&rt5682s->sar_mutex);switch (mode) {case SAR_PWR_SAVING :
@@ -695,8 +696,6 @@ static void rt5682s_sar_power_mode(struct snd_soc_component *component, int modedev_err (component->dev,"Invalid SAR Power mode: %d\n" , mode);break ; } - -mutex_unlock (&rt5682s->sar_mutex); }static void rt5682s_enable_push_button_irq (struct snd_soc_component *component)
@@ -2534,7 +2533,7 @@ static int rt5682s_wclk_prepare(struct clk_hw *hw)if (!rt5682s_clk_check (rt5682s))return -EINVAL ; -mutex_lock (&rt5682s->wclk_mutex); +guard (mutex)(&rt5682s->wclk_mutex); snd_soc_component_update_bits(component, RT5682S_PWR_ANLG_1, RT5682S_PWR_VREF2 | RT5682S_PWR_FV2 | RT5682S_PWR_MB,
@@ -2556,8 +2555,6 @@ static int rt5682s_wclk_prepare(struct clk_hw *hw) rt5682s->wclk_enabled =1 ; -mutex_unlock (&rt5682s->wclk_mutex); -return 0 ; }
@@ -2570,7 +2567,7 @@ static void rt5682s_wclk_unprepare(struct clk_hw *hw)if (!rt5682s_clk_check (rt5682s))return ; -mutex_lock (&rt5682s->wclk_mutex); +guard (mutex)(&rt5682s->wclk_mutex);if (!rt5682s->jack_type) snd_soc_component_update_bits(component, RT5682S_PWR_ANLG_1,
@@ -2585,8 +2582,6 @@ static void rt5682s_wclk_unprepare(struct clk_hw *hw)rt5682s_set_pllb_power (rt5682s,0 ); rt5682s->wclk_enabled =0 ; - -mutex_unlock (&rt5682s->wclk_mutex); } static unsigned long rt5682s_wclk_recalc_rate(struct clk_hw *hw,
@@ -2997,7 +2992,7 @@ static void rt5682s_calibrate(struct rt5682s_priv *rt5682s) {unsigned int count, value; -mutex_lock (&rt5682s->calibrate_mutex); +guard (mutex)(&rt5682s->calibrate_mutex);regmap_write (rt5682s->regmap,RT5682S_PWR_ANLG_1 ,0xaa80 );usleep_range (15000 ,20000 );
@@ -3034,8 +3029,6 @@ static void rt5682s_calibrate(struct rt5682s_priv *rt5682s)regmap_write (rt5682s->regmap,RT5682S_PWR_DIG_1 ,0x00c0 );regmap_write (rt5682s->regmap,RT5682S_PWR_ANLG_1 ,0x0800 );regmap_write (rt5682s->regmap,RT5682S_GLB_CLK ,0x0000 ); - -mutex_unlock (&rt5682s->calibrate_mutex); }static const struct regmap_config rt5682s_regmap = {
Signature · 1 line
2.43.0
PATCH v3 23/27 ASoC: codecs: rt700: 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/rt700-sdw.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
sound/soc/codecs/rt700-sdw.c +7 -7
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/soundwire/sdw.h>
@@ -415,12 +416,11 @@ static int rt700_interrupt_callback(struct sdw_slave *slave,dev_dbg (&slave->dev,"%s control_port_stat=%x" , __func__, status->control_port); -mutex_lock (&rt700->disable_irq_lock); +guard (mutex)(&rt700->disable_irq_lock);if (status->control_port &0x4 && !rt700->disable_irq) {mod_delayed_work (system_power_efficient_wq, &rt700->jack_detect_work,msecs_to_jiffies (250 )); } -mutex_unlock (&rt700->disable_irq_lock);return 0 ; }
@@ -499,11 +499,11 @@ static int rt700_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt700->disable_irq_lock); - rt700->disable_irq = true; - ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , -SDW_SCP_INT1_IMPL_DEF ,0 ); -mutex_unlock (&rt700->disable_irq_lock); + scoped_guard(mutex, &rt700->disable_irq_lock) { + rt700->disable_irq = true; + ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , +SDW_SCP_INT1_IMPL_DEF ,0 ); + }if (ret <0 ) {/* log but don't prevent suspend from happening */
Signature · 1 line
2.43.0
PATCH v3 24/27 ASoC: codecs: rt711: 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/rt711-sdca-sdw.c | 29 ++++++++++-------- sound/soc/codecs/rt711-sdca.c | 5 ++-- sound/soc/codecs/rt711-sdw.c | 24 +++++++-------- sound/soc/codecs/rt711.c | 50 +++++++++++++++---------------- 4 files changed, 54 insertions(+), 54 deletions(-)
sound/soc/codecs/rt711-sdca-sdw.c +16 -13
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/soundwire/sdw_registers.h>
@@ -415,13 +416,13 @@ static int rt711_sdca_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt711_sdca->disable_irq_lock); - rt711_sdca->disable_irq = true; - ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , -SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); - ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , -SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); -mutex_unlock (&rt711_sdca->disable_irq_lock); + scoped_guard(mutex, &rt711_sdca->disable_irq_lock) { + rt711_sdca->disable_irq = true; + ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); + ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); + }if (ret1 <0 || ret2 <0 ) {/* log but don't prevent suspend from happening */
@@ -443,13 +444,15 @@ static int rt711_sdca_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt711->disable_irq_lock); -if (rt711->disable_irq == true) { -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 ); -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 ,SDW_SCP_SDCA_INTMASK_SDCA_8 ); - rt711->disable_irq = false; + scoped_guard(mutex, &rt711->disable_irq_lock) { +if (rt711->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ); +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ); + rt711->disable_irq = false; + } } -mutex_unlock (&rt711->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT711_PROBE_TIMEOUT );
sound/soc/codecs/rt711-sdca.c +2 -3
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h>
@@ -450,7 +451,7 @@ static void rt711_sdca_btn_check_handler(struct work_struct *work)static void rt711_sdca_jack_init (struct rt711_sdca_priv *rt711) { -mutex_lock (&rt711->calibrate_mutex); +guard (mutex)(&rt711->calibrate_mutex);if (rt711->hs_jack) {/* Enable HID1 event & set button RTC mode */
@@ -515,8 +516,6 @@ static void rt711_sdca_jack_init(struct rt711_sdca_priv *rt711)dev_dbg (&rt711->slave->dev,"in %s disable\n" , __func__); } - -mutex_unlock (&rt711->calibrate_mutex); } static int rt711_sdca_set_jack_detect(struct snd_soc_component *component,
sound/soc/codecs/rt711-sdw.c +12 -12
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/soundwire/sdw.h>
@@ -422,12 +423,11 @@ static int rt711_interrupt_callback(struct sdw_slave *slave,dev_dbg (&slave->dev,"%s control_port_stat=%x" , __func__, status->control_port); -mutex_lock (&rt711->disable_irq_lock); +guard (mutex)(&rt711->disable_irq_lock);if (status->control_port &0x4 && !rt711->disable_irq) {mod_delayed_work (system_power_efficient_wq, &rt711->jack_detect_work,msecs_to_jiffies (250 )); } -mutex_unlock (&rt711->disable_irq_lock);return 0 ; }
@@ -509,11 +509,11 @@ static int rt711_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt711->disable_irq_lock); - rt711->disable_irq = true; - ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , -SDW_SCP_INT1_IMPL_DEF ,0 ); -mutex_unlock (&rt711->disable_irq_lock); + scoped_guard(mutex, &rt711->disable_irq_lock) { + rt711->disable_irq = true; + ret =sdw_update_no_pm (slave,SDW_SCP_INTMASK1 , +SDW_SCP_INT1_IMPL_DEF ,0 ); + }if (ret <0 ) {/* log but don't prevent suspend from happening */
@@ -535,12 +535,12 @@ static int rt711_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt711->disable_irq_lock); -if (rt711->disable_irq == true) { -sdw_write_no_pm (slave,SDW_SCP_INTMASK1 ,SDW_SCP_INT1_IMPL_DEF ); - rt711->disable_irq = false; + scoped_guard(mutex, &rt711->disable_irq_lock) { +if (rt711->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_INTMASK1 ,SDW_SCP_INT1_IMPL_DEF ); + rt711->disable_irq = false; + } } -mutex_unlock (&rt711->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT711_PROBE_TIMEOUT );
sound/soc/codecs/rt711.c +24 -26
127 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 25/27 ASoC: codecs: rt712: 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/rt712-sdca-sdw.c | 30 ++++++++++++++++-------------- sound/soc/codecs/rt712-sdca.c | 5 ++--- 2 files changed, 18 insertions(+), 17 deletions(-)
sound/soc/codecs/rt712-sdca-sdw.c +16 -14
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/module.h>
@@ -427,13 +428,13 @@ static int rt712_sdca_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt712_sdca->disable_irq_lock); - rt712_sdca->disable_irq = true; - ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , -SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); - ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , -SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); -mutex_unlock (&rt712_sdca->disable_irq_lock); + scoped_guard(mutex, &rt712_sdca->disable_irq_lock) { + rt712_sdca->disable_irq = true; + ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); + ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); + }if (ret1 <0 || ret2 <0 ) {/* log but don't prevent suspend from happening */
@@ -455,14 +456,15 @@ static int rt712_sdca_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt712->disable_irq_lock); -if (rt712->disable_irq == true) { - -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 ); -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 ,SDW_SCP_SDCA_INTMASK_SDCA_8 ); - rt712->disable_irq = false; + scoped_guard(mutex, &rt712->disable_irq_lock) { +if (rt712->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ); +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ); + rt712->disable_irq = false; + } } -mutex_unlock (&rt712->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT712_PROBE_TIMEOUT );
sound/soc/codecs/rt712-sdca.c +2 -3
@@ -7,6 +7,7 @@// #include <linux/bitops.h> +#include <linux/cleanup.h> #include <sound/core.h> #include <linux/delay.h> #include <linux/init.h>
@@ -403,7 +404,7 @@ static void rt712_sdca_btn_check_handler(struct work_struct *work)static void rt712_sdca_jack_init (struct rt712_sdca_priv *rt712) { -mutex_lock (&rt712->calibrate_mutex); +guard (mutex)(&rt712->calibrate_mutex);if (rt712->hs_jack) {/* Enable HID1 event & set button RTC mode */
@@ -450,8 +451,6 @@ static void rt712_sdca_jack_init(struct rt712_sdca_priv *rt712)dev_dbg (&rt712->slave->dev,"in %s disable\n" , __func__); } - -mutex_unlock (&rt712->calibrate_mutex); } static int rt712_sdca_set_jack_detect(struct snd_soc_component *component,
Signature · 1 line
2.43.0
Mark Brown
maintainerRe: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
Quoted 11 lines · On Fri, Jul 10, 2026 at 12:05:09PM +0700, [email protected] wrote:
sound/soc/codecs/rt712-sdca-sdw.c +1
-6@@ -455,14 +456,15 @@ static int rt712_sdca_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt712->disable_irq_lock); -if (rt712->disable_irq == true) { - -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 ); -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 ,SDW_SCP_SDCA_INTMASK_SDCA_8 ); - rt712->disable_irq = false; + scoped_guard(mutex, &rt712->disable_irq_lock) {
sound/soc/codecs/rt712-sdca-sdw.c static int rt712_sdca_dev_resume(struct device *dev) · line 468
Quoted 10 lines
sound/soc/codecs/rt712-sdca-sdw.c +7
-1+if (rt712->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ); +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ); + rt712->disable_irq = false; + } } -mutex_unlock (&rt712->disable_irq_lock); }
This function does also have some goto based unwinding, there's a similar thing in the rt721 changes.
Re: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
Hi Mark,
Thanks for the review.
Quoted 2 lines
This function does also have some goto based unwinding, there's a similar thing in the rt721 changes.
It seems this goto block was added recently, and I missed it after rebasing. Sorry for the inconvenience.
However, looking at the goto path, it seems we might need to unwind the states more completely. What do you think about rewriting it like this?
------------------
regcache_cache_only(rt712->regmap, false);
ret = regcache_sync(rt712->regmap);
if (ret) {
regcache_cache_only(rt712->regmap, true);
regcache_mark_dirty(rt712->regmap);
return ret;
}
regcache_cache_only(rt712->mbq_regmap, false);
ret = regcache_sync(rt712->mbq_regmap);
if (ret) {
regcache_cache_only(rt712->regmap, true);
regcache_cache_only(rt712->mbq_regmap, true);
regcache_mark_dirty(rt712->mbq_regmap);
return ret;
}
return 0;--------------------
Best regards,
Phuc
Re: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
Hi Mark,
One more note on this:
Quoted 24 lines
It seems this goto block was added recently, and I missed it after rebasing. Sorry for the inconvenience.
However, looking at the goto path, it seems we might need to unwind the states more completely. What do you think about rewriting it like this?------------------
regcache_cache_only(rt712->regmap, false); ret = regcache_sync(rt712->regmap); if (ret) { regcache_cache_only(rt712->regmap, true); regcache_mark_dirty(rt712->regmap); return ret; } regcache_cache_only(rt712->mbq_regmap, false); ret = regcache_sync(rt712->mbq_regmap); if (ret) { regcache_cache_only(rt712->regmap, true); regcache_cache_only(rt712->mbq_regmap, true); regcache_mark_dirty(rt712->mbq_regmap); return ret; } return 0;
Quoted 2 lines
--------------------
Since regmap was already synced successfully, marking it dirty again would be redundant and could cause the next regcache_sync() to needlessly rewrite cached registers that are already known to be in sync.
Also, in my understanding, any register write that happens afterwards while cache_only=true should automatically set cache_dirty=true again (see _regmap_write(), _regmap_raw_write_impl(), regmap_noinc_readwrite(), and _regmap_multi_reg_write() in regmap.c), so there may be no need to defensively mark it dirty here in case of a later write. Reads aren't a concern here, since a read never changes any state - it's only writes that can make the cache diverge from the hardware while cache_only is set.
Please correct me if I'm missing something here.
Best regards,
Phuc
Re: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
Hi all,
While looking into removing the goto label in rt712_sdca_dev_resume(), I dug a bit deeper into regcache_sync() and how it manages the cache_dirty flag. I'd like to share the analysis and propose a small patch for review.
1. cache_dirty state before the out: label in regcache_sync() Before the out: block, cache_dirty can only be in one of two states:
+ true: if writing the patch or the sync itself failed partway through.
+ false: either it was already false from the start, or — after the patch has been applied successfully (i.e. the patch loop didn't jump to goto out) — the subsequent sync() call also returns success (ret == 0).
→ The logic here is sound and consistent.
2. cache_dirty state after the out: label in regcache_sync() If _regmap_write() fails when re-pushing the paging register here, none of its three error paths (-EIO, regcache_write() failure, or map->reg_write() failure) touch cache_dirty.
Only the cache_only success path touches cache_dirty.
So cache_dirty simply keeps whatever value it already had before out:
(as described above), even though this write genuinely failed.
3. Proposed patch
-------------
ret = _regmap_write(map, this->selector_reg, i);
if (ret != 0) {
dev_err(map->dev, "Failed to write %x = %x: %d\n",
this->selector_reg, i, ret);
+ map->cache_dirty = true;
break;
}--------------
This ensures cache_dirty correctly reflects a real cache/hardware mismatch whenever this write fails.
Feedback welcome before I submit the formal patch.
Best regards,
Phuc
Re: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
Another point is: when should regcache_sync() be considered to have failed?
From my understanding, if patch application or cache synchronization fails before reaching the out: label, then regcache_sync() has already failed and should return that error.
However, the function currently uses a single ret variable throughout the entire flow.
To make the failure semantics clearer, I'm planning to submit the following follow-up patch.
I'd appreciate any feedback.
------------------
int paging_ret = 0;
/* ... */
out:
/* ... */
paging_ret = _regmap_write(map, this->selector_reg, i);
if (paging_ret) {
dev_err(...);
map->cache_dirty = true;
break;
}/* ... */
return ret ? ret : paging_ret;
-------------------
This preserves any error that occurred before out: while also reporting errors that occur after out:.
Best regards.
Phuc
Re: [PATCH v3 25/27] ASoC: codecs: rt712: Use guard() for mutex locks
I'd like to confirm one more point.
As I understand it, cache_only must be disabled before re-writing the paging selector registers. Otherwise, _regmap_write() would update only the cache and return without calling map->reg_write(), so the hardware state would not actually be restored.
If my understanding is correct, I'm planning to submit a follow-up patch like the one below.
---------------------------------
bool cache_only ;cache_only = map->cache_only;
map->cache_only = false;
for_each_selector_register() {
if (regcache_read(map, selector_reg, &selector_val))
continue;
paging_ret = _regmap_write(map, selector_reg, selector_val);
}map->cache_only = cache_only;
-----------------------------------
I'd appreciate any feedback.
Best regards,
Phuc
PATCH v3 26/27 ASoC: codecs: rt721: 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/rt721-sdca-sdw.c | 29 ++++++++++++++++------------- sound/soc/codecs/rt721-sdca.c | 5 ++--- 2 files changed, 18 insertions(+), 16 deletions(-)
sound/soc/codecs/rt721-sdca-sdw.c +16 -13
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/module.h>
@@ -466,13 +467,13 @@ static int rt721_sdca_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt721_sdca->disable_irq_lock); - rt721_sdca->disable_irq = true; - ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , -SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); - ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , -SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); -mutex_unlock (&rt721_sdca->disable_irq_lock); + scoped_guard(mutex, &rt721_sdca->disable_irq_lock) { + rt721_sdca->disable_irq = true; + ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); + ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); + }if (ret1 <0 || ret2 <0 ) {/* log but don't prevent suspend from happening */
@@ -494,13 +495,15 @@ static int rt721_sdca_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt721->disable_irq_lock); -if (rt721->disable_irq == true) { -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 ); -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 ,SDW_SCP_SDCA_INTMASK_SDCA_8 ); - rt721->disable_irq = false; + scoped_guard(mutex, &rt721->disable_irq_lock) { +if (rt721->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ); +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ); + rt721->disable_irq = false; + } } -mutex_unlock (&rt721->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT721_PROBE_TIMEOUT );
sound/soc/codecs/rt721-sdca.c +2 -3
@@ -5,7 +5,7 @@// Copyright(c) 2024 Realtek Semiconductor Corp. // // - +#include <linux/cleanup.h> #include <linux/bitops.h> #include <sound/core.h> #include <linux/delay.h>
@@ -289,7 +289,7 @@ static void rt721_sdca_jack_preset(struct rt721_sdca_priv *rt721)static void rt721_sdca_jack_init (struct rt721_sdca_priv *rt721) { -mutex_lock (&rt721->calibrate_mutex); +guard (mutex)(&rt721->calibrate_mutex);if (rt721->hs_jack) {sdw_write_no_pm (rt721->slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 );
@@ -309,7 +309,6 @@ static void rt721_sdca_jack_init(struct rt721_sdca_priv *rt721)rt_sdca_index_update_bits (rt721->mbq_regmap,RT721_HDA_SDCA_FLOAT ,RT721_GE_REL_CTRL1 ,0x4000 ,0x4000 ); } -mutex_unlock (&rt721->calibrate_mutex); } static int rt721_sdca_set_jack_detect(struct snd_soc_component *component,
Signature · 1 line
2.43.0
PATCH v3 27/27 ASoC: codecs: rt722: 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/rt722-sdca-sdw.c | 29 ++++++++++++++++------------- sound/soc/codecs/rt722-sdca.c | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-)
sound/soc/codecs/rt722-sdca-sdw.c +16 -13
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/module.h>
@@ -513,13 +514,13 @@ static int rt722_sdca_dev_system_suspend(struct device *dev)* deferred work completes and before the parent disables * interrupts on the link */ -mutex_lock (&rt722_sdca->disable_irq_lock); - rt722_sdca->disable_irq = true; - ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , -SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); - ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , -SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); -mutex_unlock (&rt722_sdca->disable_irq_lock); + scoped_guard(mutex, &rt722_sdca->disable_irq_lock) { + rt722_sdca->disable_irq = true; + ret1 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ,0 ); + ret2 =sdw_update_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ,0 ); + }if (ret1 <0 || ret2 <0 ) {/* log but don't prevent suspend from happening */
@@ -541,13 +542,15 @@ static int rt722_sdca_dev_resume(struct device *dev)return 0 ;if (!slave->unattach_request) { -mutex_lock (&rt722->disable_irq_lock); -if (rt722->disable_irq == true) { -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 ,SDW_SCP_SDCA_INTMASK_SDCA_0 ); -sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 ,SDW_SCP_SDCA_INTMASK_SDCA_8 ); - rt722->disable_irq = false; + scoped_guard(mutex, &rt722->disable_irq_lock) { +if (rt722->disable_irq) { +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK1 , +SDW_SCP_SDCA_INTMASK_SDCA_0 ); +sdw_write_no_pm (slave,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_8 ); + rt722->disable_irq = false; + } } -mutex_unlock (&rt722->disable_irq_lock); } ret =sdw_slave_wait_for_init (slave,RT722_PROBE_TIMEOUT );
sound/soc/codecs/rt722-sdca.c +2 -2
@@ -6,6 +6,7 @@// // +#include <linux/cleanup.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/dmi.h>
@@ -294,7 +295,7 @@ static void rt722_sdca_btn_check_handler(struct work_struct *work)static void rt722_sdca_jack_init (struct rt722_sdca_priv *rt722) { -mutex_lock (&rt722->calibrate_mutex); +guard (mutex)(&rt722->calibrate_mutex);if (rt722->hs_jack) {/* set SCP_SDCA_IntMask1[0]=1 */ sdw_write_no_pm(rt722->slave, SDW_SCP_SDCA_INTMASK1,
@@ -317,7 +318,6 @@ static void rt722_sdca_jack_init(struct rt722_sdca_priv *rt722)rt722_sdca_index_update_bits (rt722,RT722_VENDOR_HDA_CTL ,RT722_GE_RELATED_CTL2 ,0x4000 ,0x4000 ); } -mutex_unlock (&rt722->calibrate_mutex); } static int rt722_sdca_set_jack_detect(struct snd_soc_component *component,
Signature · 1 line
2.43.0