]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: vx: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 15:00:18 +0000 (17:00 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:53:34 +0000 (13:53 +0200)
Replace the manual mutex lock/unlock pairs with guard() for code
simplification.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829150026.6379-8-tiwai@suse.de
sound/drivers/vx/vx_core.c
sound/drivers/vx/vx_mixer.c
sound/drivers/vx/vx_pcm.c
sound/drivers/vx/vx_uer.c

index 7f25fa7c04043cb1bc8b145008c4d10f6a755064..52b93407bfe3b840a3c35bbe138f56f53e973b5f 100644 (file)
@@ -344,12 +344,8 @@ int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh)
  */
 int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh)
 {
-       int err;
-
-       mutex_lock(&chip->lock);
-       err = vx_send_msg_nolock(chip, rmh);
-       mutex_unlock(&chip->lock);
-       return err;
+       guard(mutex)(&chip->lock);
+       return vx_send_msg_nolock(chip, rmh);
 }
 
 
@@ -404,12 +400,8 @@ int vx_send_rih_nolock(struct vx_core *chip, int cmd)
  */
 int vx_send_rih(struct vx_core *chip, int cmd)
 {
-       int err;
-
-       mutex_lock(&chip->lock);
-       err = vx_send_rih_nolock(chip, cmd);
-       mutex_unlock(&chip->lock);
-       return err;
+       guard(mutex)(&chip->lock);
+       return vx_send_rih_nolock(chip, cmd);
 }
 
 #define END_OF_RESET_WAIT_TIME         500     /* us */
@@ -481,13 +473,12 @@ static int vx_test_irq_src(struct vx_core *chip, unsigned int *ret)
        int err;
 
        vx_init_rmh(&chip->irq_rmh, CMD_TEST_IT);
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        err = vx_send_msg_nolock(chip, &chip->irq_rmh);
        if (err < 0)
                *ret = 0;
        else
                *ret = chip->irq_rmh.Stat[0];
-       mutex_unlock(&chip->lock);
        return err;
 }
 
index 0a51ecdc084a98621bf40b46b97f3737acf25caa..9dc5cecaa86a56126d9edda0bd1b1ffaab1a6d60 100644 (file)
@@ -25,9 +25,8 @@ static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int dat
        if (chip->chip_status & VX_STAT_IS_STALE)
                return;
 
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        chip->ops->write_codec(chip, codec, data);
-       mutex_unlock(&chip->lock);
 }
 
 /*
@@ -166,9 +165,8 @@ static void vx_change_audio_source(struct vx_core *chip, int src)
        if (chip->chip_status & VX_STAT_IS_STALE)
                return;
 
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        chip->ops->change_audio_source(chip, src);
-       mutex_unlock(&chip->lock);
 }
 
 
@@ -411,10 +409,10 @@ static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
 {
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int codec = kcontrol->id.index;
-       mutex_lock(&chip->mixer_mutex);
+
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->output_level[codec][0];
        ucontrol->value.integer.value[1] = chip->output_level[codec][1];
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -429,16 +427,14 @@ static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
        val[1] = ucontrol->value.integer.value[1];
        if (val[0] > vmax || val[1] > vmax)
                return -EINVAL;
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (val[0] != chip->output_level[codec][0] ||
            val[1] != chip->output_level[codec][1]) {
                vx_set_analog_output_level(chip, codec, val[0], val[1]);
                chip->output_level[codec][0] = val[0];
                chip->output_level[codec][1] = val[1];
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -490,14 +486,12 @@ static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
                if (ucontrol->value.enumerated.item[0] > 1)
                        return -EINVAL;
        }
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) {
                chip->audio_source_target = ucontrol->value.enumerated.item[0];
                vx_sync_audio_source(chip);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -534,14 +528,12 @@ static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
 
        if (ucontrol->value.enumerated.item[0] > 2)
                return -EINVAL;
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (chip->clock_mode != ucontrol->value.enumerated.item[0]) {
                chip->clock_mode = ucontrol->value.enumerated.item[0];
                vx_set_clock(chip, chip->freq);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -571,10 +563,9 @@ static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
        int audio = kcontrol->private_value & 0xff;
        int capture = (kcontrol->private_value >> 8) & 1;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio];
        ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1];
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -589,15 +580,13 @@ static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
        val[1] = ucontrol->value.integer.value[1];
        if (val[0] > CVAL_MAX || val[1] > CVAL_MAX)
                return -EINVAL;
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (val[0] != chip->audio_gain[capture][audio] ||
            val[1] != chip->audio_gain[capture][audio+1]) {
                vx_set_audio_gain(chip, audio, capture, val[0]);
                vx_set_audio_gain(chip, audio+1, capture, val[1]);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -606,10 +595,9 @@ static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_el
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int audio = kcontrol->private_value & 0xff;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->audio_monitor[audio];
        ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1];
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -624,17 +612,15 @@ static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
        if (val[0] > CVAL_MAX || val[1] > CVAL_MAX)
                return -EINVAL;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (val[0] != chip->audio_monitor[audio] ||
            val[1] != chip->audio_monitor[audio+1]) {
                vx_set_monitor_level(chip, audio, val[0],
                                     chip->audio_monitor_active[audio]);
                vx_set_monitor_level(chip, audio+1, val[1],
                                     chip->audio_monitor_active[audio+1]);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -645,10 +631,9 @@ static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int audio = kcontrol->private_value & 0xff;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->audio_active[audio];
        ucontrol->value.integer.value[1] = chip->audio_active[audio+1];
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -657,17 +642,15 @@ static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int audio = kcontrol->private_value & 0xff;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (ucontrol->value.integer.value[0] != chip->audio_active[audio] ||
            ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) {
                vx_set_audio_switch(chip, audio,
                                    !!ucontrol->value.integer.value[0]);
                vx_set_audio_switch(chip, audio+1,
                                    !!ucontrol->value.integer.value[1]);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -676,10 +659,9 @@ static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int audio = kcontrol->private_value & 0xff;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio];
        ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1];
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -688,17 +670,15 @@ static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
        int audio = kcontrol->private_value & 0xff;
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] ||
            ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) {
                vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
                                     !!ucontrol->value.integer.value[0]);
                vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
                                     !!ucontrol->value.integer.value[1]);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
@@ -754,12 +734,11 @@ static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
 {
        struct vx_core *chip = snd_kcontrol_chip(kcontrol);
 
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff;
        ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff;
        ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff;
        ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff;
-       mutex_unlock(&chip->mixer_mutex);
         return 0;
 }
 
@@ -781,14 +760,12 @@ static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
              (ucontrol->value.iec958.status[1] << 8) |
              (ucontrol->value.iec958.status[2] << 16) |
              (ucontrol->value.iec958.status[3] << 24);
-       mutex_lock(&chip->mixer_mutex);
+       guard(mutex)(&chip->mixer_mutex);
        if (chip->uer_bits != val) {
                chip->uer_bits = val;
                vx_set_iec958_status(chip, val);
-               mutex_unlock(&chip->mixer_mutex);
                return 1;
        }
-       mutex_unlock(&chip->mixer_mutex);
        return 0;
 }
 
index defc489494af752a8f69a4d2a6bca1d2bf697e52..7fd8f413d6cfcc716ea97147fb6a354cbbed865c 100644 (file)
@@ -630,12 +630,11 @@ static int vx_pcm_playback_transfer_chunk(struct vx_core *chip,
        /* we don't need irqsave here, because this function
         * is called from either trigger callback or irq handler
         */
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        vx_pseudo_dma_write(chip, runtime, pipe, size);
        err = vx_notify_end_of_buffer(chip, pipe);
        /* disconnect the host, SIZE_HBUF command always switches to the stream mode */
        vx_send_rih_nolock(chip, IRQ_CONNECT_STREAM_NEXT);
-       mutex_unlock(&chip->lock);
        return err;
 }
 
index 3eca22151225b5a373d4e7c7cfc0e3b88958fd24..1d90db3b0abd03f1cbfe3beaedd6b7b8ebdf43ce 100644 (file)
@@ -49,7 +49,7 @@ static int vx_read_one_cbit(struct vx_core *chip, int index)
 {
        int val;
 
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        if (chip->type >= VX_TYPE_VXPOCKET) {
                vx_outb(chip, CSUER, 1); /* read */
                vx_outb(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK);
@@ -59,7 +59,6 @@ static int vx_read_one_cbit(struct vx_core *chip, int index)
                vx_outl(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK);
                val = (vx_inl(chip, RUER) >> 7) & 0x01;
        }
-       mutex_unlock(&chip->lock);
        return val;
 }
 
@@ -71,7 +70,7 @@ static int vx_read_one_cbit(struct vx_core *chip, int index)
 static void vx_write_one_cbit(struct vx_core *chip, int index, int val)
 {
        val = !!val;    /* 0 or 1 */
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        if (vx_is_pcmcia(chip)) {
                vx_outb(chip, CSUER, 0); /* write */
                vx_outb(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK));
@@ -79,7 +78,6 @@ static void vx_write_one_cbit(struct vx_core *chip, int index, int val)
                vx_outl(chip, CSUER, 0); /* write */
                vx_outl(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK));
        }
-       mutex_unlock(&chip->lock);
 }
 
 /*
@@ -178,10 +176,10 @@ static void vx_change_clock_source(struct vx_core *chip, int source)
 {
        /* we mute DAC to prevent clicks */
        vx_toggle_dac_mute(chip, 1);
-       mutex_lock(&chip->lock);
-       chip->ops->set_clock_source(chip, source);
-       chip->clock_source = source;
-       mutex_unlock(&chip->lock);
+       scoped_guard(mutex, &chip->lock) {
+               chip->ops->set_clock_source(chip, source);
+               chip->clock_source = source;
+       }
        /* unmute */
        vx_toggle_dac_mute(chip, 0);
 }
@@ -198,7 +196,7 @@ void vx_set_internal_clock(struct vx_core *chip, unsigned int freq)
        clock = vx_calc_clock_from_freq(chip, freq);
        dev_dbg(chip->card->dev,
                "set internal clock to 0x%x from freq %d\n", clock, freq);
-       mutex_lock(&chip->lock);
+       guard(mutex)(&chip->lock);
        if (vx_is_pcmcia(chip)) {
                vx_outb(chip, HIFREQ, (clock >> 8) & 0x0f);
                vx_outb(chip, LOFREQ, clock & 0xff);
@@ -206,7 +204,6 @@ void vx_set_internal_clock(struct vx_core *chip, unsigned int freq)
                vx_outl(chip, HIFREQ, (clock >> 8) & 0x0f);
                vx_outl(chip, LOFREQ, clock & 0xff);
        }
-       mutex_unlock(&chip->lock);
 }