[PATCH 12/27] ASoC: codecs: max98095: Use guard() for mutex locks

From: phucduc . bui

Date: Tue Jun 30 2026 - 02:37:53 EST


From: bui duc phuc <phucduc.bui@xxxxxxxxx>

Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.

Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/codecs/max98095.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index ced9bd4d94da..c47bfa2378b8 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -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);
--
2.43.0