ALSA: Use auto-cleanup for misc drivers
Subsystems (7)
cover ALSA: Use auto-cleanup for misc drivers
Finally, this is the last piece in my large patch series -- applying the auto-cleanup macros to the remaining legacy stuff such as sound/i2c, sound/synth, etc. Again, merely code cleanup / refactoring and no functional changes are expected.
Takashi
===
Takashi Iwai (19):
ALSA: i2c: Use guard() for mutex locks
ALSA: i2c: Use guard() for spin locks
ALSA: synth: Use guard() for mutex locks
ALSA: synth: Use guard() for spin locks
ALSA: synth: Use guard() for preset locks
ALSA: x86: Use guard() for mutex locks
ALSA: x86: Use guard() for spin locks
ALSA: xen: Use guard() for mutex locks
ALSA: at73c213: Use guard() for mutex locks
ALSA: pdaudiocf: Use guard() for mutex locks
ALSA: vxpocket: Use guard() for mutex locks
ALSA: sparc: Use guard() for mutex locks
ALSA: aoa: Use guard() for mutex locks
ALSA: aaci: Use guard() for mutex locks
ALSA: pxa2xx: Use guard() for mutex locks
ALSA: atmel: Use guard() for mutex locks
ALSA: ac97bus: Use guard() for mutex locks
ALSA: virtio: Use guard() for spin locks
ALSA: misc: Use guard() for spin locks
include/sound/soundfont.h | 18 ++++ sound/ac97/bus.c | 22 ++--- sound/aoa/codecs/onyx.c | 104 +++++++-------------- sound/aoa/codecs/tas.c | 113 ++++++++--------------- sound/aoa/core/gpio-feature.c | 20 ++--- sound/aoa/core/gpio-pmf.c | 26 ++---- sound/aoa/soundbus/i2sbus/pcm.c | 76 ++++++---------- sound/arm/aaci.c | 20 ++--- sound/arm/pxa2xx-ac97-lib.c | 12 +-- sound/atmel/ac97c.c | 18 ++-- sound/core/misc.c | 25 +++--- sound/i2c/other/ak4113.c | 54 ++++++----- sound/i2c/other/ak4114.c | 39 ++++---- sound/i2c/other/ak4117.c | 40 ++++----- sound/pcmcia/pdaudiocf/pdaudiocf_core.c | 3 +- sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c | 25 +++--- sound/pcmcia/vx/vxp_mixer.c | 9 +- sound/pcmcia/vx/vxp_ops.c | 6 +- sound/sparc/cs4231.c | 21 ++--- sound/spi/at73c213.c | 39 +++----- sound/synth/emux/emux_effect.c | 29 +++--- sound/synth/emux/emux_proc.c | 6 +- sound/synth/emux/emux_seq.c | 17 ++-- sound/synth/emux/emux_synth.c | 54 +++-------- sound/synth/emux/soundfont.c | 115 +++++++----------------- sound/synth/util_mem.c | 17 ++-- sound/virtio/virtio_card.c | 8 +- sound/virtio/virtio_ctl_msg.c | 23 ++--- sound/virtio/virtio_pcm.c | 8 +- sound/virtio/virtio_pcm_msg.c | 17 +--- sound/virtio/virtio_pcm_ops.c | 56 ++++-------- sound/x86/intel_hdmi_audio.c | 109 +++++++++------------- sound/xen/xen_snd_front.c | 80 ++++++++--------- sound/xen/xen_snd_front_evtchnl.c | 33 ++++--- 34 files changed, 468 insertions(+), 794 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/19 ALSA: i2c: Use guard() for mutex locks
Replace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/i2c/other/ak4113.c | 6 +++--- sound/i2c/other/ak4114.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
sound/i2c/other/ak4113.c +3 -3
@@ -127,9 +127,9 @@ void snd_ak4113_reinit(struct ak4113 *chip) {if (atomic_inc_return (&chip->wq_processing) ==1 )cancel_delayed_work_sync (&chip->work); -mutex_lock (&chip->reinit_mutex); -ak4113_init_regs (chip); -mutex_unlock (&chip->reinit_mutex); + scoped_guard(mutex, &chip->reinit_mutex) { +ak4113_init_regs (chip); + }/* bring up statistics / event queing */ if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 );
sound/i2c/other/ak4114.c +3 -3
@@ -132,9 +132,9 @@ void snd_ak4114_reinit(struct ak4114 *chip) {if (atomic_inc_return (&chip->wq_processing) ==1 )cancel_delayed_work_sync (&chip->work); -mutex_lock (&chip->reinit_mutex); -ak4114_init_regs (chip); -mutex_unlock (&chip->reinit_mutex); + scoped_guard(mutex, &chip->reinit_mutex) { +ak4114_init_regs (chip); + }/* bring up statistics / event queing */ if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 );
Signature · 1 line
2.50.1
PATCH 2/19 ALSA: i2c: Use guard() for spin locks
In reply to Takashi IwaiClean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/i2c/other/ak4113.c | 48 +++++++++++++++++++--------------------- sound/i2c/other/ak4114.c | 33 ++++++++++++++------------- sound/i2c/other/ak4117.c | 40 ++++++++++++++++----------------- 3 files changed, 58 insertions(+), 63 deletions(-)
sound/i2c/other/ak4113.c +23 -25
@@ -185,11 +185,10 @@ static int snd_ak4113_in_error_get(struct snd_kcontrol *kcontrol, {struct ak4113 *chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); ucontrol->value.integer.value[0 ] = chip->errors[kcontrol->private_value]; chip->errors[kcontrol->private_value] =0 ; -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -235,14 +234,13 @@ static int snd_ak4113_rx_put(struct snd_kcontrol *kcontrol,int change;u8 old_val; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); old_val = chip->regmap[AK4113_REG_IO1 ]; change = ucontrol->value.integer.value[0 ] !=AK4113_IPS (old_val);if (change)reg_write (chip,AK4113_REG_IO1 , (old_val & (~AK4113_IPS (0xff ))) | (AK4113_IPS (ucontrol->value.integer.value[0 ]))); -spin_unlock_irq (&chip->lock);return change; }
@@ -532,27 +530,27 @@ int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags) goto __rate; rcs0 =reg_read (ak4113,AK4113_REG_RCS0 ); rcs2 =reg_read (ak4113,AK4113_REG_RCS2 ); -spin_lock_irqsave (&ak4113->lock, _flags); -if (rcs0 &AK4113_PAR ) - ak4113->errors[AK4113_PARITY_ERRORS ]++; -if (rcs0 &AK4113_V ) - ak4113->errors[AK4113_V_BIT_ERRORS ]++; -if (rcs2 &AK4113_CCRC ) - ak4113->errors[AK4113_CCRC_ERRORS ]++; -if (rcs2 &AK4113_QCRC ) - ak4113->errors[AK4113_QCRC_ERRORS ]++; - c0 = (ak4113->rcs0 & (AK4113_QINT |AK4113_CINT |AK4113_STC | -AK4113_AUDION |AK4113_AUTO |AK4113_UNLCK )) ^ - (rcs0 & (AK4113_QINT |AK4113_CINT |AK4113_STC | -AK4113_AUDION |AK4113_AUTO |AK4113_UNLCK )); - c1 = (ak4113->rcs1 & (AK4113_DTSCD |AK4113_NPCM |AK4113_PEM | -AK4113_DAT |0xf0 )) ^ - (rcs1 & (AK4113_DTSCD |AK4113_NPCM |AK4113_PEM | -AK4113_DAT |0xf0 )); - ak4113->rcs0 = rcs0 & ~(AK4113_QINT |AK4113_CINT |AK4113_STC ); - ak4113->rcs1 = rcs1; - ak4113->rcs2 = rcs2; -spin_unlock_irqrestore (&ak4113->lock, _flags); + scoped_guard(spinlock_irqsave, &ak4113->lock) { +if (rcs0 &AK4113_PAR ) + ak4113->errors[AK4113_PARITY_ERRORS ]++; +if (rcs0 &AK4113_V ) + ak4113->errors[AK4113_V_BIT_ERRORS ]++; +if (rcs2 &AK4113_CCRC ) + ak4113->errors[AK4113_CCRC_ERRORS ]++; +if (rcs2 &AK4113_QCRC ) + ak4113->errors[AK4113_QCRC_ERRORS ]++; + c0 = (ak4113->rcs0 & (AK4113_QINT |AK4113_CINT |AK4113_STC | +AK4113_AUDION |AK4113_AUTO |AK4113_UNLCK )) ^ + (rcs0 & (AK4113_QINT |AK4113_CINT |AK4113_STC | +AK4113_AUDION |AK4113_AUTO |AK4113_UNLCK )); + c1 = (ak4113->rcs1 & (AK4113_DTSCD |AK4113_NPCM |AK4113_PEM | +AK4113_DAT |0xf0 )) ^ + (rcs1 & (AK4113_DTSCD |AK4113_NPCM |AK4113_PEM | +AK4113_DAT |0xf0 )); + ak4113->rcs0 = rcs0 & ~(AK4113_QINT |AK4113_CINT |AK4113_STC ); + ak4113->rcs1 = rcs1; + ak4113->rcs2 = rcs2; + }if (rcs0 &AK4113_PAR ) snd_ctl_notify(ak4113->card, SNDRV_CTL_EVENT_MASK_VALUE,
sound/i2c/other/ak4114.c +16 -17
@@ -170,11 +170,10 @@ static int snd_ak4114_in_error_get(struct snd_kcontrol *kcontrol, {struct ak4114 *chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); ucontrol->value.integer.value[0 ] = chip->errors[kcontrol->private_value]; chip->errors[kcontrol->private_value] =0 ; -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -552,21 +551,21 @@ int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags)if (flags &AK4114_CHECK_NO_STAT ) goto __rate; rcs0 =reg_read (ak4114,AK4114_REG_RCS0 ); -spin_lock_irqsave (&ak4114->lock, _flags); -if (rcs0 &AK4114_PAR ) - ak4114->errors[AK4114_PARITY_ERRORS ]++; -if (rcs1 &AK4114_V ) - ak4114->errors[AK4114_V_BIT_ERRORS ]++; -if (rcs1 &AK4114_CCRC ) - ak4114->errors[AK4114_CCRC_ERRORS ]++; -if (rcs1 &AK4114_QCRC ) - ak4114->errors[AK4114_QCRC_ERRORS ]++; - c0 = (ak4114->rcs0 & (AK4114_QINT |AK4114_CINT |AK4114_PEM |AK4114_AUDION |AK4114_AUTO |AK4114_UNLCK )) ^ - (rcs0 & (AK4114_QINT |AK4114_CINT |AK4114_PEM |AK4114_AUDION |AK4114_AUTO |AK4114_UNLCK )); - c1 = (ak4114->rcs1 &0xf0 ) ^ (rcs1 &0xf0 ); - ak4114->rcs0 = rcs0 & ~(AK4114_QINT |AK4114_CINT ); - ak4114->rcs1 = rcs1; -spin_unlock_irqrestore (&ak4114->lock, _flags); + scoped_guard(spinlock_irqsave, &ak4114->lock) { +if (rcs0 &AK4114_PAR ) + ak4114->errors[AK4114_PARITY_ERRORS ]++; +if (rcs1 &AK4114_V ) + ak4114->errors[AK4114_V_BIT_ERRORS ]++; +if (rcs1 &AK4114_CCRC ) + ak4114->errors[AK4114_CCRC_ERRORS ]++; +if (rcs1 &AK4114_QCRC ) + ak4114->errors[AK4114_QCRC_ERRORS ]++; + c0 = (ak4114->rcs0 & (AK4114_QINT |AK4114_CINT |AK4114_PEM |AK4114_AUDION |AK4114_AUTO |AK4114_UNLCK )) ^ + (rcs0 & (AK4114_QINT |AK4114_CINT |AK4114_PEM |AK4114_AUDION |AK4114_AUTO |AK4114_UNLCK )); + c1 = (ak4114->rcs1 &0xf0 ) ^ (rcs1 &0xf0 ); + ak4114->rcs0 = rcs0 & ~(AK4114_QINT |AK4114_CINT ); + ak4114->rcs1 = rcs1; + }ak4114_notify (ak4114, rcs0, rcs1, c0, c1);if (ak4114->change_callback && (c0 | c1) !=0 )
sound/i2c/other/ak4117.c +19 -21
@@ -144,11 +144,10 @@ static int snd_ak4117_in_error_get(struct snd_kcontrol *kcontrol, {struct ak4117 *chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); ucontrol->value.integer.value[0 ] = chip->errors[kcontrol->private_value]; chip->errors[kcontrol->private_value] =0 ; -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -192,12 +191,11 @@ static int snd_ak4117_rx_put(struct snd_kcontrol *kcontrol,int change;u8 old_val; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); old_val = chip->regmap[AK4117_REG_IO ]; change = !!ucontrol->value.integer.value[0 ] != ((old_val &AK4117_IPS ) ?1 :0 );if (change)reg_write (chip,AK4117_REG_IO , (old_val & ~AK4117_IPS ) | (ucontrol->value.integer.value[0 ] ?AK4117_IPS :0 )); -spin_unlock_irq (&chip->lock);return change; }
@@ -441,23 +439,23 @@ int snd_ak4117_check_rate_and_errors(struct ak4117 *ak4117, unsigned int flags) goto __rate; rcs0 =reg_read (ak4117,AK4117_REG_RCS0 ); rcs2 =reg_read (ak4117,AK4117_REG_RCS2 ); -spin_lock_irqsave (&ak4117->lock, _flags); -if (rcs0 &AK4117_PAR ) - ak4117->errors[AK4117_PARITY_ERRORS ]++; -if (rcs0 &AK4117_V ) - ak4117->errors[AK4117_V_BIT_ERRORS ]++; -if (rcs2 &AK4117_CCRC ) - ak4117->errors[AK4117_CCRC_ERRORS ]++; -if (rcs2 &AK4117_QCRC ) - ak4117->errors[AK4117_QCRC_ERRORS ]++; - c0 = (ak4117->rcs0 & (AK4117_QINT |AK4117_CINT |AK4117_STC |AK4117_AUDION |AK4117_AUTO |AK4117_UNLCK )) ^ - (rcs0 & (AK4117_QINT |AK4117_CINT |AK4117_STC |AK4117_AUDION |AK4117_AUTO |AK4117_UNLCK )); - c1 = (ak4117->rcs1 & (AK4117_DTSCD |AK4117_NPCM |AK4117_PEM |0x0f )) ^ - (rcs1 & (AK4117_DTSCD |AK4117_NPCM |AK4117_PEM |0x0f )); - ak4117->rcs0 = rcs0 & ~(AK4117_QINT |AK4117_CINT |AK4117_STC ); - ak4117->rcs1 = rcs1; - ak4117->rcs2 = rcs2; -spin_unlock_irqrestore (&ak4117->lock, _flags); + scoped_guard(spinlock_irqsave, &ak4117->lock) { +if (rcs0 &AK4117_PAR ) + ak4117->errors[AK4117_PARITY_ERRORS ]++; +if (rcs0 &AK4117_V ) + ak4117->errors[AK4117_V_BIT_ERRORS ]++; +if (rcs2 &AK4117_CCRC ) + ak4117->errors[AK4117_CCRC_ERRORS ]++; +if (rcs2 &AK4117_QCRC ) + ak4117->errors[AK4117_QCRC_ERRORS ]++; + c0 = (ak4117->rcs0 & (AK4117_QINT |AK4117_CINT |AK4117_STC |AK4117_AUDION |AK4117_AUTO |AK4117_UNLCK )) ^ + (rcs0 & (AK4117_QINT |AK4117_CINT |AK4117_STC |AK4117_AUDION |AK4117_AUTO |AK4117_UNLCK )); + c1 = (ak4117->rcs1 & (AK4117_DTSCD |AK4117_NPCM |AK4117_PEM |0x0f )) ^ + (rcs1 & (AK4117_DTSCD |AK4117_NPCM |AK4117_PEM |0x0f )); + ak4117->rcs0 = rcs0 & ~(AK4117_QINT |AK4117_CINT |AK4117_STC ); + ak4117->rcs1 = rcs1; + ak4117->rcs2 = rcs2; + }if (rcs0 &AK4117_PAR )snd_ctl_notify (ak4117->card,SNDRV_CTL_EVENT_MASK_VALUE , &ak4117->kctls[0 ]->id);
Signature · 1 line
2.50.1
PATCH 3/19 ALSA: synth: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/synth/emux/emux_proc.c | 6 ++---- sound/synth/emux/emux_seq.c | 17 +++++------------ sound/synth/util_mem.c | 17 +++++------------ 3 files changed, 12 insertions(+), 28 deletions(-)
sound/synth/emux/emux_proc.c +2 -4
@@ -19,7 +19,7 @@ snd_emux_proc_info_read(struct snd_info_entry *entry,int i; emu = entry->private_data; -mutex_lock (&emu->register_mutex); +guard (mutex)(&emu->register_mutex);if (emu->name)snd_iprintf (buf,"Device: %s\n" , emu->name);snd_iprintf (buf,"Ports: %d\n" , emu->num_ports);
@@ -38,13 +38,12 @@ snd_emux_proc_info_read(struct snd_info_entry *entry,snd_iprintf (buf,"Memory Size: 0\n" ); }if (emu->sflist) { -mutex_lock (&emu->sflist->presets_mutex); +guard (mutex)(&emu->sflist->presets_mutex);snd_iprintf (buf,"SoundFonts: %d\n" , emu->sflist->fonts_size);snd_iprintf (buf,"Instruments: %d\n" , emu->sflist->zone_counter);snd_iprintf (buf,"Samples: %d\n" , emu->sflist->sample_counter);snd_iprintf (buf,"Locked Instruments: %d\n" , emu->sflist->zone_locked);snd_iprintf (buf,"Locked Samples: %d\n" , emu->sflist->sample_locked); -mutex_unlock (&emu->sflist->presets_mutex); }#if 0 /* debug */ if (emu->voices[0 ].state !=SNDRV_EMUX_ST_OFF && emu->voices[0 ].ch >=0 ) {
@@ -85,7 +84,6 @@ snd_emux_proc_info_read(struct snd_info_entry *entry, snd_iprintf(buf, "sample_mode=%x, rate=%x\n", vp->reg.sample_mode, vp->reg.rate_offset); }#endif -mutex_unlock (&emu->register_mutex); }
sound/synth/emux/emux_seq.c +5 -12
@@ -272,12 +272,8 @@ __snd_emux_inc_count(struct snd_emux *emu)int snd_emux_inc_count (struct snd_emux *emu) { -int ret; - -mutex_lock (&emu->register_mutex); - ret =__snd_emux_inc_count (emu); -mutex_unlock (&emu->register_mutex); -return ret; +guard (mutex)(&emu->register_mutex); +return __snd_emux_inc_count (emu); }/*
@@ -295,9 +291,8 @@ __snd_emux_dec_count(struct snd_emux *emu)void snd_emux_dec_count (struct snd_emux *emu) { -mutex_lock (&emu->register_mutex); +guard (mutex)(&emu->register_mutex);__snd_emux_dec_count (emu); -mutex_unlock (&emu->register_mutex); }/*
@@ -316,10 +311,9 @@ snd_emux_use(void *private_data, struct snd_seq_port_subscribe *info)if (snd_BUG_ON (!emu))return -EINVAL ; -mutex_lock (&emu->register_mutex); +guard (mutex)(&emu->register_mutex);snd_emux_init_port (p);__snd_emux_inc_count (emu); -mutex_unlock (&emu->register_mutex);return 0 ; }
@@ -339,10 +333,9 @@ snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info)if (snd_BUG_ON (!emu))return -EINVAL ; -mutex_lock (&emu->register_mutex); +guard (mutex)(&emu->register_mutex);snd_emux_sounds_off_all (p);__snd_emux_dec_count (emu); -mutex_unlock (&emu->register_mutex);return 0 ; }
sound/synth/util_mem.c +5 -12
@@ -124,11 +124,8 @@ __snd_util_memblk_new(struct snd_util_memhdr *hdr, unsigned int units,struct snd_util_memblk *snd_util_mem_alloc (struct snd_util_memhdr *hdr,int size) { -struct snd_util_memblk *blk; -mutex_lock (&hdr->block_mutex); - blk =__snd_util_mem_alloc (hdr, size); -mutex_unlock (&hdr->block_mutex); -return blk; +guard (mutex)(&hdr->block_mutex); +return __snd_util_mem_alloc (hdr, size); }
@@ -153,9 +150,8 @@ int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)if (snd_BUG_ON (!hdr || !blk))return -EINVAL ; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex);__snd_util_mem_free (hdr, blk); -mutex_unlock (&hdr->block_mutex);return 0 ; }
@@ -164,11 +160,8 @@ int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)*/ int snd_util_mem_avail (struct snd_util_memhdr *hdr) { -unsigned int size; -mutex_lock (&hdr->block_mutex); - size = hdr->size - hdr->used; -mutex_unlock (&hdr->block_mutex); -return size; +guard (mutex)(&hdr->block_mutex); +return hdr->size - hdr->used; }
Signature · 1 line
2.50.1
PATCH 4/19 ALSA: synth: Use guard() for spin locks
In reply to Takashi IwaiClean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/synth/emux/emux_effect.c | 29 ++++++++-------- sound/synth/emux/emux_synth.c | 54 +++++++---------------------- sound/synth/emux/soundfont.c | 63 ++++++++++++---------------------- 3 files changed, 49 insertions(+), 97 deletions(-)
sound/synth/emux/emux_effect.c +14 -15
@@ -168,7 +168,6 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan,unsigned char *srcp, *origp;struct snd_emux *emu;struct snd_emux_effect_table *fx; -unsigned long flags; emu = port->emu; fx = chan->private;
@@ -195,22 +194,22 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan, offset++;#endif /* modify the register values */ -spin_lock_irqsave (&emu->voice_lock, flags); -for (i =0 ; i < emu->max_voices; i++) { -struct snd_emux_voice *vp = &emu->voices[i]; -if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) -continue ; - srcp = (unsigned char *)&vp->reg.parm + offset; - origp = (unsigned char *)&vp->zone->v.parm + offset; -if (parm_defs[i].type &PARM_IS_BYTE ) { - *srcp = *origp; -effect_set_byte (srcp, chan, type); - }else { - *(unsigned short *)srcp = *(unsigned short *)origp; -effect_set_word ((unsigned short *)srcp, chan, type); + scoped_guard(spinlock_irqsave, &emu->voice_lock) { +for (i =0 ; i < emu->max_voices; i++) { +struct snd_emux_voice *vp = &emu->voices[i]; +if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) +continue ; + srcp = (unsigned char *)&vp->reg.parm + offset; + origp = (unsigned char *)&vp->zone->v.parm + offset; +if (parm_defs[i].type &PARM_IS_BYTE ) { + *srcp = *origp; +effect_set_byte (srcp, chan, type); + }else { + *(unsigned short *)srcp = *(unsigned short *)origp; +effect_set_word ((unsigned short *)srcp, chan, type); + } } } -spin_unlock_irqrestore (&emu->voice_lock, flags);/* activate them */ snd_emux_update_channel (port, chan, parm_defs[type].update);
sound/synth/emux/emux_synth.c +13 -41
250 lines not on this page · raw message
sound/synth/emux/soundfont.c +22 -41
136 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 5/19 ALSA: synth: Use guard() for preset locks
In reply to Takashi IwaiDefine a macro for the preset locking/unlocking pairs for soundfont using guard() macro as a further code cleanup.
The new macro is put in soundfont.h (and some function renames) along with it for avoiding unnecessary troubles with clang.
--- include/sound/soundfont.h | 18 ++++++++++++ sound/synth/emux/soundfont.c | 56 ++++++++---------------------------- 2 files changed, 30 insertions(+), 44 deletions(-)
include/sound/soundfont.h +18 -0
@@ -114,5 +114,23 @@ int snd_sf_calc_parm_decay(int msec);extern int snd_sf_vol_table[128 ];int snd_sf_linear_to_log (unsigned int amount,int offset,int ratio); +/* lock access to sflist */ +static inline void snd_soundfont_lock_preset (struct snd_sf_list *sflist) +{ +mutex_lock (&sflist->presets_mutex); +guard (spinlock_irqsave)(&sflist->lock); + sflist->presets_locked =1 ; +} + +/* remove lock */ +static inline void snd_soundfont_unlock_preset (struct snd_sf_list *sflist) +{ +guard (spinlock_irqsave)(&sflist->lock); + sflist->presets_locked =0 ; +mutex_unlock (&sflist->presets_mutex); +} + +DEFINE_GUARD(snd_soundfont_lock_preset, struct snd_sf_list *, + snd_soundfont_lock_preset(_T), snd_soundfont_unlock_preset(_T))#endif /* __SOUND_SOUNDFONT_H */
sound/synth/emux/soundfont.c +12 -44
112 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 6/19 ALSA: x86: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/x86/intel_hdmi_audio.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
sound/x86/intel_hdmi_audio.c +5 -11
@@ -554,16 +554,13 @@ static int had_chmap_ctl_get(struct snd_kcontrol *kcontrol,memset (ucontrol->value.integer.value,0 ,sizeof (long ) *HAD_MAX_CHANNEL ); -mutex_lock (&intelhaddata->mutex); -if (!intelhaddata->chmap->chmap) { -mutex_unlock (&intelhaddata->mutex); +guard (mutex)(&intelhaddata->mutex); +if (!intelhaddata->chmap->chmap)return 0 ; - } chmap = intelhaddata->chmap->chmap;for (i =0 ; i < chmap->channels; i++) ucontrol->value.integer.value[i] = chmap->map[i]; -mutex_unlock (&intelhaddata->mutex);return 0 ; }
@@ -1394,14 +1391,13 @@ static int had_iec958_get(struct snd_kcontrol *kcontrol, {struct snd_intelhad *intelhaddata =snd_kcontrol_chip (kcontrol); -mutex_lock (&intelhaddata->mutex); +guard (mutex)(&intelhaddata->mutex); ucontrol->value.iec958.status[0 ] = (intelhaddata->aes_bits >>0 ) &0xff ; ucontrol->value.iec958.status[1 ] = (intelhaddata->aes_bits >>8 ) &0xff ; ucontrol->value.iec958.status[2 ] = (intelhaddata->aes_bits >>16 ) &0xff ; ucontrol->value.iec958.status[3 ] = (intelhaddata->aes_bits >>24 ) &0xff ; -mutex_unlock (&intelhaddata->mutex);return 0 ; }
@@ -1426,12 +1422,11 @@ static int had_iec958_put(struct snd_kcontrol *kcontrol, (ucontrol->value.iec958.status[1 ] <<8 ) | (ucontrol->value.iec958.status[2 ] <<16 ) | (ucontrol->value.iec958.status[3 ] <<24 ); -mutex_lock (&intelhaddata->mutex); +guard (mutex)(&intelhaddata->mutex);if (intelhaddata->aes_bits != val) { intelhaddata->aes_bits = val; changed =1 ; } -mutex_unlock (&intelhaddata->mutex);return changed; }
@@ -1448,10 +1443,9 @@ static int had_ctl_eld_get(struct snd_kcontrol *kcontrol, {struct snd_intelhad *intelhaddata =snd_kcontrol_chip (kcontrol); -mutex_lock (&intelhaddata->mutex); +guard (mutex)(&intelhaddata->mutex);memcpy (ucontrol->value.bytes.data, intelhaddata->eld,HDMI_MAX_ELD_BYTES ); -mutex_unlock (&intelhaddata->mutex);return 0 ; }
Signature · 1 line
2.50.1
PATCH 7/19 ALSA: x86: Use guard() for spin locks
In reply to Takashi IwaiClean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/x86/intel_hdmi_audio.c | 93 +++++++++++++++--------------------- 1 file changed, 39 insertions(+), 54 deletions(-)
sound/x86/intel_hdmi_audio.c +39 -54
@@ -171,13 +171,11 @@ static struct snd_pcm_substream * had_substream_get(struct snd_intelhad *intelhaddata) {struct snd_pcm_substream *substream; -unsigned long flags; -spin_lock_irqsave (&intelhaddata->had_spinlock, flags); +guard (spinlock_irqsave)(&intelhaddata->had_spinlock); substream = intelhaddata->stream_info.substream;if (substream) intelhaddata->stream_info.substream_refcount++; -spin_unlock_irqrestore (&intelhaddata->had_spinlock, flags);return substream; }
@@ -186,11 +184,8 @@ had_substream_get(struct snd_intelhad *intelhaddata)*/ static void had_substream_put (struct snd_intelhad *intelhaddata) { -unsigned long flags; - -spin_lock_irqsave (&intelhaddata->had_spinlock, flags); +guard (spinlock_irqsave)(&intelhaddata->had_spinlock); intelhaddata->stream_info.substream_refcount--; -spin_unlock_irqrestore (&intelhaddata->had_spinlock, flags); }static u32 had_config_offset (int pipe)
@@ -946,10 +941,9 @@ static int had_process_ringbuf(struct snd_pcm_substream *substream, struct snd_intelhad *intelhaddata) {int len, processed; -unsigned long flags; processed =0 ; -spin_lock_irqsave (&intelhaddata->had_spinlock, flags); +guard (spinlock_irqsave)(&intelhaddata->had_spinlock);for (;;) {/* get the remaining bytes on the buffer */ had_read_register(intelhaddata,
@@ -958,25 +952,20 @@ static int had_process_ringbuf(struct snd_pcm_substream *substream,if (len <0 || len > intelhaddata->period_bytes) {dev_dbg (intelhaddata->dev,"Invalid buf length %d\n" , len); - len = -EPIPE ; - goto out; +return -EPIPE ; }if (len >0 )/* OK, this is the current buffer */ break ;/* len=0 => already empty, check the next buffer */ -if (++processed >= intelhaddata->num_bds) { - len = -EPIPE ;/* all empty? - report underrun */ - goto out; - } +if (++processed >= intelhaddata->num_bds) +return -EPIPE ;/* all empty? - report underrun */ had_advance_ringbuf (substream, intelhaddata); } len = intelhaddata->period_bytes - len; len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head; - out: -spin_unlock_irqrestore (&intelhaddata->had_spinlock, flags);return len; }
@@ -1092,10 +1081,10 @@ static int had_pcm_open(struct snd_pcm_substream *substream) goto error;/* expose PCM substream */ -spin_lock_irq (&intelhaddata->had_spinlock); - intelhaddata->stream_info.substream = substream; - intelhaddata->stream_info.substream_refcount++; -spin_unlock_irq (&intelhaddata->had_spinlock); + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { + intelhaddata->stream_info.substream = substream; + intelhaddata->stream_info.substream_refcount++; + }return retval; error:
@@ -1153,7 +1142,7 @@ static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd) intelhaddata =snd_pcm_substream_chip (substream); -spin_lock (&intelhaddata->had_spinlock); +guard (spinlock)(&intelhaddata->had_spinlock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :
@@ -1172,7 +1161,6 @@ static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd)default : retval = -EINVAL ; } -spin_unlock (&intelhaddata->had_spinlock);return retval; }
@@ -1311,21 +1299,20 @@ static void had_process_hot_plug(struct snd_intelhad *intelhaddata) {struct snd_pcm_substream *substream; -spin_lock_irq (&intelhaddata->had_spinlock); -if (intelhaddata->connected) { -dev_dbg (intelhaddata->dev,"Device already connected\n" ); -spin_unlock_irq (&intelhaddata->had_spinlock); -return ; - } + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { +if (intelhaddata->connected) { +dev_dbg (intelhaddata->dev,"Device already connected\n" ); +return ; + } -/* Disable Audio */ -had_enable_audio (intelhaddata, false); +/* Disable Audio */ +had_enable_audio (intelhaddata, false); - intelhaddata->connected = true; -dev_dbg (intelhaddata->dev, -"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n" , + intelhaddata->connected = true; +dev_dbg (intelhaddata->dev, +"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n" , __func__, __LINE__); -spin_unlock_irq (&intelhaddata->had_spinlock); + }had_build_channel_allocation_map (intelhaddata);
@@ -1344,22 +1331,20 @@ static void had_process_hot_unplug(struct snd_intelhad *intelhaddata) {struct snd_pcm_substream *substream; -spin_lock_irq (&intelhaddata->had_spinlock); -if (!intelhaddata->connected) { -dev_dbg (intelhaddata->dev,"Device already disconnected\n" ); -spin_unlock_irq (&intelhaddata->had_spinlock); -return ; + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { +if (!intelhaddata->connected) { +dev_dbg (intelhaddata->dev,"Device already disconnected\n" ); +return ; + } - } +/* Disable Audio */ +had_enable_audio (intelhaddata, false); -/* Disable Audio */ -had_enable_audio (intelhaddata, false); - - intelhaddata->connected = false; -dev_dbg (intelhaddata->dev, -"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n" , + intelhaddata->connected = false; +dev_dbg (intelhaddata->dev, +"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n" , __func__, __LINE__); -spin_unlock_irq (&intelhaddata->had_spinlock); + }kfree (intelhaddata->chmap->chmap); intelhaddata->chmap->chmap =NULL ;
@@ -1636,9 +1621,9 @@ static void hdmi_lpe_audio_free(struct snd_card *card)struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data;int port; -spin_lock_irq (&pdata->lpe_audio_slock); - pdata->notify_audio_lpe =NULL ; -spin_unlock_irq (&pdata->lpe_audio_slock); + scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) { + pdata->notify_audio_lpe =NULL ; + }for_each_port (card_ctx, port) {struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
@@ -1799,9 +1784,9 @@ static int __hdmi_lpe_audio_probe(struct platform_device *pdev)if (ret)return ret; -spin_lock_irq (&pdata->lpe_audio_slock); - pdata->notify_audio_lpe = notify_audio_lpe; -spin_unlock_irq (&pdata->lpe_audio_slock); + scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) { + pdata->notify_audio_lpe = notify_audio_lpe; + }pm_runtime_set_autosuspend_delay (&pdev->dev,INTEL_HDMI_AUDIO_SUSPEND_DELAY_MS );pm_runtime_use_autosuspend (&pdev->dev);
Signature · 1 line
2.50.1
PATCH 8/19 ALSA: xen: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/xen/xen_snd_front.c | 80 ++++++++++++++----------------- sound/xen/xen_snd_front_evtchnl.c | 33 ++++++------- 2 files changed, 52 insertions(+), 61 deletions(-)
sound/xen/xen_snd_front.c +37 -43
@@ -62,12 +62,12 @@ int xen_snd_front_stream_query_hw_param(struct xen_snd_front_evtchnl *evtchnl,struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_HW_PARAM_QUERY ); - req->op.hw_param = *hw_param_req; -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_HW_PARAM_QUERY ); + req->op.hw_param = *hw_param_req; + } ret =be_stream_do_io (evtchnl);
@@ -77,7 +77,6 @@ int xen_snd_front_stream_query_hw_param(struct xen_snd_front_evtchnl *evtchnl,if (ret ==0 ) *hw_param_resp = evtchnl->u.req.resp.hw_param; -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
@@ -90,25 +89,24 @@ int xen_snd_front_stream_prepare(struct xen_snd_front_evtchnl *evtchnl,struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_OPEN ); - req->op.open.pcm_format = format; - req->op.open.pcm_channels = channels; - req->op.open.pcm_rate = rate; - req->op.open.buffer_sz = buffer_sz; - req->op.open.period_sz = period_sz; - req->op.open.gref_directory = -xen_front_pgdir_shbuf_get_dir_start (shbuf); -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_OPEN ); + req->op.open.pcm_format = format; + req->op.open.pcm_channels = channels; + req->op.open.pcm_rate = rate; + req->op.open.buffer_sz = buffer_sz; + req->op.open.period_sz = period_sz; + req->op.open.gref_directory = +xen_front_pgdir_shbuf_get_dir_start (shbuf); + } ret =be_stream_do_io (evtchnl);if (ret ==0 ) ret =be_stream_wait_io (evtchnl); -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
@@ -117,18 +115,17 @@ int xen_snd_front_stream_close(struct xen_snd_front_evtchnl *evtchnl)__always_unused struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_CLOSE ); -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_CLOSE ); + } ret =be_stream_do_io (evtchnl);if (ret ==0 ) ret =be_stream_wait_io (evtchnl); -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
@@ -138,20 +135,19 @@ int xen_snd_front_stream_write(struct xen_snd_front_evtchnl *evtchnl,struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_WRITE ); - req->op.rw.length = count; - req->op.rw.offset = pos; -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_WRITE ); + req->op.rw.length = count; + req->op.rw.offset = pos; + } ret =be_stream_do_io (evtchnl);if (ret ==0 ) ret =be_stream_wait_io (evtchnl); -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
@@ -161,20 +157,19 @@ int xen_snd_front_stream_read(struct xen_snd_front_evtchnl *evtchnl,struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_READ ); - req->op.rw.length = count; - req->op.rw.offset = pos; -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_READ ); + req->op.rw.length = count; + req->op.rw.offset = pos; + } ret =be_stream_do_io (evtchnl);if (ret ==0 ) ret =be_stream_wait_io (evtchnl); -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
@@ -184,19 +179,18 @@ int xen_snd_front_stream_trigger(struct xen_snd_front_evtchnl *evtchnl,struct xensnd_req *req;int ret; -mutex_lock (&evtchnl->u.req.req_io_lock); +guard (mutex)(&evtchnl->u.req.req_io_lock); -mutex_lock (&evtchnl->ring_io_lock); - req =be_stream_prepare_req (evtchnl,XENSND_OP_TRIGGER ); - req->op.trigger.type = type; -mutex_unlock (&evtchnl->ring_io_lock); + scoped_guard(mutex, &evtchnl->ring_io_lock) { + req =be_stream_prepare_req (evtchnl,XENSND_OP_TRIGGER ); + req->op.trigger.type = type; + } ret =be_stream_do_io (evtchnl);if (ret ==0 ) ret =be_stream_wait_io (evtchnl); -mutex_unlock (&evtchnl->u.req.req_io_lock);return ret; }
sound/xen/xen_snd_front_evtchnl.c +15 -18
@@ -28,7 +28,7 @@ static irqreturn_t evtchnl_interrupt_req(int irq, void *dev_id)if (unlikely (channel->state !=EVTCHNL_STATE_CONNECTED ))return IRQ_HANDLED ; -mutex_lock (&channel->ring_io_lock); +guard (mutex)(&channel->ring_io_lock); again: rp = channel->u.req.ring.sring->rsp_prod;
@@ -80,7 +80,6 @@ static irqreturn_t evtchnl_interrupt_req(int irq, void *dev_id) channel->u.req.ring.sring->rsp_event = i +1 ; } -mutex_unlock (&channel->ring_io_lock);return IRQ_HANDLED ; }
@@ -93,13 +92,13 @@ static irqreturn_t evtchnl_interrupt_evt(int irq, void *dev_id)if (unlikely (channel->state !=EVTCHNL_STATE_CONNECTED ))return IRQ_HANDLED ; -mutex_lock (&channel->ring_io_lock); +guard (mutex)(&channel->ring_io_lock); prod = page->in_prod;/* Ensure we see ring contents up to prod. */ virt_rmb ();if (prod == page->in_cons) - goto out; +return IRQ_HANDLED ;/* * Assume that the backend is trusted to always write sane values
@@ -125,8 +124,6 @@ static irqreturn_t evtchnl_interrupt_evt(int irq, void *dev_id)/* Ensure ring contents. */ virt_wmb (); -out: -mutex_unlock (&channel->ring_io_lock);return IRQ_HANDLED ; }
@@ -444,23 +441,23 @@ void xen_snd_front_evtchnl_pair_set_connected(struct xen_snd_front_evtchnl_pairelse state =EVTCHNL_STATE_DISCONNECTED ; -mutex_lock (&evt_pair->req.ring_io_lock); - evt_pair->req.state = state; -mutex_unlock (&evt_pair->req.ring_io_lock); + scoped_guard(mutex, &evt_pair->req.ring_io_lock) { + evt_pair->req.state = state; + } -mutex_lock (&evt_pair->evt.ring_io_lock); - evt_pair->evt.state = state; -mutex_unlock (&evt_pair->evt.ring_io_lock); + scoped_guard(mutex, &evt_pair->evt.ring_io_lock) { + evt_pair->evt.state = state; + } }void xen_snd_front_evtchnl_pair_clear (struct xen_snd_front_evtchnl_pair *evt_pair) { -mutex_lock (&evt_pair->req.ring_io_lock); - evt_pair->req.evt_next_id =0 ; -mutex_unlock (&evt_pair->req.ring_io_lock); + scoped_guard(mutex, &evt_pair->req.ring_io_lock) { + evt_pair->req.evt_next_id =0 ; + } -mutex_lock (&evt_pair->evt.ring_io_lock); - evt_pair->evt.evt_next_id =0 ; -mutex_unlock (&evt_pair->evt.ring_io_lock); + scoped_guard(mutex, &evt_pair->evt.ring_io_lock) { + evt_pair->evt.evt_next_id =0 ; + } }
Signature · 1 line
2.50.1
PATCH 9/19 ALSA: at73c213: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/spi/at73c213.c | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-)
sound/spi/at73c213.c +10 -29
@@ -401,7 +401,7 @@ static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,int mask = (kcontrol->private_value >>16 ) &0xff ;int invert = (kcontrol->private_value >>24 ) &0xff ; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); ucontrol->value.integer.value[0 ] = (chip->reg_image[reg] >> shift) & mask;
@@ -410,8 +410,6 @@ static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[0 ] = mask - ucontrol->value.integer.value[0 ]; -mutex_unlock (&chip->mixer_lock); -return 0 ; }
@@ -431,14 +429,12 @@ static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol, val = mask - val; val <<= shift; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); val = (chip->reg_image[reg] & ~(mask << shift)) | val; change = val != chip->reg_image[reg]; retval =snd_at73c213_write_reg (chip, reg, val); -mutex_unlock (&chip->mixer_lock); -if (retval)return retval;
@@ -473,7 +469,7 @@ static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,int mask = (kcontrol->private_value >>24 ) &0xff ;int invert = (kcontrol->private_value >>22 ) &1 ; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); ucontrol->value.integer.value[0 ] = (chip->reg_image[left_reg] >> shift_left) & mask;
@@ -487,8 +483,6 @@ static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol, mask - ucontrol->value.integer.value[1 ]; } -mutex_unlock (&chip->mixer_lock); -return 0 ; }
@@ -514,29 +508,20 @@ static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol, val1 <<= shift_left; val2 <<= shift_right; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); val1 = (chip->reg_image[left_reg] & ~(mask << shift_left)) | val1; val2 = (chip->reg_image[right_reg] & ~(mask << shift_right)) | val2; change = val1 != chip->reg_image[left_reg] || val2 != chip->reg_image[right_reg]; retval =snd_at73c213_write_reg (chip, left_reg, val1); -if (retval) { -mutex_unlock (&chip->mixer_lock); - goto out; - } +if (retval) +return retval; retval =snd_at73c213_write_reg (chip, right_reg, val2); -if (retval) { -mutex_unlock (&chip->mixer_lock); - goto out; - } - -mutex_unlock (&chip->mixer_lock); +if (retval) +return retval;return change; - -out: -return retval; }#define snd_at73c213_mono_switch_info snd_ctl_boolean_mono_info
@@ -549,7 +534,7 @@ static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,int shift = (kcontrol->private_value >>8 ) &0xff ;int invert = (kcontrol->private_value >>24 ) &0xff ; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); ucontrol->value.integer.value[0 ] = (chip->reg_image[reg] >> shift) &0x01 ;
@@ -558,8 +543,6 @@ static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[0 ] =0x01 - ucontrol->value.integer.value[0 ]; -mutex_unlock (&chip->mixer_lock); -return 0 ; }
@@ -583,15 +566,13 @@ static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol, val = mask - val; val <<= shift; -mutex_lock (&chip->mixer_lock); +guard (mutex)(&chip->mixer_lock); val |= (chip->reg_image[reg] & ~(mask << shift)); change = val != chip->reg_image[reg]; retval =snd_at73c213_write_reg (chip, reg, val); -mutex_unlock (&chip->mixer_lock); -if (retval)return retval;
Signature · 1 line
2.50.1
PATCH 10/19 ALSA: pdaudiocf: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/pcmcia/pdaudiocf/pdaudiocf_core.c | 3 +-- sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-)
sound/pcmcia/pdaudiocf/pdaudiocf_core.c +1 -2
@@ -161,14 +161,13 @@ static void snd_pdacf_ak4117_change(struct ak4117 *ak4117, unsigned char c0, unsif (!(c0 &AK4117_UNLCK ))return ; -mutex_lock (&chip->reg_lock); +guard (mutex)(&chip->reg_lock); val = chip->regmap[PDAUDIOCF_REG_SCR >>1 ];if (ak4117->rcs0 &AK4117_UNLCK ) val |=PDAUDIOCF_BLUE_LED_OFF ;else val &= ~PDAUDIOCF_BLUE_LED_OFF ;pdacf_reg_write (chip,PDAUDIOCF_REG_SCR , val); -mutex_unlock (&chip->reg_lock); }int snd_pdacf_ak4117_create (struct snd_pdacf *chip)
sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c +12 -13
@@ -64,21 +64,20 @@ static int pdacf_pcm_trigger(struct snd_pcm_substream *subs, int cmd)default :return -EINVAL ; } -mutex_lock (&chip->reg_lock); - chip->pcm_running += inc; - tmp =pdacf_reg_read (chip,PDAUDIOCF_REG_SCR ); -if (chip->pcm_running) { -if ((chip->ak4117->rcs0 &AK4117_UNLCK ) || runtime->rate != rate) { - chip->pcm_running -= inc; - ret = -EIO ; - goto __end; + scoped_guard(mutex, &chip->reg_lock) { + chip->pcm_running += inc; + tmp =pdacf_reg_read (chip,PDAUDIOCF_REG_SCR ); +if (chip->pcm_running) { +if ((chip->ak4117->rcs0 &AK4117_UNLCK ) || runtime->rate != rate) { + chip->pcm_running -= inc; + ret = -EIO ; +break ; + } } + tmp &= ~mask; + tmp |= val; +pdacf_reg_write (chip,PDAUDIOCF_REG_SCR , tmp); } - tmp &= ~mask; - tmp |= val; -pdacf_reg_write (chip,PDAUDIOCF_REG_SCR , tmp); - __end: -mutex_unlock (&chip->reg_lock);snd_ak4117_check_rate_and_errors (chip->ak4117,AK4117_CHECK_NO_RATE );return ret; }
Signature · 1 line
2.50.1
PATCH 11/19 ALSA: vxpocket: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/pcmcia/vx/vxp_mixer.c | 9 +++------ sound/pcmcia/vx/vxp_ops.c | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-)
sound/pcmcia/vx/vxp_mixer.c +3 -6
@@ -43,14 +43,12 @@ static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_vif (val >MIC_LEVEL_MAX )return -EINVAL ; -mutex_lock (&_chip->mixer_mutex); +guard (mutex)(&_chip->mixer_mutex);if (chip->mic_level != ucontrol->value.integer.value[0 ]) {vx_set_mic_level (_chip, ucontrol->value.integer.value[0 ]); chip->mic_level = ucontrol->value.integer.value[0 ]; -mutex_unlock (&_chip->mixer_mutex);return 1 ; } -mutex_unlock (&_chip->mixer_mutex);return 0 ; }
@@ -85,14 +83,13 @@ static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_vstruct vx_core *_chip =snd_kcontrol_chip (kcontrol);struct snd_vxpocket *chip =to_vxpocket (_chip);int val = !!ucontrol->value.integer.value[0 ]; -mutex_lock (&_chip->mixer_mutex); + +guard (mutex)(&_chip->mixer_mutex);if (chip->mic_level != val) {vx_set_mic_boost (_chip, val); chip->mic_level = val; -mutex_unlock (&_chip->mixer_mutex);return 1 ; } -mutex_unlock (&_chip->mixer_mutex);return 0 ; }
sound/pcmcia/vx/vxp_ops.c +2 -4
@@ -463,7 +463,7 @@ void vx_set_mic_boost(struct vx_core *chip, int boost)if (chip->chip_status &VX_STAT_IS_STALE )return ; -mutex_lock (&chip->lock); +guard (mutex)(&chip->lock);if (pchip->regCDSP &P24_CDSP_MICS_SEL_MASK ) {if (boost) {/* boost: 38 dB */
@@ -476,7 +476,6 @@ void vx_set_mic_boost(struct vx_core *chip, int boost) }vx_outb (chip,CDSP , pchip->regCDSP); } -mutex_unlock (&chip->lock); }/*
@@ -505,12 +504,11 @@ void vx_set_mic_level(struct vx_core *chip, int level)if (chip->chip_status &VX_STAT_IS_STALE )return ; -mutex_lock (&chip->lock); +guard (mutex)(&chip->lock);if (pchip->regCDSP &VXP_CDSP_MIC_SEL_MASK ) { level =vx_compute_mic_level (level);vx_outb (chip,MICRO , level); } -mutex_unlock (&chip->lock); }
Signature · 1 line
2.50.1
PATCH 12/19 ALSA: sparc: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/sparc/cs4231.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
sound/sparc/cs4231.c +6 -15
@@ -608,7 +608,7 @@ static void snd_cs4231_playback_format(struct snd_cs4231 *chip, {unsigned long flags; -mutex_lock (&chip->mce_mutex); +guard (mutex)(&chip->mce_mutex);snd_cs4231_calibrate_mute (chip,1 );snd_cs4231_mce_up (chip);
@@ -623,7 +623,6 @@ static void snd_cs4231_playback_format(struct snd_cs4231 *chip,snd_cs4231_mce_down (chip);snd_cs4231_calibrate_mute (chip,0 ); -mutex_unlock (&chip->mce_mutex); } static void snd_cs4231_capture_format(struct snd_cs4231 *chip,
@@ -632,7 +631,7 @@ static void snd_cs4231_capture_format(struct snd_cs4231 *chip, {unsigned long flags; -mutex_lock (&chip->mce_mutex); +guard (mutex)(&chip->mce_mutex);snd_cs4231_calibrate_mute (chip,1 );snd_cs4231_mce_up (chip);
@@ -653,7 +652,6 @@ static void snd_cs4231_capture_format(struct snd_cs4231 *chip,snd_cs4231_mce_down (chip);snd_cs4231_calibrate_mute (chip,0 ); -mutex_unlock (&chip->mce_mutex); }/*
@@ -775,14 +773,11 @@ static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode) {unsigned long flags; -mutex_lock (&chip->open_mutex); -if ((chip->mode & mode)) { -mutex_unlock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex); +if ((chip->mode & mode))return -EAGAIN ; - }if (chip->mode &CS4231_MODE_OPEN ) { chip->mode |= mode; -mutex_unlock (&chip->open_mutex);return 0 ; }/* ok. now enable and ack CODEC IRQ */
@@ -802,7 +797,6 @@ static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode)spin_unlock_irqrestore (&chip->lock, flags); chip->mode = mode; -mutex_unlock (&chip->open_mutex);return 0 ; }
@@ -810,12 +804,10 @@ static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) {unsigned long flags; -mutex_lock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex); chip->mode &= ~mode; -if (chip->mode &CS4231_MODE_OPEN ) { -mutex_unlock (&chip->open_mutex); +if (chip->mode &CS4231_MODE_OPEN )return ; - }snd_cs4231_calibrate_mute (chip,1 );/* disable IRQ */
@@ -851,7 +843,6 @@ static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode)snd_cs4231_calibrate_mute (chip,0 ); chip->mode =0 ; -mutex_unlock (&chip->open_mutex); }/*
Signature · 1 line
2.50.1
PATCH 13/19 ALSA: aoa: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/aoa/codecs/onyx.c | 104 +++++++++-------------------- sound/aoa/codecs/tas.c | 113 +++++++++++--------------------- sound/aoa/core/gpio-feature.c | 20 ++---- sound/aoa/core/gpio-pmf.c | 26 +++----- sound/aoa/soundbus/i2sbus/pcm.c | 76 +++++++-------------- 5 files changed, 112 insertions(+), 227 deletions(-)
sound/aoa/codecs/onyx.c +32 -72
@@ -122,10 +122,9 @@ static int onyx_snd_vol_get(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);s8 l, r; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_LEFT , &l);onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_RIGHT , &r); -mutex_unlock (&onyx->mutex); ucontrol->value.integer.value[0 ] = l +VOLUME_RANGE_SHIFT ; ucontrol->value.integer.value[1 ] = r +VOLUME_RANGE_SHIFT ;
@@ -146,15 +145,13 @@ static int onyx_snd_vol_put(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[1] > -1 + VOLUME_RANGE_SHIFT)return -EINVAL ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_LEFT , &l);onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_RIGHT , &r);if (l +VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[0 ] && - r +VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[1 ]) { -mutex_unlock (&onyx->mutex); + r +VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[1 ])return 0 ; - }onyx_write_register (onyx,ONYX_REG_DAC_ATTEN_LEFT , ucontrol->value.integer.value[0]
@@ -162,7 +159,6 @@ static int onyx_snd_vol_put(struct snd_kcontrol *kcontrol,onyx_write_register (onyx,ONYX_REG_DAC_ATTEN_RIGHT , ucontrol->value.integer.value[1 ] -VOLUME_RANGE_SHIFT ); -mutex_unlock (&onyx->mutex);return 1 ; }
@@ -198,9 +194,8 @@ static int onyx_snd_inputgain_get(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);u8 ig; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_ADC_CONTROL , &ig); -mutex_unlock (&onyx->mutex); ucontrol->value.integer.value[0 ] = (ig &ONYX_ADC_PGA_GAIN_MASK ) +INPUTGAIN_RANGE_SHIFT ;
@@ -217,14 +212,13 @@ static int onyx_snd_inputgain_put(struct snd_kcontrol *kcontrol,if (ucontrol->value.integer.value[0 ] <3 +INPUTGAIN_RANGE_SHIFT || ucontrol->value.integer.value[0 ] >28 +INPUTGAIN_RANGE_SHIFT )return -EINVAL ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_ADC_CONTROL , &v); n = v; n &= ~ONYX_ADC_PGA_GAIN_MASK ; n |= (ucontrol->value.integer.value[0 ] -INPUTGAIN_RANGE_SHIFT ) &ONYX_ADC_PGA_GAIN_MASK ;onyx_write_register (onyx,ONYX_REG_ADC_CONTROL , n); -mutex_unlock (&onyx->mutex);return n != v; }
@@ -252,9 +246,8 @@ static int onyx_snd_capture_source_get(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);s8 v; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_ADC_CONTROL , &v); -mutex_unlock (&onyx->mutex); ucontrol->value.enumerated.item[0 ] = !!(v&ONYX_ADC_INPUT_MIC );
@@ -265,13 +258,12 @@ static void onyx_set_capture_source(struct onyx *onyx, int mic) {s8 v; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_ADC_CONTROL , &v); v &= ~ONYX_ADC_INPUT_MIC ;if (mic) v |=ONYX_ADC_INPUT_MIC ;onyx_write_register (onyx,ONYX_REG_ADC_CONTROL , v); -mutex_unlock (&onyx->mutex); } static int onyx_snd_capture_source_put(struct snd_kcontrol *kcontrol,
@@ -312,9 +304,8 @@ static int onyx_snd_mute_get(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);u8 c; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DAC_CONTROL , &c); -mutex_unlock (&onyx->mutex); ucontrol->value.integer.value[0 ] = !(c &ONYX_MUTE_LEFT ); ucontrol->value.integer.value[1 ] = !(c &ONYX_MUTE_RIGHT );
@@ -329,9 +320,9 @@ static int onyx_snd_mute_put(struct snd_kcontrol *kcontrol,u8 v =0 , c =0 ;int err = -EBUSY ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);if (onyx->analog_locked) - goto out_unlock; +return -EBUSY ;onyx_read_register (onyx,ONYX_REG_DAC_CONTROL , &v); c = v;
@@ -342,9 +333,6 @@ static int onyx_snd_mute_put(struct snd_kcontrol *kcontrol, c |=ONYX_MUTE_RIGHT ; err =onyx_write_register (onyx,ONYX_REG_DAC_CONTROL , c); - out_unlock: -mutex_unlock (&onyx->mutex); -return !err ? (v != c) : err; }
@@ -373,9 +361,8 @@ static int onyx_snd_single_bit_get(struct snd_kcontrol *kcontrol,u8 address = (pv >>8 ) &0xff ;u8 mask = pv &0xff ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx, address, &c); -mutex_unlock (&onyx->mutex); ucontrol->value.integer.value[0 ] = !!(c & mask) ^ polarity;
@@ -394,11 +381,10 @@ static int onyx_snd_single_bit_put(struct snd_kcontrol *kcontrol,u8 address = (pv >>8 ) &0xff ;u8 mask = pv &0xff ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);if (spdiflock && onyx->spdif_locked) {/* even if alsamixer doesn't care.. */ - err = -EBUSY ; - goto out_unlock; +return -EBUSY ; }onyx_read_register (onyx, address, &v); c = v;
@@ -407,9 +393,6 @@ static int onyx_snd_single_bit_put(struct snd_kcontrol *kcontrol, c |= mask; err =onyx_write_register (onyx, address, c); - out_unlock: -mutex_unlock (&onyx->mutex); -return !err ? (v != c) : err; }
@@ -490,7 +473,7 @@ static int onyx_spdif_get(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);u8 v; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DIG_INFO1 , &v); ucontrol->value.iec958.status[0 ] = v &0x3e ;
@@ -502,7 +485,6 @@ static int onyx_spdif_get(struct snd_kcontrol *kcontrol,onyx_read_register (onyx,ONYX_REG_DIG_INFO4 , &v); ucontrol->value.iec958.status[4 ] = v &0x0f ; -mutex_unlock (&onyx->mutex);return 0 ; }
@@ -513,7 +495,7 @@ static int onyx_spdif_put(struct snd_kcontrol *kcontrol,struct onyx *onyx =snd_kcontrol_chip (kcontrol);u8 v; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DIG_INFO1 , &v); v = (v & ~0x3e ) | (ucontrol->value.iec958.status[0 ] &0x3e );onyx_write_register (onyx,ONYX_REG_DIG_INFO1 , v);
@@ -528,7 +510,6 @@ static int onyx_spdif_put(struct snd_kcontrol *kcontrol,onyx_read_register (onyx,ONYX_REG_DIG_INFO4 , &v); v = (v & ~0x0f ) | (ucontrol->value.iec958.status[4 ] &0x0f );onyx_write_register (onyx,ONYX_REG_DIG_INFO4 , v); -mutex_unlock (&onyx->mutex);return 1 ; }
@@ -673,14 +654,13 @@ static int onyx_usable(struct codec_info_item *cii,struct onyx *onyx = cii->codec_data;int spdif_enabled, analog_enabled; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);onyx_read_register (onyx,ONYX_REG_DIG_INFO4 , &v); spdif_enabled = !!(v &ONYX_SPDIF_ENABLE );onyx_read_register (onyx,ONYX_REG_DAC_CONTROL , &v); analog_enabled = (v & (ONYX_MUTE_RIGHT |ONYX_MUTE_LEFT )) != (ONYX_MUTE_RIGHT |ONYX_MUTE_LEFT ); -mutex_unlock (&onyx->mutex);switch (ti->tag) {case 0 :return 1 ;
@@ -696,9 +676,8 @@ static int onyx_prepare(struct codec_info_item *cii, {u8 v;struct onyx *onyx = cii->codec_data; -int err = -EBUSY ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);#ifdef SNDRV_PCM_FMTBIT_COMPRESSED_16BE if (substream->runtime->format ==SNDRV_PCM_FMTBIT_COMPRESSED_16BE ) {
@@ -707,10 +686,9 @@ static int onyx_prepare(struct codec_info_item *cii,if (onyx_write_register (onyx,ONYX_REG_DAC_CONTROL , v |ONYX_MUTE_RIGHT |ONYX_MUTE_LEFT )) - goto out_unlock; +return -EBUSY ; onyx->analog_locked =1 ; - err =0 ; - goto out_unlock; + return 0; }#endif switch (substream->runtime->rate) {
@@ -720,8 +698,7 @@ static int onyx_prepare(struct codec_info_item *cii,/* these rates are ok for all outputs */ /* FIXME: program spdif channel control bits here so that * userspace doesn't have to if it only plays pcm! */ - err =0 ; - goto out_unlock; +return 0 ;default :/* got some rate that the digital output can't do, * so disable and lock it */
@@ -729,16 +706,12 @@ static int onyx_prepare(struct codec_info_item *cii,if (onyx_write_register (onyx,ONYX_REG_DIG_INFO4 , v & ~ONYX_SPDIF_ENABLE )) - goto out_unlock; +return -EBUSY ; onyx->spdif_locked =1 ; - err =0 ; - goto out_unlock; +return 0 ; } - out_unlock: -mutex_unlock (&onyx->mutex); - -return err; +return -EBUSY ; } static int onyx_open(struct codec_info_item *cii,
@@ -746,9 +719,8 @@ static int onyx_open(struct codec_info_item *cii, {struct onyx *onyx = cii->codec_data; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex); onyx->open_count++; -mutex_unlock (&onyx->mutex);return 0 ; }
@@ -758,11 +730,10 @@ static int onyx_close(struct codec_info_item *cii, {struct onyx *onyx = cii->codec_data; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex); onyx->open_count--;if (!onyx->open_count) onyx->spdif_locked = onyx->analog_locked =0 ; -mutex_unlock (&onyx->mutex);return 0 ; }
@@ -772,7 +743,7 @@ static int onyx_switch_clock(struct codec_info_item *cii, {struct onyx *onyx = cii->codec_data; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);/* this *MUST* be more elaborate later... */ switch (what) {case CLOCK_SWITCH_PREPARE_SLAVE :
@@ -784,7 +755,6 @@ static int onyx_switch_clock(struct codec_info_item *cii,default :/* silence warning */ break ; } -mutex_unlock (&onyx->mutex);return 0 ; }
@@ -795,27 +765,21 @@ static int onyx_suspend(struct codec_info_item *cii, pm_message_t state) {struct onyx *onyx = cii->codec_data;u8 v; -int err = -ENXIO ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);if (onyx_read_register (onyx,ONYX_REG_CONTROL , &v)) - goto out_unlock; +return -ENXIO ;onyx_write_register (onyx,ONYX_REG_CONTROL , v |ONYX_ADPSV |ONYX_DAPSV );/* Apple does a sleep here but the datasheet says to do it on resume */ - err =0 ; - out_unlock: -mutex_unlock (&onyx->mutex); - -return err; +return 0 ; }static int onyx_resume (struct codec_info_item *cii) {struct onyx *onyx = cii->codec_data;u8 v; -int err = -ENXIO ; -mutex_lock (&onyx->mutex); +guard (mutex)(&onyx->mutex);/* reset codec */ onyx->codec.gpio->methods->set_hw_reset (onyx->codec.gpio,0 );
@@ -827,17 +791,13 @@ static int onyx_resume(struct codec_info_item *cii)/* take codec out of suspend (if it still is after reset) */ if (onyx_read_register (onyx,ONYX_REG_CONTROL , &v)) - goto out_unlock; +return -ENXIO ;onyx_write_register (onyx,ONYX_REG_CONTROL , v & ~(ONYX_ADPSV |ONYX_DAPSV ));/* FIXME: should divide by sample rate, but 8k is the lowest we go */ msleep (2205000 /8000 );/* reset all values */ onyx_register_init (onyx); - err =0 ; - out_unlock: -mutex_unlock (&onyx->mutex); - - return err; + return 0; }#endif /* CONFIG_PM */
sound/aoa/codecs/tas.c +39 -74
303 lines not on this page · raw message
sound/aoa/core/gpio-feature.c +7 -13
@@ -212,10 +212,9 @@ static void ftr_handle_notify(struct work_struct *work)struct gpio_notification *notif = container_of(work, struct gpio_notification, work.work); -mutex_lock (¬if->mutex); +guard (mutex)(¬if->mutex);if (notif->notify) notif->notify (notif->data); -mutex_unlock (¬if->mutex); }static void gpio_enable_dual_edge (int gpio)
@@ -341,19 +340,17 @@ static int ftr_set_notify(struct gpio_runtime *rt,if (!irq)return -ENODEV ; -mutex_lock (¬if->mutex); +guard (mutex)(¬if->mutex); old = notif->notify; -if (!old && !notify) { - err =0 ; - goto out_unlock; - } +if (!old && !notify) +return 0 ;if (old && notify) {if (old == notify && notif->data == data) err =0 ; - goto out_unlock; +return err; }if (old && !notify)
@@ -362,16 +359,13 @@ static int ftr_set_notify(struct gpio_runtime *rt,if (!old && notify) { err =request_irq (irq, ftr_handle_notify_irq,0 , name, notif);if (err) - goto out_unlock; +return err; } notif->notify = notify; notif->data = data; - err =0 ; - out_unlock: -mutex_unlock (¬if->mutex); -return err; +return 0 ; } static int ftr_get_detect(struct gpio_runtime *rt,
sound/aoa/core/gpio-pmf.c +9 -17
@@ -74,10 +74,9 @@ static void pmf_handle_notify(struct work_struct *work)struct gpio_notification *notif = container_of(work, struct gpio_notification, work.work); -mutex_lock (¬if->mutex); +guard (mutex)(¬if->mutex);if (notif->notify) notif->notify (notif->data); -mutex_unlock (¬if->mutex); }static void pmf_gpio_init (struct gpio_runtime *rt)
@@ -154,19 +153,17 @@ static int pmf_set_notify(struct gpio_runtime *rt,return -EINVAL ; } -mutex_lock (¬if->mutex); +guard (mutex)(¬if->mutex); old = notif->notify; -if (!old && !notify) { - err =0 ; - goto out_unlock; - } +if (!old && !notify) +return 0 ;if (old && notify) {if (old == notify && notif->data == data) err =0 ; - goto out_unlock; +return err; }if (old && !notify) {
@@ -178,10 +175,8 @@ static int pmf_set_notify(struct gpio_runtime *rt,if (!old && notify) { irq_client =kzalloc (sizeof (struct pmf_irq_client ),GFP_KERNEL ); -if (!irq_client) { - err = -ENOMEM ; - goto out_unlock; - } +if (!irq_client) +return -ENOMEM ; irq_client->data = notif; irq_client->handler = pmf_handle_notify_irq; irq_client->owner =THIS_MODULE ;
@@ -192,17 +187,14 @@ static int pmf_set_notify(struct gpio_runtime *rt,printk (KERN_ERR "snd-aoa: gpio layer failed to" " register %s irq (%d)\n" , name, err);kfree (irq_client); - goto out_unlock; +return err; } notif->gpio_private = irq_client; } notif->notify = notify; notif->data = data; - err =0 ; - out_unlock: -mutex_unlock (¬if->mutex); -return err; +return 0 ; } static int pmf_get_detect(struct gpio_runtime *rt,
sound/aoa/soundbus/i2sbus/pcm.c +25 -51
184 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 14/19 ALSA: aaci: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/arm/aaci.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
sound/arm/aaci.c +6 -14
@@ -73,7 +73,7 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,if (ac97->num >=4 )return ; -mutex_lock (&aaci->ac97_sem); +guard (mutex)(&aaci->ac97_sem);aaci_ac97_select_codec (aaci, ac97);
@@ -97,8 +97,6 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,if (v & (SLFR_1TXB |SLFR_2TXB ))dev_err (&aaci->dev->dev,"timeout waiting for write to complete\n" ); - -mutex_unlock (&aaci->ac97_sem); }/*
@@ -113,7 +111,7 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)if (ac97->num >=4 )return ~0 ; -mutex_lock (&aaci->ac97_sem); +guard (mutex)(&aaci->ac97_sem);aaci_ac97_select_codec (aaci, ac97);
@@ -134,8 +132,7 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)if (v &SLFR_1TXB ) {dev_err (&aaci->dev->dev,"timeout on slot 1 TX busy\n" ); - v = ~0 ; - goto out; +return ~0 ; }/* Now wait for the response frame */
@@ -151,8 +148,7 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)if (v != (SLFR_1RXV |SLFR_2RXV )) {dev_err (&aaci->dev->dev,"timeout on RX valid\n" ); - v = ~0 ; - goto out; +return ~0 ; } do {
@@ -171,8 +167,6 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) v = ~0 ; } }while (retries); - out: -mutex_unlock (&aaci->ac97_sem);return v; }
@@ -437,14 +431,13 @@ static int aaci_pcm_open(struct snd_pcm_substream *substream)*/ runtime->hw.fifo_size = aaci->fifo_depth *2 ; -mutex_lock (&aaci->irq_lock); +guard (mutex)(&aaci->irq_lock);if (!aaci->users++) { ret =request_irq (aaci->dev->irq[0 ], aaci_irq,IRQF_SHARED ,DRIVER_NAME , aaci);if (ret !=0 ) aaci->users--; } -mutex_unlock (&aaci->irq_lock);return ret; }
@@ -462,10 +455,9 @@ static int aaci_pcm_close(struct snd_pcm_substream *substream) aacirun->substream =NULL ; -mutex_lock (&aaci->irq_lock); +guard (mutex)(&aaci->irq_lock);if (!--aaci->users)free_irq (aaci->dev->irq[0 ], aaci); -mutex_unlock (&aaci->irq_lock);return 0 ; }
Signature · 1 line
2.50.1
PATCH 15/19 ALSA: pxa2xx: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/arm/pxa2xx-ac97-lib.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
sound/arm/pxa2xx-ac97-lib.c +4 -8
@@ -51,7 +51,7 @@ int pxa2xx_ac97_read(int slot, unsigned short reg)if (slot >0 )return -ENODEV ; -mutex_lock (&car_mutex); +guard (mutex)(&car_mutex);/* set up primary or secondary codec space */ if (cpu_is_pxa25x () && reg ==AC97_GPIO_STATUS )
@@ -67,13 +67,12 @@ int pxa2xx_ac97_read(int slot, unsigned short reg) gsr_bits =0 ; val = (readl (reg_addr) &0xffff );if (reg ==AC97_GPIO_STATUS ) - goto out; +return val;if (wait_event_timeout (gsr_wq, (readl (ac97_reg_base +GSR ) | gsr_bits) &GSR_SDONE ,1 ) <=0 && !((readl (ac97_reg_base +GSR ) | gsr_bits) &GSR_SDONE )) {printk (KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n" , __func__, reg,readl (ac97_reg_base +GSR ) | gsr_bits); - val = -ETIMEDOUT ; - goto out; +return -ETIMEDOUT ; }/* valid data now */
@@ -82,8 +81,6 @@ int pxa2xx_ac97_read(int slot, unsigned short reg) val = (readl (reg_addr) &0xffff );/* but we've just started another cycle... */ wait_event_timeout (gsr_wq, (readl (ac97_reg_base +GSR ) | gsr_bits) &GSR_SDONE ,1 ); - -out:mutex_unlock (&car_mutex);return val; }EXPORT_SYMBOL_GPL (pxa2xx_ac97_read);
@@ -93,7 +90,7 @@ int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val)u32 __iomem *reg_addr;int ret =0 ; -mutex_lock (&car_mutex); +guard (mutex)(&car_mutex);/* set up primary or secondary codec space */ if (cpu_is_pxa25x () && reg ==AC97_GPIO_STATUS )
@@ -114,7 +111,6 @@ int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val) ret = -EIO ; } -mutex_unlock (&car_mutex);return ret; }EXPORT_SYMBOL_GPL (pxa2xx_ac97_write);
Signature · 1 line
2.50.1
PATCH 16/19 ALSA: atmel: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/atmel/ac97c.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
sound/atmel/ac97c.c +6 -12
@@ -88,7 +88,7 @@ static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream)struct atmel_ac97c *chip =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime; -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->opened++; runtime->hw = atmel_ac97c_hw;if (chip->cur_rate) {
@@ -97,7 +97,6 @@ static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream) }if (chip->cur_format) runtime->hw.formats =pcm_format_to_bits (chip->cur_format); -mutex_unlock (&opened_mutex); chip->playback_substream = substream;return 0 ; }
@@ -107,7 +106,7 @@ static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream)struct atmel_ac97c *chip =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime; -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->opened++; runtime->hw = atmel_ac97c_hw;if (chip->cur_rate) {
@@ -116,7 +115,6 @@ static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream) }if (chip->cur_format) runtime->hw.formats =pcm_format_to_bits (chip->cur_format); -mutex_unlock (&opened_mutex); chip->capture_substream = substream;return 0 ; }
@@ -125,13 +123,12 @@ static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream) {struct atmel_ac97c *chip =snd_pcm_substream_chip (substream); -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->opened--;if (!chip->opened) { chip->cur_rate =0 ; chip->cur_format =0 ; } -mutex_unlock (&opened_mutex); chip->playback_substream =NULL ;
@@ -142,13 +139,12 @@ static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream) {struct atmel_ac97c *chip =snd_pcm_substream_chip (substream); -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->opened--;if (!chip->opened) { chip->cur_rate =0 ; chip->cur_format =0 ; } -mutex_unlock (&opened_mutex); chip->capture_substream =NULL ;
@@ -161,10 +157,9 @@ static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,struct atmel_ac97c *chip =snd_pcm_substream_chip (substream);/* Set restrictions to params. */ -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->cur_rate =params_rate (hw_params); chip->cur_format =params_format (hw_params); -mutex_unlock (&opened_mutex);return 0 ; }
@@ -175,10 +170,9 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,struct atmel_ac97c *chip =snd_pcm_substream_chip (substream);/* Set restrictions to params. */ -mutex_lock (&opened_mutex); +guard (mutex)(&opened_mutex); chip->cur_rate =params_rate (hw_params); chip->cur_format =params_format (hw_params); -mutex_unlock (&opened_mutex);return 0 ; }
Signature · 1 line
2.50.1
PATCH 17/19 ALSA: ac97bus: Use guard() for mutex locks
In reply to Takashi IwaiReplace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/ac97/bus.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
sound/ac97/bus.c +9 -13
@@ -241,10 +241,9 @@ static ssize_t cold_reset_store(struct device *dev, {struct ac97_controller *ac97_ctrl; -mutex_lock (&ac97_controllers_mutex); +guard (mutex)(&ac97_controllers_mutex); ac97_ctrl =to_ac97_controller (dev); ac97_ctrl->ops->reset (ac97_ctrl); -mutex_unlock (&ac97_controllers_mutex);return len; }static DEVICE_ATTR_WO (cold_reset);
@@ -258,10 +257,9 @@ static ssize_t warm_reset_store(struct device *dev,if (!dev)return -ENODEV ; -mutex_lock (&ac97_controllers_mutex); +guard (mutex)(&ac97_controllers_mutex); ac97_ctrl =to_ac97_controller (dev); ac97_ctrl->ops->warm_reset (ac97_ctrl); -mutex_unlock (&ac97_controllers_mutex);return len; }static DEVICE_ATTR_WO (warm_reset);
@@ -284,10 +282,10 @@ static const struct attribute_group *ac97_adapter_groups[] = {static void ac97_del_adapter (struct ac97_controller *ac97_ctrl) { -mutex_lock (&ac97_controllers_mutex); -ac97_ctrl_codecs_unregister (ac97_ctrl); -list_del (&ac97_ctrl->controllers); -mutex_unlock (&ac97_controllers_mutex); + scoped_guard(mutex, &ac97_controllers_mutex) { +ac97_ctrl_codecs_unregister (ac97_ctrl); +list_del (&ac97_ctrl->controllers); + }device_unregister (&ac97_ctrl->adap); }
@@ -311,7 +309,7 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl) {int ret; -mutex_lock (&ac97_controllers_mutex); +guard (mutex)(&ac97_controllers_mutex); ret =idr_alloc (&ac97_adapter_idr, ac97_ctrl,0 ,0 ,GFP_KERNEL ); ac97_ctrl->nr = ret;if (ret >=0 ) {
@@ -322,13 +320,11 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)if (ret)put_device (&ac97_ctrl->adap); } -if (!ret) +if (!ret) {list_add (&ac97_ctrl->controllers, &ac97_controllers); -mutex_unlock (&ac97_controllers_mutex); - -if (!ret)dev_dbg (&ac97_ctrl->adap,"adapter registered by %s\n" ,dev_name (ac97_ctrl->parent)); + }return ret; }
Signature · 1 line
2.50.1
PATCH 18/19 ALSA: virtio: Use guard() for spin locks
In reply to Takashi IwaiReplace the manual spin lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
--- sound/virtio/virtio_card.c | 8 ++--- sound/virtio/virtio_ctl_msg.c | 23 ++++++-------- sound/virtio/virtio_pcm.c | 8 ++--- sound/virtio/virtio_pcm_msg.c | 17 +++-------- sound/virtio/virtio_pcm_ops.c | 56 ++++++++++++----------------------- 5 files changed, 38 insertions(+), 74 deletions(-)
sound/virtio/virtio_card.c +2 -6
@@ -85,9 +85,8 @@ static void virtsnd_event_notify_cb(struct virtqueue *vqueue)struct virtio_snd_queue *queue =virtsnd_event_queue (snd);struct virtio_snd_event *event;u32 length; -unsigned long flags; -spin_lock_irqsave (&queue->lock, flags); +guard (spinlock_irqsave)(&queue->lock); do { virtqueue_disable_cb(vqueue); while ((event = virtqueue_get_buf(vqueue, &length))) {
@@ -95,7 +94,6 @@ static void virtsnd_event_notify_cb(struct virtqueue *vqueue)virtsnd_event_send (vqueue, event, true,GFP_ATOMIC ); } }while (!virtqueue_enable_cb (vqueue)); -spin_unlock_irqrestore (&queue->lock, flags); }/**
@@ -176,14 +174,12 @@ static void virtsnd_disable_event_vq(struct virtio_snd *snd)struct virtio_snd_queue *queue =virtsnd_event_queue (snd);struct virtio_snd_event *event;u32 length; -unsigned long flags;if (queue->vqueue) { -spin_lock_irqsave (&queue->lock, flags); +guard (spinlock_irqsave)(&queue->lock);virtqueue_disable_cb (queue->vqueue);while ((event =virtqueue_get_buf (queue->vqueue, &length)))virtsnd_event_dispatch (snd, event); -spin_unlock_irqrestore (&queue->lock, flags); } }
sound/virtio/virtio_ctl_msg.c +9 -14
@@ -131,7 +131,6 @@ int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg,unsigned int nins =0 ;struct scatterlist *psgs[4 ];bool notify = false; -unsigned long flags;int rc;virtsnd_ctl_msg_ref (msg);
@@ -147,15 +146,15 @@ int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg,if (in_sgs) psgs[nouts + nins++] = in_sgs; -spin_lock_irqsave (&queue->lock, flags); - rc =virtqueue_add_sgs (queue->vqueue, psgs, nouts, nins, msg, -GFP_ATOMIC ); -if (!rc) { - notify =virtqueue_kick_prepare (queue->vqueue); + scoped_guard(spinlock_irqsave, &queue->lock) { + rc =virtqueue_add_sgs (queue->vqueue, psgs, nouts, nins, msg, +GFP_ATOMIC ); +if (!rc) { + notify =virtqueue_kick_prepare (queue->vqueue); -list_add_tail (&msg->list, &snd->ctl_msgs); +list_add_tail (&msg->list, &snd->ctl_msgs); + } } -spin_unlock_irqrestore (&queue->lock, flags);if (rc) { dev_err(&vdev->dev, "failed to send control message (0x%08x)\n",
@@ -233,9 +232,8 @@ void virtsnd_ctl_msg_complete(struct virtio_snd_msg *msg)void virtsnd_ctl_msg_cancel_all (struct virtio_snd *snd) {struct virtio_snd_queue *queue =virtsnd_control_queue (snd); -unsigned long flags; -spin_lock_irqsave (&queue->lock, flags); +guard (spinlock_irqsave)(&queue->lock);while (!list_empty (&snd->ctl_msgs)) {struct virtio_snd_msg *msg = list_first_entry(&snd->ctl_msgs, struct virtio_snd_msg,
@@ -243,7 +241,6 @@ void virtsnd_ctl_msg_cancel_all(struct virtio_snd *snd)virtsnd_ctl_msg_complete (msg); } -spin_unlock_irqrestore (&queue->lock, flags); }/**
@@ -296,13 +293,11 @@ void virtsnd_ctl_notify_cb(struct virtqueue *vqueue)struct virtio_snd_queue *queue =virtsnd_control_queue (snd);struct virtio_snd_msg *msg;u32 length; -unsigned long flags; -spin_lock_irqsave (&queue->lock, flags); +guard (spinlock_irqsave)(&queue->lock);do {virtqueue_disable_cb (vqueue);while ((msg =virtqueue_get_buf (vqueue, &length)))virtsnd_ctl_msg_complete (msg); }while (!virtqueue_enable_cb (vqueue)); -spin_unlock_irqrestore (&queue->lock, flags); }
sound/virtio/virtio_pcm.c +4 -4
@@ -515,10 +515,10 @@ void virtsnd_pcm_event(struct virtio_snd *snd, struct virtio_snd_event *event)/* TODO: deal with shmem elapsed period */ break ;case VIRTIO_SND_EVT_PCM_XRUN : -spin_lock (&vss->lock); -if (vss->xfer_enabled) - vss->xfer_xrun = true; -spin_unlock (&vss->lock); + scoped_guard(spinlock, &vss->lock) { +if (vss->xfer_enabled) + vss->xfer_xrun = true; + }break ; } }
sound/virtio/virtio_pcm_msg.c +4 -13
@@ -272,14 +272,8 @@ int virtsnd_pcm_msg_send(struct virtio_pcm_substream *vss, unsigned long offset,*/ unsigned int virtsnd_pcm_msg_pending_num (struct virtio_pcm_substream *vss) { -unsigned int num; -unsigned long flags; - -spin_lock_irqsave (&vss->lock, flags); - num = vss->msg_count; -spin_unlock_irqrestore (&vss->lock, flags); - -return num; +guard (spinlock_irqsave)(&vss->lock); +return vss->msg_count; }/**
@@ -308,7 +302,7 @@ static void virtsnd_pcm_msg_complete(struct virtio_pcm_msg *msg,* in the virtqueue. Therefore, on each completion of an I/O message, * the hw_ptr value is unconditionally advanced. */ -spin_lock (&vss->lock); +guard (spinlock)(&vss->lock);/* * If the capture substream returned an incorrect status, then just * increase the hw_ptr by the message size.
@@ -338,7 +332,6 @@ static void virtsnd_pcm_msg_complete(struct virtio_pcm_msg *msg, }else if (!vss->msg_count) {wake_up_all (&vss->msg_empty); } -spin_unlock (&vss->lock); }/**
@@ -351,15 +344,13 @@ static inline void virtsnd_pcm_notify_cb(struct virtio_snd_queue *queue) {struct virtio_pcm_msg *msg;u32 written_bytes; -unsigned long flags; -spin_lock_irqsave (&queue->lock, flags); +guard (spinlock_irqsave)(&queue->lock);do {virtqueue_disable_cb (queue->vqueue);while ((msg =virtqueue_get_buf (queue->vqueue, &written_bytes)))virtsnd_pcm_msg_complete (msg, written_bytes); }while (!virtqueue_enable_cb (queue->vqueue)); -spin_unlock_irqrestore (&queue->lock, flags); }/**
sound/virtio/virtio_pcm_ops.c +19 -37
96 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 19/19 ALSA: misc: Use guard() for spin locks
In reply to Takashi IwaiClean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/core/misc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
sound/core/misc.c +10 -15
@@ -127,35 +127,30 @@ int snd_fasync_helper(int fd, struct file *file, int on,INIT_LIST_HEAD (&fasync->list); } -spin_lock_irq (&snd_fasync_lock); -if (*fasyncp) { -kfree (fasync); - fasync = *fasyncp; - }else { -if (!fasync) { -spin_unlock_irq (&snd_fasync_lock); -return 0 ; + scoped_guard(spinlock_irq, &snd_fasync_lock) { +if (*fasyncp) { +kfree (fasync); + fasync = *fasyncp; + }else { +if (!fasync) +return 0 ; + *fasyncp = fasync; } - *fasyncp = fasync; + fasync->on = on; } - fasync->on = on; -spin_unlock_irq (&snd_fasync_lock);return fasync_helper (fd, file, on, &fasync->fasync); }EXPORT_SYMBOL_GPL (snd_fasync_helper);void snd_kill_fasync (struct snd_fasync *fasync,int signal,int poll) { -unsigned long flags; -if (!fasync || !fasync->on)return ; -spin_lock_irqsave (&snd_fasync_lock, flags); +guard (spinlock_irqsave)(&snd_fasync_lock); fasync->signal = signal; fasync->poll = poll;list_move (&fasync->list, &snd_fasync_list);schedule_work (&snd_fasync_work); -spin_unlock_irqrestore (&snd_fasync_lock, flags); }EXPORT_SYMBOL_GPL (snd_kill_fasync);
Signature · 1 line
2.50.1