ALSA: Use auto-cleanup for PCI drivers
Subsystems (5)
cover ALSA: Use auto-cleanup for PCI drivers
This is another patch set for applying the auto-cleanup macros to sound/pci/* code. Merely code cleanups and no functional changes are expected by all those changes.
Takashi
===
Takashi Iwai (61):
ALSA: ac97: Use guard() for mutex locks
ALSA: ac97: Use guard() for spin locks
ALSA: ali5451: Use guard() for spin locks
ALSA: azt3328: Use guard() for spin locks
ALSA: ens137x: Use guard() for mutex locks
ALSA: ens137x: Use guard() for spin locks
ALSA: als300: Use guard() for spin locks
ALSA: als4000: Use guard() for spin locks
ALSA: ad1889: Use guard() for spin locks
ALSA: atiixp: Use guard() for mutex locks
ALSA: atiixp: Use guard() for spin locks
ALSA: aw2: Use guard() for mutex locks
ALSA: aw2: Use guard() for spin locks
ALSA: bt87x: Use guard() for spin locks
ALSA: ca0106: Use guard() for spin locks
ALSA: cmipci: Use guard() for mutex locks
ALSA: cmipci: Use guard() for spin locks
ALSA: cs4281: Use guard() for spin locks
ALSA: cs46xx: Use guard() for mutex locks
ALSA: cs46xx: Use guard() for spin locks
ALSA: cs5535audio: Use guard() for spin locks
ALSA: ctxfi: Use guard() for mutex locks
ALSA: ctxfi: Use guard() for spin locks
ALSA: echoaudio: Use guard() for mutex locks
ALSA: echoaudio: Use guard() for spin locks
ALSA: emu10k1: Use guard() for mutex locks
ALSA: emu10k1: Use guard() for emu1010 FPGA locking
ALSA: emu10k1: Use guard() for spin locks
ALSA: emu10k1x: Use guard() for spin locks
ALSA: es1938: Use guard() for spin locks
ALSA: es1968: Use guard() for mutex locks
ALSA: es1968: Use guard() for spin locks
ALSA: fm801: Use guard() for spin locks
ALSA: ice1712: Use guard() for mutex locks
ALSA: ice1712: Use guard() for spin locks
ALSA: intel8x0: Use guard() for spin locks
ALSA: korg1212: Use guard() for mutex locks
ALSA: korg1212: Use guard() for spin locks
ALSA: lola: Use guard() for mutex locks
ALSA: lola: Use guard() for spin locks
ALSA: lx6464es: Use guard() for mutex locks
ALSA: maestro3: Use guard() for spin locks
ALSA: mixart: Use guard() for mutex locks
ALSA: nm256: Use guard() for mutex locks
ALSA: nm256: Use guard() for spin locks
ALSA: oxygen: Use guard() for mutex locks
ALSA: oxygen: Use guard() for spin locks
ALSA: pcxhr: Use guard() for mutex locks
ALSA: rme32: Use guard() for spin locks
ALSA: rme96: Use guard() for spin locks
ALSA: hdsp: Use guard() for spin locks
ALSA: hdspm: Use guard() for spin locks
ALSA: rme9652: Use guard() for spin locks
ALSA: sis7019: Use guard() for mutex locks
ALSA: sis7019: Use guard() for spin locks
ALSA: sonicvibes: Use guard() for spin locks
ALSA: trident: Use guard() for mutex locks
ALSA: trident: Use guard() for spin locks
ALSA: via82xx: Use guard() for spin locks
ALSA: vx222: Use guard() for mutex locks
ALSA: ymfpci: Use guard() for spin locks
include/sound/emu10k1.h | 3 +- sound/pci/ac97/ac97_codec.c | 32 +-- sound/pci/ac97/ac97_patch.c | 9 +- sound/pci/ac97/ac97_pcm.c | 50 ++-- sound/pci/ac97/ac97_proc.c | 10 +- sound/pci/ad1889.c | 12 +- sound/pci/ak4531_codec.c | 18 +- sound/pci/ali5451/ali5451.c | 92 +++---- sound/pci/als300.c | 21 +- sound/pci/als4000.c | 68 +++-- sound/pci/atiixp.c | 69 ++--- sound/pci/atiixp_modem.c | 49 ++-- sound/pci/aw2/aw2-alsa.c | 26 +- sound/pci/azt3328.c | 143 +++++------ sound/pci/bt87x.c | 26 +- sound/pci/ca0106/ca0106_main.c | 33 +-- sound/pci/ca0106/ca0106_proc.c | 28 +- sound/pci/ca0106/ca_midi.c | 169 ++++++------ sound/pci/cmipci.c | 185 ++++++-------- sound/pci/cs4281.c | 53 ++-- sound/pci/cs46xx/cs46xx_lib.c | 200 ++++++--------- sound/pci/cs46xx/dsp_spos.c | 70 ++--- sound/pci/cs46xx/dsp_spos_scb_lib.c | 63 ++--- sound/pci/cs5535audio/cs5535audio.c | 14 +- sound/pci/cs5535audio/cs5535audio_pcm.c | 12 +- sound/pci/ctxfi/ctamixer.c | 67 +++-- sound/pci/ctxfi/ctatc.c | 28 +- sound/pci/ctxfi/ctdaio.c | 42 ++- sound/pci/ctxfi/cthw20k1.c | 39 +-- sound/pci/ctxfi/ctsrc.c | 101 +++----- sound/pci/ctxfi/cttimer.c | 63 ++--- sound/pci/ctxfi/ctvmem.c | 16 +- sound/pci/echoaudio/echoaudio.c | 128 ++++------ sound/pci/echoaudio/echoaudio_3g.c | 6 +- sound/pci/echoaudio/gina24_dsp.c | 3 +- sound/pci/echoaudio/layla24_dsp.c | 6 +- sound/pci/echoaudio/midi.c | 41 +-- sound/pci/echoaudio/mona_dsp.c | 3 +- sound/pci/emu10k1/emu10k1_main.c | 27 +- sound/pci/emu10k1/emu10k1_synth.c | 11 +- sound/pci/emu10k1/emu10k1x.c | 221 +++++++--------- sound/pci/emu10k1/emufx.c | 81 +++--- sound/pci/emu10k1/emumixer.c | 71 ++---- sound/pci/emu10k1/emumpu401.c | 173 ++++++------- sound/pci/emu10k1/emupcm.c | 58 ++--- sound/pci/emu10k1/emuproc.c | 19 +- sound/pci/emu10k1/io.c | 123 +++------ sound/pci/emu10k1/memory.c | 34 +-- sound/pci/emu10k1/p16v.c | 8 +- sound/pci/emu10k1/voice.c | 8 +- sound/pci/ens1370.c | 316 +++++++++++------------ sound/pci/es1938.c | 28 +- sound/pci/es1968.c | 160 +++++------- sound/pci/fm801.c | 71 +++--- sound/pci/ice1712/aureon.c | 27 +- sound/pci/ice1712/delta.c | 83 +++--- sound/pci/ice1712/ews.c | 53 ++-- sound/pci/ice1712/hoontech.c | 24 +- sound/pci/ice1712/ice1712.c | 186 ++++++-------- sound/pci/ice1712/ice1724.c | 314 +++++++++++------------ sound/pci/ice1712/maya44.c | 18 +- sound/pci/ice1712/phase.c | 6 +- sound/pci/ice1712/pontis.c | 70 ++--- sound/pci/ice1712/prodigy192.c | 11 +- sound/pci/ice1712/prodigy_hifi.c | 56 ++-- sound/pci/ice1712/quartet.c | 3 +- sound/pci/ice1712/wtm.c | 6 +- sound/pci/intel8x0.c | 178 +++++++------ sound/pci/intel8x0m.c | 8 +- sound/pci/korg1212/korg1212.c | 182 +++++-------- sound/pci/lola/lola.c | 4 +- sound/pci/lola/lola_pcm.c | 36 +-- sound/pci/lx6464es/lx6464es.c | 49 ++-- sound/pci/lx6464es/lx_core.c | 107 +++----- sound/pci/maestro3.c | 23 +- sound/pci/mixart/mixart.c | 48 ++-- sound/pci/mixart/mixart_core.c | 71 +++--- sound/pci/mixart/mixart_mixer.c | 46 ++-- sound/pci/nm256/nm256.c | 37 +-- sound/pci/oxygen/oxygen.c | 12 +- sound/pci/oxygen/oxygen_lib.c | 132 +++++----- sound/pci/oxygen/oxygen_mixer.c | 66 ++--- sound/pci/oxygen/oxygen_pcm.c | 165 ++++++------ sound/pci/oxygen/xonar_cs43xx.c | 6 +- sound/pci/oxygen/xonar_dg_mixer.c | 33 +-- sound/pci/oxygen/xonar_lib.c | 3 +- sound/pci/oxygen/xonar_pcm179x.c | 21 +- sound/pci/oxygen/xonar_wm87x6.c | 31 +-- sound/pci/pcxhr/pcxhr.c | 35 +-- sound/pci/pcxhr/pcxhr_core.c | 15 +- sound/pci/pcxhr/pcxhr_mix22.c | 23 +- sound/pci/pcxhr/pcxhr_mixer.c | 58 ++--- sound/pci/rme32.c | 152 ++++------- sound/pci/rme96.c | 211 +++++++-------- sound/pci/rme9652/hdsp.c | 309 +++++++++------------- sound/pci/rme9652/hdspm.c | 303 ++++++++++------------ sound/pci/rme9652/rme9652.c | 203 ++++++--------- sound/pci/sis7019.c | 43 ++-- sound/pci/sonicvibes.c | 113 ++++----- sound/pci/trident/trident_main.c | 324 ++++++++++-------------- sound/pci/trident/trident_memory.c | 19 +- sound/pci/via82xx.c | 80 +++--- sound/pci/via82xx_modem.c | 6 +- sound/pci/vx222/vx222_ops.c | 12 +- sound/pci/ymfpci/ymfpci_main.c | 248 ++++++++---------- 105 files changed, 3094 insertions(+), 4582 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/61 ALSA: ac97: 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/pci/ac97/ac97_codec.c | 32 ++++++++++---------------------- sound/pci/ac97/ac97_patch.c | 9 +++------ sound/pci/ac97/ac97_pcm.c | 3 +-- sound/pci/ac97/ac97_proc.c | 10 ++++------ 4 files changed, 18 insertions(+), 36 deletions(-)
sound/pci/ac97/ac97_codec.c +10 -22
@@ -326,11 +326,10 @@ void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned sh {if (!snd_ac97_valid_reg (ac97, reg))return ; -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); ac97->regs[reg] = value; ac97->bus->ops->write (ac97, reg, value);set_bit (reg, ac97->reg_accessed); -mutex_unlock (&ac97->reg_mutex); }EXPORT_SYMBOL (snd_ac97_write_cache);
@@ -353,14 +352,13 @@ int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short vaif (!snd_ac97_valid_reg (ac97, reg))return -EINVAL ; -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); change = ac97->regs[reg] != value;if (change) { ac97->regs[reg] = value; ac97->bus->ops->write (ac97, reg, value); }set_bit (reg, ac97->reg_accessed); -mutex_unlock (&ac97->reg_mutex);return change; }
@@ -381,14 +379,10 @@ EXPORT_SYMBOL(snd_ac97_update);*/ int snd_ac97_update_bits (struct snd_ac97 *ac97,unsigned short reg,unsigned short mask,unsigned short value) { -int change; -if (!snd_ac97_valid_reg (ac97, reg))return -EINVAL ; -mutex_lock (&ac97->reg_mutex); - change =snd_ac97_update_bits_nolock (ac97, reg, mask, value); -mutex_unlock (&ac97->reg_mutex); -return change; +guard (mutex)(&ac97->reg_mutex); +return snd_ac97_update_bits_nolock (ac97, reg, mask, value); }EXPORT_SYMBOL (snd_ac97_update_bits);
@@ -416,12 +410,12 @@ static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsint change;unsigned short old, new, cfg; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex); old = ac97->spec.ad18xx.pcmreg[codec]; new = (old & ~mask) | (value & mask); change = old != new;if (change) { -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); cfg =snd_ac97_read_cache (ac97,AC97_AD_SERIAL_CFG ); ac97->spec.ad18xx.pcmreg[codec] = new;/* select single codec */
@@ -433,9 +427,7 @@ static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, uns/* select all codecs */ ac97->bus->ops->write (ac97,AC97_AD_SERIAL_CFG , cfg |0x7000 ); -mutex_unlock (&ac97->reg_mutex); } -mutex_unlock (&ac97->page_mutex);return change; }
@@ -716,12 +708,11 @@ static int snd_ac97_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ {struct snd_ac97 *ac97 =snd_kcontrol_chip (kcontrol); -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); ucontrol->value.iec958.status[0 ] = ac97->spdif_status &0xff ; ucontrol->value.iec958.status[1 ] = (ac97->spdif_status >>8 ) &0xff ; ucontrol->value.iec958.status[2 ] = (ac97->spdif_status >>16 ) &0xff ; ucontrol->value.iec958.status[3 ] = (ac97->spdif_status >>24 ) &0xff ; -mutex_unlock (&ac97->reg_mutex);return 0 ; }
@@ -760,7 +751,7 @@ static int snd_ac97_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ } } -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); change = ac97->spdif_status != new; ac97->spdif_status = new;
@@ -794,7 +785,6 @@ static int snd_ac97_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_snd_ac97_update_bits_nolock (ac97,AC97_EXTENDED_STATUS ,AC97_EA_SPDIF ,AC97_EA_SPDIF );/* turn on again */ } } -mutex_unlock (&ac97->reg_mutex);return change; }
@@ -811,7 +801,7 @@ static int snd_ac97_put_spsa(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ value = (ucontrol->value.integer.value[0 ] & mask); -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); mask <<= shift; value <<= shift; old =snd_ac97_read_cache (ac97, reg);
@@ -825,7 +815,6 @@ static int snd_ac97_put_spsa(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_if (extst &AC97_EA_SPDIF )snd_ac97_update_bits_nolock (ac97,AC97_EXTENDED_STATUS ,AC97_EA_SPDIF ,AC97_EA_SPDIF );/* turn on again */ } -mutex_unlock (&ac97->reg_mutex);return change; }
@@ -936,10 +925,9 @@ static int snd_ac97_ad18xx_pcm_get_volume(struct snd_kcontrol *kcontrol, structstruct snd_ac97 *ac97 =snd_kcontrol_chip (kcontrol);int codec = kcontrol->private_value &3 ; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex); ucontrol->value.integer.value[0 ] =31 - ((ac97->spec.ad18xx.pcmreg[codec] >>8 ) &31 ); ucontrol->value.integer.value[1 ] =31 - ((ac97->spec.ad18xx.pcmreg[codec] >>0 ) &31 ); -mutex_unlock (&ac97->page_mutex);return 0 ; }
sound/pci/ac97/ac97_patch.c +3 -6
@@ -54,12 +54,11 @@ static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsiunsigned short page_save;int ret; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex); page_save =snd_ac97_read (ac97,AC97_INT_PAGING ) &AC97_PAGE_MASK ;snd_ac97_update_bits (ac97,AC97_INT_PAGING ,AC97_PAGE_MASK , page); ret =snd_ac97_update_bits (ac97, reg, mask, value);snd_ac97_update_bits (ac97,AC97_INT_PAGING ,AC97_PAGE_MASK , page_save); -mutex_unlock (&ac97->page_mutex);/* unlock paging */ return ret; }
@@ -976,12 +975,11 @@ static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_struct snd_ac97 *ac97 =snd_kcontrol_chip (kcontrol);int err; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex);snd_ac97_write (ac97,AC97_SIGMATEL_BIAS1 ,0xabba ); err =snd_ac97_update_bits (ac97,AC97_SIGMATEL_BIAS2 ,0x0010 , (ucontrol->value.integer.value[0 ] &1 ) <<4 );snd_ac97_write (ac97,AC97_SIGMATEL_BIAS1 ,0 ); -mutex_unlock (&ac97->page_mutex);return err; }
@@ -3699,7 +3697,7 @@ static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,unsigned short datpag, uaj;struct snd_ac97 *pac97 =snd_kcontrol_chip (kcontrol); -mutex_lock (&pac97->page_mutex); +guard (mutex)(&pac97->page_mutex); datpag =snd_ac97_read (pac97,AC97_INT_PAGING ) &AC97_PAGE_MASK ;snd_ac97_update_bits (pac97,AC97_INT_PAGING ,AC97_PAGE_MASK ,0 );
@@ -3708,7 +3706,6 @@ static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol, vt1618_uaj[kcontrol->private_value].mask;snd_ac97_update_bits (pac97,AC97_INT_PAGING ,AC97_PAGE_MASK , datpag); -mutex_unlock (&pac97->page_mutex); ucontrol->value.enumerated.item[0 ] = uaj >> vt1618_uaj[kcontrol->private_value].shift;
sound/pci/ac97/ac97_pcm.c +1 -2
@@ -192,7 +192,7 @@ static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate) mask =AC97_SC_SPSR_MASK ; } -mutex_lock (&ac97->reg_mutex); +guard (mutex)(&ac97->reg_mutex); old =snd_ac97_read (ac97, reg) & mask;if (old != bits) {snd_ac97_update_bits_nolock (ac97,AC97_EXTENDED_STATUS ,AC97_EA_SPDIF ,0 );
@@ -217,7 +217,6 @@ static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate) ac97->spdif_status = sbits; }snd_ac97_update_bits_nolock (ac97,AC97_EXTENDED_STATUS ,AC97_EA_SPDIF ,AC97_EA_SPDIF ); -mutex_unlock (&ac97->reg_mutex);return 0 ; }
sound/pci/ac97/ac97_proc.c +4 -6
@@ -329,7 +329,7 @@ static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buf {struct snd_ac97 *ac97 = entry->private_data; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex);if ((ac97->id &0xffffff40 ) ==AC97_ID_AD1881 ) {// Analog Devices AD1881/85/86 int idx;for (idx =0 ; idx <3 ; idx++)
@@ -355,7 +355,6 @@ static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buf }else {snd_ac97_proc_read_main (ac97, buffer,0 ); } -mutex_unlock (&ac97->page_mutex); }#ifdef CONFIG_SND_DEBUG
@@ -365,7 +364,8 @@ static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_instruct snd_ac97 *ac97 = entry->private_data;char line[64 ];unsigned int reg, val; -mutex_lock (&ac97->page_mutex); + +guard (mutex)(&ac97->page_mutex);while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ;
@@ -373,7 +373,6 @@ static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_inif (reg <0x80 && (reg &1 ) ==0 && val <=0xffff ) snd_ac97_write_cache(ac97, reg, val); } -mutex_unlock (&ac97->page_mutex); }#endif
@@ -392,7 +391,7 @@ static void snd_ac97_proc_regs_read(struct snd_info_entry *entry, {struct snd_ac97 *ac97 = entry->private_data; -mutex_lock (&ac97->page_mutex); +guard (mutex)(&ac97->page_mutex);if ((ac97->id &0xffffff40 ) ==AC97_ID_AD1881 ) {// Analog Devices AD1881/85/86 int idx;
@@ -408,7 +407,6 @@ static void snd_ac97_proc_regs_read(struct snd_info_entry *entry, }else {snd_ac97_proc_regs_read_main (ac97, buffer,0 ); } -mutex_unlock (&ac97->page_mutex); }void snd_ac97_proc_init (struct snd_ac97 * ac97)
Signature · 1 line
2.50.1
PATCH 2/61 ALSA: ac97: 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/pci/ac97/ac97_pcm.c | 47 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-)
sound/pci/ac97/ac97_pcm.c +22 -25
@@ -570,33 +570,31 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,return err; } } -spin_lock_irq (&pcm->bus->bus_lock); -for (i =3 ; i <12 ; i++) { -if (!(slots & (1 << i))) -continue ; - ok_flag =0 ; -for (cidx =0 ; cidx <4 ; cidx++) { -if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { -spin_unlock_irq (&pcm->bus->bus_lock); - err = -EBUSY ; + scoped_guard(spinlock_irq, &pcm->bus->bus_lock) { +for (i =3 ; i <12 ; i++) { +if (!(slots & (1 << i))) +continue ; + ok_flag =0 ; +for (cidx =0 ; cidx <4 ; cidx++) { +if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { + err = -EBUSY ; + goto error; + } +if (pcm->r[r].rslots[cidx] & (1 << i)) { + bus->used_slots[pcm->stream][cidx] |= (1 << i); + ok_flag++; + } + } +if (!ok_flag) { +dev_err (bus->card->dev, +"cannot find configuration for AC97 slot %i\n" , + i); + err = -EAGAIN ; goto error; } -if (pcm->r[r].rslots[cidx] & (1 << i)) { - bus->used_slots[pcm->stream][cidx] |= (1 << i); - ok_flag++; - } - } -if (!ok_flag) { -spin_unlock_irq (&pcm->bus->bus_lock); -dev_err (bus->card->dev, -"cannot find configuration for AC97 slot %i\n" , - i); - err = -EAGAIN ; - goto error; } + pcm->cur_dbl = r; } - pcm->cur_dbl = r; -spin_unlock_irq (&pcm->bus->bus_lock);for (i =3 ; i <12 ; i++) {if (!(slots & (1 << i)))continue ;
@@ -664,7 +662,7 @@ int snd_ac97_pcm_close(struct ac97_pcm *pcm)#endif bus = pcm->bus; -spin_lock_irq (&pcm->bus->bus_lock); +guard (spinlock_irq)(&pcm->bus->bus_lock);for (i =3 ; i <12 ; i++) {if (!(slots & (1 << i)))continue ;
@@ -673,7 +671,6 @@ int snd_ac97_pcm_close(struct ac97_pcm *pcm) } pcm->aslots =0 ; pcm->cur_dbl =0 ; -spin_unlock_irq (&pcm->bus->bus_lock);return 0 ; }
Signature · 1 line
2.50.1
PATCH 3/61 ALSA: ali5451: 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/pci/ali5451/ali5451.c | 92 +++++++++++++++---------------------- 1 file changed, 38 insertions(+), 54 deletions(-)
sound/pci/ali5451/ali5451.c +38 -54
@@ -911,13 +911,12 @@ static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec,dev_dbg (codec->card->dev,"alloc_voice: type=%d rec=%d\n" , type, rec); -spin_lock_irq (&codec->voice_alloc); +guard (spinlock_irq)(&codec->voice_alloc);if (type ==SNDRV_ALI_VOICE_TYPE_PCM ) { idx = channel >0 ?snd_ali_alloc_pcm_channel (codec, channel) :snd_ali_find_free_channel (codec,rec);if (idx <0 ) {dev_err (codec->card->dev,"ali_alloc_voice: err.\n" ); -spin_unlock_irq (&codec->voice_alloc);return NULL ; } pvoice = &(codec->synth.voices[idx]);
@@ -925,10 +924,8 @@ static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, pvoice->use =1 ; pvoice->pcm =1 ; pvoice->mode = rec; -spin_unlock_irq (&codec->voice_alloc);return pvoice; } -spin_unlock_irq (&codec->voice_alloc);return NULL ; }
@@ -943,16 +940,16 @@ static void snd_ali_free_voice(struct snd_ali * codec,if (!pvoice->use)return ;snd_ali_clear_voices (codec, pvoice->number, pvoice->number); -spin_lock_irq (&codec->voice_alloc); - private_free = pvoice->private_free; - private_data = pvoice->private_data; - pvoice->private_free =NULL ; - pvoice->private_data =NULL ; -if (pvoice->pcm) -snd_ali_free_channel_pcm (codec, pvoice->number); - pvoice->use = pvoice->pcm = pvoice->synth =0 ; - pvoice->substream =NULL ; -spin_unlock_irq (&codec->voice_alloc); + scoped_guard(spinlock_irq, &codec->voice_alloc) { + private_free = pvoice->private_free; + private_data = pvoice->private_data; + pvoice->private_free =NULL ; + pvoice->private_data =NULL ; +if (pvoice->pcm) +snd_ali_free_channel_pcm (codec, pvoice->number); + pvoice->use = pvoice->pcm = pvoice->synth =0 ; + pvoice->substream =NULL ; + }if (private_free)private_free (private_data); }
@@ -1109,7 +1106,7 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,snd_pcm_trigger_done (s, substream); } } -spin_lock (&codec->reg_lock); +guard (spinlock)(&codec->reg_lock);if (!do_start)outl (what,ALI_REG (codec,ALI_STOP )); val =inl (ALI_REG (codec,ALI_AINTEN ));
@@ -1121,7 +1118,6 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,if (do_start)outl (what,ALI_REG (codec,ALI_START ));dev_dbg (codec->card->dev,"trigger: what=%xh whati=%xh\n" , what, whati); -spin_unlock (&codec->reg_lock);return 0 ; }
@@ -1189,8 +1185,8 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)dev_dbg (codec->card->dev,"playback_prepare ...\n" ); -spin_lock_irq (&codec->reg_lock); - +guard (spinlock_irq)(&codec->reg_lock); +/* set Delta (rate) value */ Delta =snd_ali_convert_rate (runtime->rate,0 );
@@ -1259,7 +1255,6 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)CTRL , EC); } -spin_unlock_irq (&codec->reg_lock);return 0 ; }
@@ -1360,14 +1355,11 @@ snd_ali_playback_pointer(struct snd_pcm_substream *substream)struct snd_ali_voice *pvoice = runtime->private_data;unsigned int cso; -spin_lock (&codec->reg_lock); -if (!pvoice->running) { -spin_unlock (&codec->reg_lock); +guard (spinlock)(&codec->reg_lock); +if (!pvoice->running)return 0 ; - }outb (pvoice->number,ALI_REG (codec,ALI_GC_CIR )); cso =inw (ALI_REG (codec,ALI_CSO_ALPHA_FMS +2 )); -spin_unlock (&codec->reg_lock);dev_dbg (codec->card->dev,"playback pointer returned cso=%xh.\n" , cso); cso %= runtime->buffer_size;
@@ -1382,14 +1374,11 @@ static snd_pcm_uframes_t snd_ali_pointer(struct snd_pcm_substream *substream)struct snd_ali_voice *pvoice = runtime->private_data;unsigned int cso; -spin_lock (&codec->reg_lock); -if (!pvoice->running) { -spin_unlock (&codec->reg_lock); +guard (spinlock)(&codec->reg_lock); +if (!pvoice->running)return 0 ; - }outb (pvoice->number,ALI_REG (codec,ALI_GC_CIR )); cso =inw (ALI_REG (codec,ALI_CSO_ALPHA_FMS +2 )); -spin_unlock (&codec->reg_lock); cso %= runtime->buffer_size;return cso;
@@ -1693,7 +1682,7 @@ static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol, spdif_enable = ucontrol->value.integer.value[0 ] ?1 :0 ; -spin_lock_irq (&codec->reg_lock); +guard (spinlock_irq)(&codec->reg_lock);switch (kcontrol->private_value) {case 0 : spdif_enable = (codec->spdif_mask &0x02 ) ?1 :0 ;
@@ -1709,7 +1698,6 @@ static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol,break ; } ucontrol->value.integer.value[0 ] = spdif_enable; -spin_unlock_irq (&codec->reg_lock);return 0 ; }
@@ -1721,7 +1709,7 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol, spdif_enable = ucontrol->value.integer.value[0 ] ?1 :0 ; -spin_lock_irq (&codec->reg_lock); +guard (spinlock_irq)(&codec->reg_lock);switch (kcontrol->private_value) {case 0 : change = (codec->spdif_mask &0x02 ) ?1 :0 ;
@@ -1766,7 +1754,6 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,default :break ; } -spin_unlock_irq (&codec->reg_lock);return change; }
@@ -1833,7 +1820,7 @@ static int ali_suspend(struct device *dev)for (i =0 ; i < chip->num_of_codecs; i++)snd_ac97_suspend (chip->ac97[i]); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); im->regs[ALI_MISCINT >>2 ] =inl (ALI_REG (chip,ALI_MISCINT ));/* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */
@@ -1857,7 +1844,6 @@ static int ali_suspend(struct device *dev)/* stop all HW channel */ outl (0xffffffff ,ALI_REG (chip,ALI_STOP )); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1868,27 +1854,25 @@ static int ali_resume(struct device *dev)struct snd_ali_image *im = &chip->image;int i, j; -spin_lock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { +for (i =0 ; i <ALI_CHANNELS ; i++) { +outb (i,ALI_REG (chip,ALI_GC_CIR )); +for (j =0 ; j <ALI_CHANNEL_REGS ; j++) +outl (im->channel_regs[i][j],ALI_REG (chip, j*4 +0xe0 )); + } -for (i =0 ; i <ALI_CHANNELS ; i++) { -outb (i,ALI_REG (chip,ALI_GC_CIR )); -for (j =0 ; j <ALI_CHANNEL_REGS ; j++) -outl (im->channel_regs[i][j],ALI_REG (chip, j*4 +0xe0 )); +for (i =0 ; i <ALI_GLOBAL_REGS ; i++) { +if ((i*4 ==ALI_MISCINT ) || (i*4 ==ALI_STOP ) || + (i*4 ==ALI_START )) +continue ; +outl (im->regs[i],ALI_REG (chip, i*4 )); + } + +/* start HW channel */ +outl (im->regs[ALI_START >>2 ],ALI_REG (chip,ALI_START )); +/* restore IRQ enable bits */ +outl (im->regs[ALI_MISCINT >>2 ],ALI_REG (chip,ALI_MISCINT )); } - -for (i =0 ; i <ALI_GLOBAL_REGS ; i++) { -if ((i*4 ==ALI_MISCINT ) || (i*4 ==ALI_STOP ) || - (i*4 ==ALI_START )) -continue ; -outl (im->regs[i],ALI_REG (chip, i*4 )); - } - -/* start HW channel */ -outl (im->regs[ALI_START >>2 ],ALI_REG (chip,ALI_START )); -/* restore IRQ enable bits */ -outl (im->regs[ALI_MISCINT >>2 ],ALI_REG (chip,ALI_MISCINT )); - -spin_unlock_irq (&chip->reg_lock);for (i =0 ; i < chip->num_of_codecs; i++)snd_ac97_resume (chip->ac97[i]);
Signature · 1 line
2.50.1
PATCH 4/61 ALSA: azt3328: 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/pci/azt3328.c | 143 ++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 78 deletions(-)
sound/pci/azt3328.c +65 -78
@@ -1201,7 +1201,6 @@ snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,unsigned int channels ) { -unsigned long flags;u16 val =0xff00 ;u8 freq =0 ;
@@ -1244,7 +1243,7 @@ snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,if (format_width ==16 ) val |=SOUNDFORMAT_FLAG_16BIT ; -spin_lock_irqsave (codec->lock, flags); +guard (spinlock_irqsave)(codec->lock);/* set bitrate/format */ snd_azf3328_codec_outw (codec,IDX_IO_CODEC_SOUNDFORMAT , val);
@@ -1266,8 +1265,6 @@ snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,DMA_EPILOGUE_SOMETHING |DMA_SOMETHING_ELSE ); - -spin_unlock_irqrestore (codec->lock, flags); } static inline void
@@ -1373,8 +1370,6 @@ snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,if (!codec->running) {/* AZF3328 uses a two buffer pointer DMA transfer approach */ -unsigned long flags; -/* width 32bit (prevent overflow): */ u32 area_length; struct codec_setup_io {
@@ -1405,11 +1400,10 @@ snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,/* build combined I/O buffer length word */ setup_io.dma_lengths = (area_length <<16 ) | (area_length); -spin_lock_irqsave (codec->lock, flags); +guard (spinlock_irqsave)(codec->lock);snd_azf3328_codec_outl_multi ( codec,IDX_IO_CODEC_DMA_START_1 , &setup_io,3 ); -spin_unlock_irqrestore (codec->lock, flags); } }
@@ -1464,48 +1458,48 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)snd_pcm_format_width (runtime->format), runtime->channels); -spin_lock (codec->lock); -/* first, remember current value: */ - flags1 =snd_azf3328_codec_inw (codec,IDX_IO_CODEC_DMA_FLAGS ); + scoped_guard(spinlock, codec->lock) { +/* first, remember current value: */ + flags1 =snd_azf3328_codec_inw (codec,IDX_IO_CODEC_DMA_FLAGS ); -/* stop transfer */ - flags1 &= ~DMA_RESUME ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); +/* stop transfer */ + flags1 &= ~DMA_RESUME ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); -/* FIXME: clear interrupts or what??? */ -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_IRQTYPE ,0xffff ); -spin_unlock (codec->lock); +/* FIXME: clear interrupts or what??? */ +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_IRQTYPE ,0xffff ); + }snd_azf3328_codec_setdmaa (chip, codec, runtime->dma_addr,snd_pcm_lib_period_bytes (substream),snd_pcm_lib_buffer_bytes (substream) ); -spin_lock (codec->lock); + scoped_guard(spinlock, codec->lock) {#ifdef WIN9X -/* FIXME: enable playback/recording??? */ - flags1 |=DMA_RUN_SOMETHING1 |DMA_RUN_SOMETHING2 ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); +/* FIXME: enable playback/recording??? */ + flags1 |=DMA_RUN_SOMETHING1 |DMA_RUN_SOMETHING2 ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); -/* start transfer again */ -/* FIXME: what is this value (0x0010)??? */ - flags1 |=DMA_RESUME |DMA_EPILOGUE_SOMETHING ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); +/* start transfer again */ +/* FIXME: what is this value (0x0010)??? */ + flags1 |=DMA_RESUME |DMA_EPILOGUE_SOMETHING ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1);#else /* NT4 */ -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , -0x0000 ); -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , -DMA_RUN_SOMETHING1 ); -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , -DMA_RUN_SOMETHING1 | -DMA_RUN_SOMETHING2 ); -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , -DMA_RESUME | -SOMETHING_ALMOST_ALWAYS_SET | -DMA_EPILOGUE_SOMETHING | -DMA_SOMETHING_ELSE ); +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , +0x0000 ); +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , +DMA_RUN_SOMETHING1 ); +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , +DMA_RUN_SOMETHING1 | +DMA_RUN_SOMETHING2 ); +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , +DMA_RESUME | +SOMETHING_ALMOST_ALWAYS_SET | +DMA_EPILOGUE_SOMETHING | +DMA_SOMETHING_ELSE );#endif -spin_unlock (codec->lock); + }snd_azf3328_ctrl_codec_activity (chip, codec->type,1 );if (is_main_mixer_playback_codec) {
@@ -1521,14 +1515,14 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)case SNDRV_PCM_TRIGGER_RESUME :dev_dbg (chip->card->dev,"PCM RESUME %s\n" , codec->name);/* resume codec if we were active */ -spin_lock (codec->lock); -if (codec->running) -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , -snd_azf3328_codec_inw ( - codec,IDX_IO_CODEC_DMA_FLAGS - ) |DMA_RESUME - ); -spin_unlock (codec->lock); + scoped_guard(spinlock, codec->lock) { +if (codec->running) +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , +snd_azf3328_codec_inw ( + codec,IDX_IO_CODEC_DMA_FLAGS + ) |DMA_RESUME + ); + }break ;case SNDRV_PCM_TRIGGER_STOP :dev_dbg (chip->card->dev,"PCM STOP %s\n" , codec->name);
@@ -1541,22 +1535,22 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd) ); } -spin_lock (codec->lock); -/* first, remember current value: */ - flags1 =snd_azf3328_codec_inw (codec,IDX_IO_CODEC_DMA_FLAGS ); + scoped_guard(spinlock, codec->lock) { +/* first, remember current value: */ + flags1 =snd_azf3328_codec_inw (codec,IDX_IO_CODEC_DMA_FLAGS ); -/* stop transfer */ - flags1 &= ~DMA_RESUME ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); +/* stop transfer */ + flags1 &= ~DMA_RESUME ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); -/* hmm, is this really required? we're resetting the same bit -* immediately thereafter... */ - flags1 |=DMA_RUN_SOMETHING1 ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); +/* hmm, is this really required? we're resetting the same bit +* immediately thereafter... */ + flags1 |=DMA_RUN_SOMETHING1 ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); - flags1 &= ~DMA_RUN_SOMETHING1 ; -snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); -spin_unlock (codec->lock); + flags1 &= ~DMA_RUN_SOMETHING1 ; +snd_azf3328_codec_outw (codec,IDX_IO_CODEC_DMA_FLAGS , flags1); + }snd_azf3328_ctrl_codec_activity (chip, codec->type,0 );if (is_main_mixer_playback_codec) {
@@ -1724,12 +1718,11 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,struct snd_azf3328 *chip =gameport_get_port_data (gameport);int i;u8 val; -unsigned long flags;if (snd_BUG_ON (!chip))return 0 ; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock); val =snd_azf3328_game_inb (chip,IDX_GAME_LEGACY_COMPATIBLE ); *buttons = (~(val) >>4 ) &0xf ;
@@ -1766,7 +1759,6 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,snd_azf3328_game_outb (chip,IDX_GAME_AXES_CONFIG , val);snd_azf3328_game_outw (chip,IDX_GAME_AXIS_VALUE ,0xffff ); -spin_unlock_irqrestore (&chip->reg_lock, flags);for (i =0 ; i <ARRAY_SIZE (chip->axes); i++) { axes[i] = chip->axes[i];
@@ -1863,11 +1855,11 @@ snd_azf3328_pcm_interrupt(struct snd_azf3328 *chip,if (!(status & (1 << codec_type)))continue ; -spin_lock (codec->lock); - which =snd_azf3328_codec_inb (codec,IDX_IO_CODEC_IRQTYPE ); -/* ack all IRQ types immediately */ -snd_azf3328_codec_outb (codec,IDX_IO_CODEC_IRQTYPE , which); -spin_unlock (codec->lock); + scoped_guard(spinlock, codec->lock) { + which =snd_azf3328_codec_inb (codec,IDX_IO_CODEC_IRQTYPE ); +/* ack all IRQ types immediately */ +snd_azf3328_codec_outb (codec,IDX_IO_CODEC_IRQTYPE , which); + }if (codec->substream) {snd_pcm_period_elapsed (codec->substream);
@@ -1912,9 +1904,9 @@ snd_azf3328_interrupt(int irq, void *dev_id)if (chip->timer)snd_timer_interrupt (chip->timer, chip->timer->sticks);/* ACK timer */ -spin_lock (&chip->reg_lock); -snd_azf3328_ctrl_outb (chip,IDX_IO_TIMER_VALUE +3 ,0x07 ); -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { +snd_azf3328_ctrl_outb (chip,IDX_IO_TIMER_VALUE +3 ,0x07 ); + }dev_dbg (chip->card->dev,"timer IRQ\n" ); }
@@ -2137,7 +2129,6 @@ static int snd_azf3328_timer_start(struct snd_timer *timer) {struct snd_azf3328 *chip; -unsigned long flags;unsigned int delay; chip =snd_timer_chip (timer);
@@ -2152,9 +2143,8 @@ snd_azf3328_timer_start(struct snd_timer *timer) }dev_dbg (chip->card->dev,"setting timer countdown value %d\n" , delay); delay |=TIMER_COUNTDOWN_ENABLE |TIMER_IRQ_ENABLE ; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);snd_azf3328_ctrl_outl (chip,IDX_IO_TIMER_VALUE , delay); -spin_unlock_irqrestore (&chip->reg_lock, flags);return 0 ; }
@@ -2162,10 +2152,9 @@ static int snd_azf3328_timer_stop(struct snd_timer *timer) {struct snd_azf3328 *chip; -unsigned long flags; chip =snd_timer_chip (timer); -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);/* disable timer countdown and interrupt */ /* Hmm, should we write TIMER_IRQ_ACK here? YES indeed, otherwise a rogue timer operation - which prompts
@@ -2174,7 +2163,6 @@ snd_azf3328_timer_stop(struct snd_timer *timer)Simply manually poking 0x04 _once_ immediately successfully stops the hardware/ALSA interrupt activity. */ snd_azf3328_ctrl_outb (chip,IDX_IO_TIMER_VALUE +3 ,0x04 ); -spin_unlock_irqrestore (&chip->reg_lock, flags);return 0 ; }
@@ -2406,10 +2394,9 @@ snd_azf3328_create(struct snd_card *card, codec->running = true;snd_azf3328_ctrl_codec_activity (chip, codec_type,0 ); -spin_lock_irq (codec->lock); +guard (spinlock_irq)(codec->lock);snd_azf3328_codec_outb (codec,IDX_IO_CODEC_DMA_FLAGS , dma_init); -spin_unlock_irq (codec->lock); }return 0 ;
Signature · 1 line
2.50.1
PATCH 5/61 ALSA: ens137x: 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/pci/ak4531_codec.c | 18 ++++++------------ sound/pci/ens1370.c | 13 ++++--------- 2 files changed, 10 insertions(+), 21 deletions(-)
sound/pci/ak4531_codec.c +6 -12
@@ -77,9 +77,8 @@ static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_eint invert = (kcontrol->private_value >>22 ) &1 ;int val; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex); val = (ak4531->regs[reg] >> shift) & mask; -mutex_unlock (&ak4531->reg_mutex);if (invert) { val = mask - val; }
@@ -102,11 +101,10 @@ static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_e val = mask - val; } val <<= shift; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex); val = (ak4531->regs[reg] & ~(mask << shift)) | val; change = val != ak4531->regs[reg]; ak4531->write (ak4531, reg, ak4531->regs[reg] = val); -mutex_unlock (&ak4531->reg_mutex);return change; }
@@ -146,10 +144,9 @@ static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_eint invert = (kcontrol->private_value >>22 ) &1 ;int left, right; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex); left = (ak4531->regs[left_reg] >> left_shift) & mask; right = (ak4531->regs[right_reg] >> right_shift) & mask; -mutex_unlock (&ak4531->reg_mutex);if (invert) { left = mask - left; right = mask - right;
@@ -179,7 +176,7 @@ static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e } left <<= left_shift; right <<= right_shift; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex);if (left_reg == right_reg) { left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right; change = left != ak4531->regs[left_reg];
@@ -191,7 +188,6 @@ static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e ak4531->write (ak4531, left_reg, ak4531->regs[left_reg] = left); ak4531->write (ak4531, right_reg, ak4531->regs[right_reg] = right); } -mutex_unlock (&ak4531->reg_mutex);return change; }
@@ -218,12 +214,11 @@ static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctlint left_shift = (kcontrol->private_value >>16 ) &0x0f ;int right_shift = (kcontrol->private_value >>24 ) &0x0f ; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex); ucontrol->value.integer.value[0 ] = (ak4531->regs[reg1] >> left_shift) &1 ; ucontrol->value.integer.value[1 ] = (ak4531->regs[reg2] >> left_shift) &1 ; ucontrol->value.integer.value[2 ] = (ak4531->regs[reg1] >> right_shift) &1 ; ucontrol->value.integer.value[3 ] = (ak4531->regs[reg2] >> right_shift) &1 ; -mutex_unlock (&ak4531->reg_mutex);return 0 ; }
@@ -237,7 +232,7 @@ static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctlint change;int val1, val2; -mutex_lock (&ak4531->reg_mutex); +guard (mutex)(&ak4531->reg_mutex); val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift)); val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift)); val1 |= (ucontrol->value.integer.value[0 ] &1 ) << left_shift;
@@ -247,7 +242,6 @@ static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2]; ak4531->write (ak4531, reg1, ak4531->regs[reg1] = val1); ak4531->write (ak4531, reg2, ak4531->regs[reg2] = val2); -mutex_unlock (&ak4531->reg_mutex);return change; }
sound/pci/ens1370.c +4 -9
@@ -596,7 +596,7 @@ static void snd_es1371_codec_write(struct snd_ac97 *ac97,unsigned int t, x, flag; flag =is_ev1938 (ensoniq) ?EV_1938_CODEC_MAGIC :0 ; -mutex_lock (&ensoniq->src_mutex); +guard (mutex)(&ensoniq->src_mutex);for (t =0 ; t <POLL_COUNT ; t++) { if (!(inl(ES_REG(ensoniq, 1371_CODEC)) & ES_1371_CODEC_WIP)) {/* save the current state for latter */
@@ -622,11 +622,9 @@ static void snd_es1371_codec_write(struct snd_ac97 *ac97,/* restore SRC reg */ snd_es1371_wait_src_ready (ensoniq); outl(x, ES_REG(ensoniq, 1371_SMPRATE)); -mutex_unlock (&ensoniq->src_mutex);return ; } } -mutex_unlock (&ensoniq->src_mutex);dev_err (ensoniq->card->dev,"codec write timeout at 0x%lx [0x%x]\n" , ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); }
@@ -713,7 +711,7 @@ static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate) {unsigned int n, truncm, freq; -mutex_lock (&ensoniq->src_mutex); +guard (mutex)(&ensoniq->src_mutex); n = rate /3000 ;if ((1 << n) & ((1 <<15 ) | (1 <<13 ) | (1 <<11 ) | (1 <<9 ))) n--;
@@ -737,14 +735,13 @@ static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)snd_es1371_src_write (ensoniq,ES_SMPREG_ADC +ES_SMPREG_VFREQ_FRAC , freq &0x7fff );snd_es1371_src_write (ensoniq,ES_SMPREG_VOL_ADC , n <<8 );snd_es1371_src_write (ensoniq,ES_SMPREG_VOL_ADC +1 , n <<8 ); -mutex_unlock (&ensoniq->src_mutex); }static void snd_es1371_dac1_rate (struct ensoniq * ensoniq,unsigned int rate) {unsigned int freq, r; -mutex_lock (&ensoniq->src_mutex); +guard (mutex)(&ensoniq->src_mutex); freq =DIV_ROUND_CLOSEST (rate <<15 ,3000 ); r = (snd_es1371_wait_src_ready (ensoniq) & (ES_1371_SRC_DISABLE | ES_1371_DIS_P2 | ES_1371_DIS_R1)) |
@@ -758,14 +755,13 @@ static void snd_es1371_dac1_rate(struct ensoniq * ensoniq, unsigned int rate) r = (snd_es1371_wait_src_ready (ensoniq) & (ES_1371_SRC_DISABLE |ES_1371_DIS_P2 |ES_1371_DIS_R1 )); outl(r, ES_REG(ensoniq, 1371_SMPRATE)); -mutex_unlock (&ensoniq->src_mutex); }static void snd_es1371_dac2_rate (struct ensoniq * ensoniq,unsigned int rate) {unsigned int freq, r; -mutex_lock (&ensoniq->src_mutex); +guard (mutex)(&ensoniq->src_mutex); freq =DIV_ROUND_CLOSEST (rate <<15 ,3000 ); r = (snd_es1371_wait_src_ready (ensoniq) & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 | ES_1371_DIS_R1)) |
@@ -780,7 +776,6 @@ static void snd_es1371_dac2_rate(struct ensoniq * ensoniq, unsigned int rate) r = (snd_es1371_wait_src_ready (ensoniq) & (ES_1371_SRC_DISABLE |ES_1371_DIS_P1 |ES_1371_DIS_R1 )); outl(r, ES_REG(ensoniq, 1371_SMPRATE)); - mutex_unlock(&ensoniq->src_mutex); }#endif /* CHIP1371 */
Signature · 1 line
2.50.1
PATCH 6/61 ALSA: ens137x: 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/pci/ens1370.c | 303 ++++++++++++++++++++------------------------ 1 file changed, 138 insertions(+), 165 deletions(-)
sound/pci/ens1370.c +138 -165
@@ -799,13 +799,13 @@ static int snd_ensoniq_trigger(struct snd_pcm_substream *substream, int cmd) }else if (s == ensoniq->capture_substream)return -EINVAL ; } -spin_lock (&ensoniq->reg_lock); -if (cmd ==SNDRV_PCM_TRIGGER_PAUSE_PUSH ) - ensoniq->sctrl |= what; -else - ensoniq->sctrl &= ~what; -outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); -spin_unlock (&ensoniq->reg_lock); + scoped_guard(spinlock, &ensoniq->reg_lock) { +if (cmd ==SNDRV_PCM_TRIGGER_PAUSE_PUSH ) + ensoniq->sctrl |= what; +else + ensoniq->sctrl &= ~what; +outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); + }break ; }case SNDRV_PCM_TRIGGER_START :
@@ -825,13 +825,13 @@ static int snd_ensoniq_trigger(struct snd_pcm_substream *substream, int cmd)snd_pcm_trigger_done (s, substream); } } -spin_lock (&ensoniq->reg_lock); -if (cmd ==SNDRV_PCM_TRIGGER_START ) - ensoniq->ctrl |= what; -else - ensoniq->ctrl &= ~what; -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock (&ensoniq->reg_lock); + scoped_guard(spinlock, &ensoniq->reg_lock) { +if (cmd ==SNDRV_PCM_TRIGGER_START ) + ensoniq->ctrl |= what; +else + ensoniq->ctrl &= ~what; +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); + }break ; }default :
@@ -856,36 +856,36 @@ static int snd_ensoniq_playback1_prepare(struct snd_pcm_substream *substream) mode |=0x02 ;if (runtime->channels >1 ) mode |=0x01 ; -spin_lock_irq (&ensoniq->reg_lock); - ensoniq->ctrl &= ~ES_DAC1_EN ; + scoped_guard(spinlock_irq, &ensoniq->reg_lock) { + ensoniq->ctrl &= ~ES_DAC1_EN ;#ifdef CHIP1371 -/* 48k doesn't need SRC (it breaks AC3-passthru) */ -if (runtime->rate ==48000 ) - ensoniq->ctrl |=ES_1373_BYPASS_P1 ; -else - ensoniq->ctrl &= ~ES_1373_BYPASS_P1 ; +/* 48k doesn't need SRC (it breaks AC3-passthru) */ +if (runtime->rate ==48000 ) + ensoniq->ctrl |=ES_1373_BYPASS_P1 ; +else + ensoniq->ctrl &= ~ES_1373_BYPASS_P1 ;#endif -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); -outl (runtime->dma_addr,ES_REG (ensoniq,DAC1_FRAME )); -outl ((ensoniq->p1_dma_size >>2 ) -1 ,ES_REG (ensoniq,DAC1_SIZE )); - ensoniq->sctrl &= ~(ES_P1_LOOP_SEL |ES_P1_PAUSE |ES_P1_SCT_RLD |ES_P1_MODEM ); - ensoniq->sctrl |=ES_P1_INT_EN |ES_P1_MODEO (mode); -outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); -outl ((ensoniq->p1_period_size >> snd_ensoniq_sample_shift[mode]) -1 , -ES_REG (ensoniq,DAC1_COUNT )); +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); +outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); +outl (runtime->dma_addr,ES_REG (ensoniq,DAC1_FRAME )); +outl ((ensoniq->p1_dma_size >>2 ) -1 ,ES_REG (ensoniq,DAC1_SIZE )); + ensoniq->sctrl &= ~(ES_P1_LOOP_SEL |ES_P1_PAUSE |ES_P1_SCT_RLD |ES_P1_MODEM ); + ensoniq->sctrl |=ES_P1_INT_EN |ES_P1_MODEO (mode); +outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); +outl ((ensoniq->p1_period_size >> snd_ensoniq_sample_shift[mode]) -1 , +ES_REG (ensoniq,DAC1_COUNT ));#ifdef CHIP1370 - ensoniq->ctrl &= ~ES_1370_WTSRSELM ; -switch (runtime->rate) { -case 5512 : ensoniq->ctrl |=ES_1370_WTSRSEL (0 );break ; -case 11025 : ensoniq->ctrl |=ES_1370_WTSRSEL (1 );break ; -case 22050 : ensoniq->ctrl |=ES_1370_WTSRSEL (2 );break ; -case 44100 : ensoniq->ctrl |=ES_1370_WTSRSEL (3 );break ; -default :snd_BUG (); - } + ensoniq->ctrl &= ~ES_1370_WTSRSELM ; +switch (runtime->rate) { +case 5512 : ensoniq->ctrl |=ES_1370_WTSRSEL (0 );break ; +case 11025 : ensoniq->ctrl |=ES_1370_WTSRSEL (1 );break ; +case 22050 : ensoniq->ctrl |=ES_1370_WTSRSEL (2 );break ; +case 44100 : ensoniq->ctrl |=ES_1370_WTSRSEL (3 );break ; +default :snd_BUG (); + }#endif -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock_irq (&ensoniq->reg_lock); +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); + }#ifndef CHIP1370 snd_es1371_dac1_rate (ensoniq, runtime->rate);#endif
@@ -904,28 +904,28 @@ static int snd_ensoniq_playback2_prepare(struct snd_pcm_substream *substream) mode |=0x02 ;if (runtime->channels >1 ) mode |=0x01 ; -spin_lock_irq (&ensoniq->reg_lock); - ensoniq->ctrl &= ~ES_DAC2_EN ; -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); -outl (runtime->dma_addr,ES_REG (ensoniq,DAC2_FRAME )); -outl ((ensoniq->p2_dma_size >>2 ) -1 ,ES_REG (ensoniq,DAC2_SIZE )); - ensoniq->sctrl &= ~(ES_P2_LOOP_SEL |ES_P2_PAUSE |ES_P2_DAC_SEN | -ES_P2_END_INCM |ES_P2_ST_INCM |ES_P2_MODEM ); - ensoniq->sctrl |=ES_P2_INT_EN |ES_P2_MODEO (mode) | -ES_P2_END_INCO (mode &2 ?2 :1 ) |ES_P2_ST_INCO (0 ); -outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); -outl ((ensoniq->p2_period_size >> snd_ensoniq_sample_shift[mode]) -1 , -ES_REG (ensoniq,DAC2_COUNT )); + scoped_guard(spinlock_irq, &ensoniq->reg_lock) { + ensoniq->ctrl &= ~ES_DAC2_EN ; +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); +outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); +outl (runtime->dma_addr,ES_REG (ensoniq,DAC2_FRAME )); +outl ((ensoniq->p2_dma_size >>2 ) -1 ,ES_REG (ensoniq,DAC2_SIZE )); + ensoniq->sctrl &= ~(ES_P2_LOOP_SEL |ES_P2_PAUSE |ES_P2_DAC_SEN | +ES_P2_END_INCM |ES_P2_ST_INCM |ES_P2_MODEM ); + ensoniq->sctrl |=ES_P2_INT_EN |ES_P2_MODEO (mode) | +ES_P2_END_INCO (mode &2 ?2 :1 ) |ES_P2_ST_INCO (0 ); +outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); +outl ((ensoniq->p2_period_size >> snd_ensoniq_sample_shift[mode]) -1 , +ES_REG (ensoniq,DAC2_COUNT ));#ifdef CHIP1370 -if (!(ensoniq->u.es1370.pclkdiv_lock &ES_MODE_CAPTURE )) { - ensoniq->ctrl &= ~ES_1370_PCLKDIVM ; - ensoniq->ctrl |=ES_1370_PCLKDIVO (ES_1370_SRTODIV (runtime->rate)); - ensoniq->u.es1370.pclkdiv_lock |=ES_MODE_PLAY2 ; - } +if (!(ensoniq->u.es1370.pclkdiv_lock &ES_MODE_CAPTURE )) { + ensoniq->ctrl &= ~ES_1370_PCLKDIVM ; + ensoniq->ctrl |=ES_1370_PCLKDIVO (ES_1370_SRTODIV (runtime->rate)); + ensoniq->u.es1370.pclkdiv_lock |=ES_MODE_PLAY2 ; + }#endif -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock_irq (&ensoniq->reg_lock); +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); + }#ifndef CHIP1370 snd_es1371_dac2_rate (ensoniq, runtime->rate);#endif
@@ -944,26 +944,26 @@ static int snd_ensoniq_capture_prepare(struct snd_pcm_substream *substream) mode |=0x02 ;if (runtime->channels >1 ) mode |=0x01 ; -spin_lock_irq (&ensoniq->reg_lock); - ensoniq->ctrl &= ~ES_ADC_EN ; -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -outl (ES_MEM_PAGEO (ES_PAGE_ADC ),ES_REG (ensoniq,MEM_PAGE )); -outl (runtime->dma_addr,ES_REG (ensoniq,ADC_FRAME )); -outl ((ensoniq->c_dma_size >>2 ) -1 ,ES_REG (ensoniq,ADC_SIZE )); - ensoniq->sctrl &= ~(ES_R1_LOOP_SEL |ES_R1_MODEM ); - ensoniq->sctrl |=ES_R1_INT_EN |ES_R1_MODEO (mode); -outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); -outl ((ensoniq->c_period_size >> snd_ensoniq_sample_shift[mode]) -1 , -ES_REG (ensoniq,ADC_COUNT )); + scoped_guard(spinlock_irq, &ensoniq->reg_lock) { + ensoniq->ctrl &= ~ES_ADC_EN ; +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); +outl (ES_MEM_PAGEO (ES_PAGE_ADC ),ES_REG (ensoniq,MEM_PAGE )); +outl (runtime->dma_addr,ES_REG (ensoniq,ADC_FRAME )); +outl ((ensoniq->c_dma_size >>2 ) -1 ,ES_REG (ensoniq,ADC_SIZE )); + ensoniq->sctrl &= ~(ES_R1_LOOP_SEL |ES_R1_MODEM ); + ensoniq->sctrl |=ES_R1_INT_EN |ES_R1_MODEO (mode); +outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); +outl ((ensoniq->c_period_size >> snd_ensoniq_sample_shift[mode]) -1 , +ES_REG (ensoniq,ADC_COUNT ));#ifdef CHIP1370 -if (!(ensoniq->u.es1370.pclkdiv_lock &ES_MODE_PLAY2 )) { - ensoniq->ctrl &= ~ES_1370_PCLKDIVM ; - ensoniq->ctrl |=ES_1370_PCLKDIVO (ES_1370_SRTODIV (runtime->rate)); - ensoniq->u.es1370.pclkdiv_lock |=ES_MODE_CAPTURE ; - } +if (!(ensoniq->u.es1370.pclkdiv_lock &ES_MODE_PLAY2 )) { + ensoniq->ctrl &= ~ES_1370_PCLKDIVM ; + ensoniq->ctrl |=ES_1370_PCLKDIVO (ES_1370_SRTODIV (runtime->rate)); + ensoniq->u.es1370.pclkdiv_lock |=ES_MODE_CAPTURE ; + }#endif -outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock_irq (&ensoniq->reg_lock); +outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); + }#ifndef CHIP1370 snd_es1371_adc_rate (ensoniq, runtime->rate);#endif
@@ -975,16 +975,14 @@ static snd_pcm_uframes_t snd_ensoniq_playback1_pointer(struct snd_pcm_substreamstruct ensoniq *ensoniq =snd_pcm_substream_chip (substream);size_t ptr; -spin_lock (&ensoniq->reg_lock); +guard (spinlock)(&ensoniq->reg_lock);if (inl (ES_REG (ensoniq,CONTROL )) &ES_DAC1_EN ) {outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); ptr =ES_REG_FCURR_COUNTI (inl (ES_REG (ensoniq,DAC1_SIZE ))); - ptr =bytes_to_frames (substream->runtime, ptr); +return bytes_to_frames (substream->runtime, ptr); }else { - ptr =0 ; +return 0 ; } -spin_unlock (&ensoniq->reg_lock); -return ptr; }static snd_pcm_uframes_t snd_ensoniq_playback2_pointer (struct snd_pcm_substream *substream)
@@ -992,16 +990,14 @@ static snd_pcm_uframes_t snd_ensoniq_playback2_pointer(struct snd_pcm_substreamstruct ensoniq *ensoniq =snd_pcm_substream_chip (substream);size_t ptr; -spin_lock (&ensoniq->reg_lock); +guard (spinlock)(&ensoniq->reg_lock);if (inl (ES_REG (ensoniq,CONTROL )) &ES_DAC2_EN ) {outl (ES_MEM_PAGEO (ES_PAGE_DAC ),ES_REG (ensoniq,MEM_PAGE )); ptr =ES_REG_FCURR_COUNTI (inl (ES_REG (ensoniq,DAC2_SIZE ))); - ptr =bytes_to_frames (substream->runtime, ptr); +return bytes_to_frames (substream->runtime, ptr); }else { - ptr =0 ; +return 0 ; } -spin_unlock (&ensoniq->reg_lock); -return ptr; }static snd_pcm_uframes_t snd_ensoniq_capture_pointer (struct snd_pcm_substream *substream)
@@ -1009,16 +1005,14 @@ static snd_pcm_uframes_t snd_ensoniq_capture_pointer(struct snd_pcm_substream *sstruct ensoniq *ensoniq =snd_pcm_substream_chip (substream);size_t ptr; -spin_lock (&ensoniq->reg_lock); +guard (spinlock)(&ensoniq->reg_lock);if (inl (ES_REG (ensoniq,CONTROL )) &ES_ADC_EN ) {outl (ES_MEM_PAGEO (ES_PAGE_ADC ),ES_REG (ensoniq,MEM_PAGE )); ptr =ES_REG_FCURR_COUNTI (inl (ES_REG (ensoniq,ADC_SIZE ))); - ptr =bytes_to_frames (substream->runtime, ptr); +return bytes_to_frames (substream->runtime, ptr); }else { - ptr =0 ; +return 0 ; } -spin_unlock (&ensoniq->reg_lock); -return ptr; } static const struct snd_pcm_hardware snd_ensoniq_playback1 =
@@ -1096,10 +1090,10 @@ static int snd_ensoniq_playback1_open(struct snd_pcm_substream *substream) ensoniq->playback1_substream = substream; runtime->hw = snd_ensoniq_playback1;snd_pcm_set_sync (substream); -spin_lock_irq (&ensoniq->reg_lock); -if (ensoniq->spdif && ensoniq->playback2_substream ==NULL ) - ensoniq->spdif_stream = ensoniq->spdif_default; -spin_unlock_irq (&ensoniq->reg_lock); + scoped_guard(spinlock_irq, &ensoniq->reg_lock) { +if (ensoniq->spdif && ensoniq->playback2_substream ==NULL ) + ensoniq->spdif_stream = ensoniq->spdif_default; + }#ifdef CHIP1370 snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_RATE , &snd_es1370_hw_constraints_rates);
@@ -1119,10 +1113,10 @@ static int snd_ensoniq_playback2_open(struct snd_pcm_substream *substream) ensoniq->playback2_substream = substream; runtime->hw = snd_ensoniq_playback2;snd_pcm_set_sync (substream); -spin_lock_irq (&ensoniq->reg_lock); -if (ensoniq->spdif && ensoniq->playback1_substream ==NULL ) - ensoniq->spdif_stream = ensoniq->spdif_default; -spin_unlock_irq (&ensoniq->reg_lock); + scoped_guard(spinlock_irq, &ensoniq->reg_lock) { +if (ensoniq->spdif && ensoniq->playback1_substream ==NULL ) + ensoniq->spdif_stream = ensoniq->spdif_default; + }#ifdef CHIP1370 snd_pcm_hw_constraint_ratnums (runtime,0 ,SNDRV_PCM_HW_PARAM_RATE , &snd_es1370_hw_constraints_clock);
@@ -1166,12 +1160,11 @@ static int snd_ensoniq_playback2_close(struct snd_pcm_substream *substream)struct ensoniq *ensoniq =snd_pcm_substream_chip (substream); ensoniq->playback2_substream =NULL ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);#ifdef CHIP1370 ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_PLAY2 ;#endif ensoniq->mode &= ~ES_MODE_PLAY2 ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1180,12 +1173,11 @@ static int snd_ensoniq_capture_close(struct snd_pcm_substream *substream)struct ensoniq *ensoniq =snd_pcm_substream_chip (substream); ensoniq->capture_substream =NULL ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);#ifdef CHIP1370 ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_CAPTURE ;#endif ensoniq->mode &= ~ES_MODE_CAPTURE ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1307,12 +1299,12 @@ static int snd_ens1373_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&ensoniq->reg_lock); + +guard (spinlock_irq)(&ensoniq->reg_lock); ucontrol->value.iec958.status[0 ] = (ensoniq->spdif_default >>0 ) &0xff ; ucontrol->value.iec958.status[1 ] = (ensoniq->spdif_default >>8 ) &0xff ; ucontrol->value.iec958.status[2 ] = (ensoniq->spdif_default >>16 ) &0xff ; ucontrol->value.iec958.status[3 ] = (ensoniq->spdif_default >>24 ) &0xff ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1327,13 +1319,12 @@ static int snd_ens1373_spdif_default_put(struct snd_kcontrol *kcontrol, ((u32 )ucontrol->value.iec958.status[1 ] <<8 ) | ((u32 )ucontrol->value.iec958.status[2 ] <<16 ) | ((u32 )ucontrol->value.iec958.status[3 ] <<24 ); -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); change = ensoniq->spdif_default != val; ensoniq->spdif_default = val;if (change && ensoniq->playback1_substream ==NULL && ensoniq->playback2_substream ==NULL )outl (val,ES_REG (ensoniq,CHANNEL_STATUS )); -spin_unlock_irq (&ensoniq->reg_lock);return change; }
@@ -1351,12 +1342,12 @@ static int snd_ens1373_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&ensoniq->reg_lock); + +guard (spinlock_irq)(&ensoniq->reg_lock); ucontrol->value.iec958.status[0 ] = (ensoniq->spdif_stream >>0 ) &0xff ; ucontrol->value.iec958.status[1 ] = (ensoniq->spdif_stream >>8 ) &0xff ; ucontrol->value.iec958.status[2 ] = (ensoniq->spdif_stream >>16 ) &0xff ; ucontrol->value.iec958.status[3 ] = (ensoniq->spdif_stream >>24 ) &0xff ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1371,13 +1362,12 @@ static int snd_ens1373_spdif_stream_put(struct snd_kcontrol *kcontrol, ((u32 )ucontrol->value.iec958.status[1 ] <<8 ) | ((u32 )ucontrol->value.iec958.status[2 ] <<16 ) | ((u32 )ucontrol->value.iec958.status[3 ] <<24 ); -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); change = ensoniq->spdif_stream != val; ensoniq->spdif_stream = val;if (change && (ensoniq->playback1_substream !=NULL || ensoniq->playback2_substream !=NULL ))outl (val,ES_REG (ensoniq,CHANNEL_STATUS )); -spin_unlock_irq (&ensoniq->reg_lock);return change; }
@@ -1392,9 +1382,8 @@ static int snd_es1371_spdif_get(struct snd_kcontrol *kcontrol, {struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); ucontrol->value.integer.value[0 ] = ensoniq->ctrl &ES_1373_SPDIF_THRU ?1 :0 ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1407,7 +1396,7 @@ static int snd_es1371_spdif_put(struct snd_kcontrol *kcontrol, nval1 = ucontrol->value.integer.value[0 ] ?ES_1373_SPDIF_THRU :0 ; nval2 = ucontrol->value.integer.value[0 ] ?ES_1373_SPDIF_EN :0 ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); change = (ensoniq->ctrl &ES_1373_SPDIF_THRU ) != nval1; ensoniq->ctrl &= ~ES_1373_SPDIF_THRU ; ensoniq->ctrl |= nval1;
@@ -1415,7 +1404,6 @@ static int snd_es1371_spdif_put(struct snd_kcontrol *kcontrol, ensoniq->cssr |= nval2;outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL ));outl (ensoniq->cssr,ES_REG (ensoniq,STATUS )); -spin_unlock_irq (&ensoniq->reg_lock);return change; }
@@ -1455,12 +1443,11 @@ static int snd_es1373_rear_get(struct snd_kcontrol *kcontrol,struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol);int val =0 ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);if ((ensoniq->cssr & (ES_1373_REAR_BIT27 |ES_1373_REAR_BIT26 |ES_1373_REAR_BIT24 )) ==ES_1373_REAR_BIT26 ) val =1 ; ucontrol->value.integer.value[0 ] = val; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1473,13 +1460,12 @@ static int snd_es1373_rear_put(struct snd_kcontrol *kcontrol, nval1 = ucontrol->value.integer.value[0 ] ?ES_1373_REAR_BIT26 : (ES_1373_REAR_BIT27 |ES_1373_REAR_BIT24 ); -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); change = (ensoniq->cssr & (ES_1373_REAR_BIT27 |ES_1373_REAR_BIT26 |ES_1373_REAR_BIT24 )) != nval1; ensoniq->cssr &= ~(ES_1373_REAR_BIT27 |ES_1373_REAR_BIT26 |ES_1373_REAR_BIT24 ); ensoniq->cssr |= nval1;outl (ensoniq->cssr,ES_REG (ensoniq,STATUS )); -spin_unlock_irq (&ensoniq->reg_lock);return change; }
@@ -1500,11 +1486,10 @@ static int snd_es1373_line_get(struct snd_kcontrol *kcontrol,struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol);int val =0 ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);if (ensoniq->ctrl &ES_1371_GPIO_OUT (4 )) val =1 ; ucontrol->value.integer.value[0 ] = val; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1515,7 +1500,7 @@ static int snd_es1373_line_put(struct snd_kcontrol *kcontrol,int changed;unsigned int ctrl; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); ctrl = ensoniq->ctrl;if (ucontrol->value.integer.value[0 ]) ensoniq->ctrl |=ES_1371_GPIO_OUT (4 );/* switch line-in -> rear out */
@@ -1524,7 +1509,6 @@ static int snd_es1373_line_put(struct snd_kcontrol *kcontrol, changed = (ctrl != ensoniq->ctrl);if (changed)outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock_irq (&ensoniq->reg_lock);return changed; }
@@ -1660,9 +1644,8 @@ static int snd_ensoniq_control_get(struct snd_kcontrol *kcontrol,struct ensoniq *ensoniq =snd_kcontrol_chip (kcontrol);int mask = kcontrol->private_value; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); ucontrol->value.integer.value[0 ] = ensoniq->ctrl & mask ?1 :0 ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -1675,12 +1658,11 @@ static int snd_ensoniq_control_put(struct snd_kcontrol *kcontrol,int change; nval = ucontrol->value.integer.value[0 ] ? mask :0 ; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); change = (ensoniq->ctrl & mask) != nval; ensoniq->ctrl &= ~mask; ensoniq->ctrl |= nval;outl (ensoniq->ctrl,ES_REG (ensoniq,CONTROL )); -spin_unlock_irq (&ensoniq->reg_lock);return change; }
@@ -2074,19 +2056,19 @@ static void snd_ensoniq_midi_interrupt(struct ensoniq * ensoniq)if (rmidi ==NULL )return ;/* do Rx at first */ -spin_lock (&ensoniq->reg_lock); - mask = ensoniq->uartm &ES_MODE_INPUT ?ES_RXRDY :0 ; -while (mask) { - status =inb (ES_REG (ensoniq,UART_STATUS )); -if ((status & mask) ==0 ) -break ; - byte =inb (ES_REG (ensoniq,UART_DATA )); -snd_rawmidi_receive (ensoniq->midi_input, &byte,1 ); + scoped_guard(spinlock, &ensoniq->reg_lock) { + mask = ensoniq->uartm &ES_MODE_INPUT ?ES_RXRDY :0 ; +while (mask) { + status =inb (ES_REG (ensoniq,UART_STATUS )); +if ((status & mask) ==0 ) +break ; + byte =inb (ES_REG (ensoniq,UART_DATA )); +snd_rawmidi_receive (ensoniq->midi_input, &byte,1 ); + } } -spin_unlock (&ensoniq->reg_lock);/* do Tx at second */ -spin_lock (&ensoniq->reg_lock); +guard (spinlock)(&ensoniq->reg_lock); mask = ensoniq->uartm &ES_MODE_OUTPUT ?ES_TXRDY :0 ;while (mask) { status =inb (ES_REG (ensoniq,UART_STATUS ));
@@ -2100,14 +2082,13 @@ static void snd_ensoniq_midi_interrupt(struct ensoniq * ensoniq)outb (byte,ES_REG (ensoniq,UART_DATA )); } } -spin_unlock (&ensoniq->reg_lock); }static int snd_ensoniq_midi_input_open (struct snd_rawmidi_substream *substream) {struct ensoniq *ensoniq = substream->rmidi->private_data; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); ensoniq->uartm |=ES_MODE_INPUT ; ensoniq->midi_input = substream;if (!(ensoniq->uartm &ES_MODE_OUTPUT )) {
@@ -2115,7 +2096,6 @@ static int snd_ensoniq_midi_input_open(struct snd_rawmidi_substream *substream)outb (ensoniq->uartc =0 ,ES_REG (ensoniq,UART_CONTROL ));outl (ensoniq->ctrl |=ES_UART_EN ,ES_REG (ensoniq,CONTROL )); } -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -2123,7 +2103,7 @@ static int snd_ensoniq_midi_input_close(struct snd_rawmidi_substream *substream) {struct ensoniq *ensoniq = substream->rmidi->private_data; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);if (!(ensoniq->uartm &ES_MODE_OUTPUT )) {outb (ensoniq->uartc =0 ,ES_REG (ensoniq,UART_CONTROL ));outl (ensoniq->ctrl &= ~ES_UART_EN ,ES_REG (ensoniq,CONTROL ));
@@ -2132,7 +2112,6 @@ static int snd_ensoniq_midi_input_close(struct snd_rawmidi_substream *substream) } ensoniq->midi_input =NULL ; ensoniq->uartm &= ~ES_MODE_INPUT ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -2140,7 +2119,7 @@ static int snd_ensoniq_midi_output_open(struct snd_rawmidi_substream *substream) {struct ensoniq *ensoniq = substream->rmidi->private_data; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock); ensoniq->uartm |=ES_MODE_OUTPUT ; ensoniq->midi_output = substream;if (!(ensoniq->uartm &ES_MODE_INPUT )) {
@@ -2148,7 +2127,6 @@ static int snd_ensoniq_midi_output_open(struct snd_rawmidi_substream *substream)outb (ensoniq->uartc =0 ,ES_REG (ensoniq,UART_CONTROL ));outl (ensoniq->ctrl |=ES_UART_EN ,ES_REG (ensoniq,CONTROL )); } -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }
@@ -2156,7 +2134,7 @@ static int snd_ensoniq_midi_output_close(struct snd_rawmidi_substream *substream {struct ensoniq *ensoniq = substream->rmidi->private_data; -spin_lock_irq (&ensoniq->reg_lock); +guard (spinlock_irq)(&ensoniq->reg_lock);if (!(ensoniq->uartm &ES_MODE_INPUT )) {outb (ensoniq->uartc =0 ,ES_REG (ensoniq,UART_CONTROL ));outl (ensoniq->ctrl &= ~ES_UART_EN ,ES_REG (ensoniq,CONTROL ));
@@ -2165,17 +2143,15 @@ static int snd_ensoniq_midi_output_close(struct snd_rawmidi_substream *substream } ensoniq->midi_output =NULL ; ensoniq->uartm &= ~ES_MODE_OUTPUT ; -spin_unlock_irq (&ensoniq->reg_lock);return 0 ; }static void snd_ensoniq_midi_input_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct ensoniq *ensoniq = substream->rmidi->private_data;int idx; -spin_lock_irqsave (&ensoniq->reg_lock, flags); +guard (spinlock_irqsave)(&ensoniq->reg_lock);if (up) {if ((ensoniq->uartc &ES_RXINTEN ) ==0 ) {/* empty input FIFO */
@@ -2190,16 +2166,14 @@ static void snd_ensoniq_midi_input_trigger(struct snd_rawmidi_substream *substreoutb (ensoniq->uartc,ES_REG (ensoniq,UART_CONTROL )); } } -spin_unlock_irqrestore (&ensoniq->reg_lock, flags); }static void snd_ensoniq_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct ensoniq *ensoniq = substream->rmidi->private_data;unsigned char byte; -spin_lock_irqsave (&ensoniq->reg_lock, flags); +guard (spinlock_irqsave)(&ensoniq->reg_lock);if (up) {if (ES_TXINTENI (ensoniq->uartc) ==0 ) { ensoniq->uartc |=ES_TXINTENO (1 );
@@ -2220,7 +2194,6 @@ static void snd_ensoniq_midi_output_trigger(struct snd_rawmidi_substream *substroutb (ensoniq->uartc,ES_REG (ensoniq,UART_CONTROL )); } } -spin_unlock_irqrestore (&ensoniq->reg_lock, flags); } static const struct snd_rawmidi_ops snd_ensoniq_midi_output =
@@ -2271,17 +2244,17 @@ static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id)if (!(status &ES_INTR ))return IRQ_NONE ; -spin_lock (&ensoniq->reg_lock); - sctrl = ensoniq->sctrl; -if (status &ES_DAC1 ) - sctrl &= ~ES_P1_INT_EN ; -if (status &ES_DAC2 ) - sctrl &= ~ES_P2_INT_EN ; -if (status &ES_ADC ) - sctrl &= ~ES_R1_INT_EN ; -outl (sctrl,ES_REG (ensoniq,SERIAL )); -outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); -spin_unlock (&ensoniq->reg_lock); + scoped_guard(spinlock, &ensoniq->reg_lock) { + sctrl = ensoniq->sctrl; +if (status &ES_DAC1 ) + sctrl &= ~ES_P1_INT_EN ; +if (status &ES_DAC2 ) + sctrl &= ~ES_P2_INT_EN ; +if (status &ES_ADC ) + sctrl &= ~ES_R1_INT_EN ; +outl (sctrl,ES_REG (ensoniq,SERIAL )); +outl (ensoniq->sctrl,ES_REG (ensoniq,SERIAL )); + }if (status &ES_UART )snd_ensoniq_midi_interrupt (ensoniq);
Signature · 1 line
2.50.1
PATCH 7/61 ALSA: als300: 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/pci/als300.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
sound/pci/als300.c +8 -13
@@ -402,7 +402,7 @@ static int snd_als300_playback_prepare(struct snd_pcm_substream *substream)unsigned short period_bytes =snd_pcm_lib_period_bytes (substream);unsigned short buffer_bytes =snd_pcm_lib_buffer_bytes (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); tmp =snd_als300_gcr_read (chip->port,PLAYBACK_CONTROL ); tmp &= ~TRANSFER_START ;
@@ -419,7 +419,6 @@ static int snd_als300_playback_prepare(struct snd_pcm_substream *substream) runtime->dma_addr);snd_als300_gcr_write (chip->port,PLAYBACK_END , runtime->dma_addr + buffer_bytes -1 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -431,7 +430,7 @@ static int snd_als300_capture_prepare(struct snd_pcm_substream *substream)unsigned short period_bytes =snd_pcm_lib_period_bytes (substream);unsigned short buffer_bytes =snd_pcm_lib_buffer_bytes (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); tmp =snd_als300_gcr_read (chip->port,RECORD_CONTROL ); tmp &= ~TRANSFER_START ;
@@ -448,7 +447,6 @@ static int snd_als300_capture_prepare(struct snd_pcm_substream *substream) runtime->dma_addr);snd_als300_gcr_write (chip->port,RECORD_END , runtime->dma_addr + buffer_bytes -1 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -463,7 +461,7 @@ static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd) data = substream->runtime->private_data; reg = data->control_register; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -492,7 +490,6 @@ static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd)snd_als300_dbgplay ("TRIGGER INVALID\n" ); ret = -EINVAL ; } -spin_unlock (&chip->reg_lock);return ret; }
@@ -506,10 +503,10 @@ static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream) data = substream->runtime->private_data; period_bytes =snd_pcm_lib_period_bytes (substream); -spin_lock (&chip->reg_lock); - current_ptr = (u16 )snd_als300_gcr_read (chip->port, - data->block_counter_register) +4 ; -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + current_ptr = (u16 )snd_als300_gcr_read (chip->port, + data->block_counter_register) +4 ; + }if (current_ptr > period_bytes) current_ptr =0 ;else
@@ -563,10 +560,9 @@ static int snd_als300_new_pcm(struct snd_als300 *chip)static void snd_als300_init (struct snd_als300 *chip) { -unsigned long flags;u32 tmp; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock); chip->revision = (snd_als300_gcr_read (chip->port,MISC_CONTROL ) >>16 ) &0x0000000F ;/* Setup DRAM */
@@ -591,7 +587,6 @@ static void snd_als300_init(struct snd_als300 *chip) tmp =snd_als300_gcr_read (chip->port,PLAYBACK_CONTROL );snd_als300_gcr_write (chip->port,PLAYBACK_CONTROL , tmp & ~TRANSFER_START ); -spin_unlock_irqrestore (&chip->reg_lock, flags); } static int snd_als300_create(struct snd_card *card,
Signature · 1 line
2.50.1
PATCH 8/61 ALSA: als4000: 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/pci/als4000.c | 68 +++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 36 deletions(-)
sound/pci/als4000.c +32 -36
@@ -369,14 +369,14 @@ static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream) count >>=1 ; count--; -spin_lock_irq (&chip->reg_lock); -snd_als4000_set_rate (chip, runtime->rate); -snd_als4000_set_capture_dma (chip, runtime->dma_addr, size); -spin_unlock_irq (&chip->reg_lock); -spin_lock_irq (&chip->mixer_lock); -snd_als4_cr_write (chip,ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO , count &0xff ); -snd_als4_cr_write (chip,ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI , count >>8 ); -spin_unlock_irq (&chip->mixer_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { +snd_als4000_set_rate (chip, runtime->rate); +snd_als4000_set_capture_dma (chip, runtime->dma_addr, size); + } + scoped_guard(spinlock_irq, &chip->mixer_lock) { +snd_als4_cr_write (chip,ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO , count &0xff ); +snd_als4_cr_write (chip,ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI , count >>8 ); + }return 0 ; }
@@ -402,7 +402,7 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)* reordering, ...). Something seems to get enabled on playback * that I haven't found out how to disable again, which then causes * the switching pops to reach the speakers the next time here. */ -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);snd_als4000_set_rate (chip, runtime->rate);snd_als4000_set_playback_dma (chip, runtime->dma_addr, size);
@@ -413,7 +413,6 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)snd_sbdsp_command (chip, count &0xff );snd_sbdsp_command (chip, count >>8 );snd_sbdsp_command (chip,playback_cmd (chip).dma_off); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -429,7 +428,7 @@ static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, intProbably need to take reg_lock as outer (or inner??) lock, too. (or serialize both lock operations? probably not, though... - racy?) */ -spin_lock (&chip->mixer_lock); +guard (spinlock)(&chip->mixer_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -447,7 +446,6 @@ static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int result = -EINVAL ;break ; } -spin_unlock (&chip->mixer_lock);return result; }
@@ -456,7 +454,7 @@ static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, intstruct snd_sb *chip =snd_pcm_substream_chip (substream);int result =0 ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -472,7 +470,6 @@ static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int result = -EINVAL ;break ; } -spin_unlock (&chip->reg_lock);return result; }
@@ -481,9 +478,9 @@ static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *sstruct snd_sb *chip =snd_pcm_substream_chip (substream);unsigned int result; -spin_lock (&chip->reg_lock); - result =snd_als4k_gcr_read (chip,ALS4K_GCRA4_FIFO2_CURRENT_ADDR ); -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + result =snd_als4k_gcr_read (chip,ALS4K_GCRA4_FIFO2_CURRENT_ADDR ); + } result &=0xffff ;return bytes_to_frames ( substream->runtime, result ); }
@@ -493,9 +490,9 @@ static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *struct snd_sb *chip =snd_pcm_substream_chip (substream);unsigned result; -spin_lock (&chip->reg_lock); - result =snd_als4k_gcr_read (chip,ALS4K_GCRA0_FIFO1_CURRENT_ADDR ); -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + result =snd_als4k_gcr_read (chip,ALS4K_GCRA0_FIFO1_CURRENT_ADDR ); + } result &=0xffff ;return bytes_to_frames ( substream->runtime, result ); }
@@ -536,10 +533,10 @@ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id)snd_als4k_iobase_writeb (chip->alt_port,ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU , pci_irqstatus); -spin_lock (&chip->mixer_lock); -/* SPECS_PAGE: 20 */ - sb_irqstatus =snd_sbmixer_read (chip,SB_DSP4_IRQSTATUS ); -spin_unlock (&chip->mixer_lock); + scoped_guard(spinlock, &chip->mixer_lock) { +/* SPECS_PAGE: 20 */ + sb_irqstatus =snd_sbmixer_read (chip,SB_DSP4_IRQSTATUS ); + }if (sb_irqstatus &SB_IRQTYPE_8BIT )snd_sb_ack_8bit (chip);
@@ -709,18 +706,18 @@ static void snd_als4000_configure(struct snd_sb *chip)int i;/* do some more configuration */ -spin_lock_irq (&chip->mixer_lock); - tmp =snd_als4_cr_read (chip,ALS4K_CR0_SB_CONFIG ); -snd_als4_cr_write (chip,ALS4K_CR0_SB_CONFIG , - tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE ); -/* always select DMA channel 0, since we do not actually use DMA -* SPECS_PAGE: 19/20 */ -snd_sbmixer_write (chip,SB_DSP4_DMASETUP ,SB_DMASETUP_DMA0 ); -snd_als4_cr_write (chip,ALS4K_CR0_SB_CONFIG , - tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE ); -spin_unlock_irq (&chip->mixer_lock); + scoped_guard(spinlock_irq, &chip->mixer_lock) { + tmp =snd_als4_cr_read (chip,ALS4K_CR0_SB_CONFIG ); +snd_als4_cr_write (chip,ALS4K_CR0_SB_CONFIG , + tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE ); +/* always select DMA channel 0, since we do not actually use DMA +* SPECS_PAGE: 19/20 */ +snd_sbmixer_write (chip,SB_DSP4_DMASETUP ,SB_DMASETUP_DMA0 ); +snd_als4_cr_write (chip,ALS4K_CR0_SB_CONFIG , + tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE ); + } -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);/* enable interrupts */ snd_als4k_gcr_write (chip,ALS4K_GCR8C_MISC_CTRL ,ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE );
@@ -731,7 +728,6 @@ static void snd_als4000_configure(struct snd_sb *chip)/* enable burst mode to prevent dropouts during high PCI bus usage */ snd_als4k_gcr_write (chip,ALS4K_GCR99_DMA_EMULATION_CTRL , (snd_als4k_gcr_read (chip,ALS4K_GCR99_DMA_EMULATION_CTRL ) & ~0x07 ) |0x04 ); -spin_unlock_irq (&chip->reg_lock); }#ifdef SUPPORT_JOYSTICK
Signature · 1 line
2.50.1
PATCH 9/61 ALSA: ad1889: 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/pci/ad1889.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
sound/pci/ad1889.c +3 -9
@@ -353,7 +353,7 @@ snd_ad1889_playback_prepare(struct snd_pcm_substream *ss) reg |=AD_DS_WSMC_WAST ;/* let's make sure we don't clobber ourselves */ -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); chip->wave.size = size; chip->wave.reg = reg;
@@ -372,8 +372,6 @@ snd_ad1889_playback_prepare(struct snd_pcm_substream *ss)/* writes flush */ ad1889_readw (chip,AD_DS_WSMC ); -spin_unlock_irq (&chip->lock); -dev_dbg (chip->card->dev,"prepare playback: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n" , chip->wave.addr, count, size, reg, rt->rate);
@@ -403,7 +401,7 @@ snd_ad1889_capture_prepare(struct snd_pcm_substream *ss) reg |=AD_DS_RAMC_ADST ;/* let's make sure we don't clobber ourselves */ -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); chip->ramc.size = size; chip->ramc.reg = reg;
@@ -419,8 +417,6 @@ snd_ad1889_capture_prepare(struct snd_pcm_substream *ss)/* writes flush */ ad1889_readw (chip,AD_DS_RAMC ); -spin_unlock_irq (&chip->lock); -dev_dbg (chip->card->dev,"prepare capture: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n" , chip->ramc.addr, count, size, reg, rt->rate);
@@ -775,7 +771,7 @@ snd_ad1889_free(struct snd_card *card) {struct snd_ad1889 *chip = card->private_data; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);ad1889_mute (chip);
@@ -785,8 +781,6 @@ snd_ad1889_free(struct snd_card *card)/* clear DISR. If we don't, we'd better jump off the Eiffel Tower */ ad1889_writel (chip,AD_DMA_DISR ,AD_DMA_DISR_PTAI |AD_DMA_DISR_PMAI );ad1889_readl (chip,AD_DMA_DISR );/* flush, dammit! */ - -spin_unlock_irq (&chip->lock); } static int
Signature · 1 line
2.50.1
PATCH 10/61 ALSA: atiixp: 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/pci/atiixp.c | 31 ++++++++++++------------------- sound/pci/atiixp_modem.c | 17 +++++------------ 2 files changed, 17 insertions(+), 31 deletions(-)
sound/pci/atiixp.c +12 -19
@@ -1073,9 +1073,8 @@ static int snd_atiixp_playback_open(struct snd_pcm_substream *substream)struct atiixp *chip =snd_pcm_substream_chip (substream);int err; -mutex_lock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex); err =snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_PLAYBACK ],0 ); -mutex_unlock (&chip->open_mutex);if (err <0 )return err; substream->runtime->hw.channels_max = chip->max_channels;
@@ -1089,11 +1088,9 @@ static int snd_atiixp_playback_open(struct snd_pcm_substream *substream)static int snd_atiixp_playback_close (struct snd_pcm_substream *substream) {struct atiixp *chip =snd_pcm_substream_chip (substream); -int err; -mutex_lock (&chip->open_mutex); - err =snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]); -mutex_unlock (&chip->open_mutex); -return err; + +guard (mutex)(&chip->open_mutex); +return snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]); }static int snd_atiixp_capture_open (struct snd_pcm_substream *substream)
@@ -1111,27 +1108,23 @@ static int snd_atiixp_capture_close(struct snd_pcm_substream *substream)static int snd_atiixp_spdif_open (struct snd_pcm_substream *substream) {struct atiixp *chip =snd_pcm_substream_chip (substream); -int err; -mutex_lock (&chip->open_mutex); + +guard (mutex)(&chip->open_mutex);if (chip->spdif_over_aclink)/* share DMA_PLAYBACK */ - err =snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_PLAYBACK ],2 ); +return snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_PLAYBACK ],2 );else - err =snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_SPDIF ],-1 ); -mutex_unlock (&chip->open_mutex); -return err; +return snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_SPDIF ],-1 ); }static int snd_atiixp_spdif_close (struct snd_pcm_substream *substream) {struct atiixp *chip =snd_pcm_substream_chip (substream); -int err; -mutex_lock (&chip->open_mutex); + +guard (mutex)(&chip->open_mutex);if (chip->spdif_over_aclink) - err =snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]); +return snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]);else - err =snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_SPDIF ]); -mutex_unlock (&chip->open_mutex); -return err; +return snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_SPDIF ]); }/* AC97 playback */
sound/pci/atiixp_modem.c +5 -12
@@ -892,24 +892,17 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,static int snd_atiixp_playback_open (struct snd_pcm_substream *substream) {struct atiixp_modem *chip =snd_pcm_substream_chip (substream); -int err; -mutex_lock (&chip->open_mutex); - err =snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_PLAYBACK ],0 ); -mutex_unlock (&chip->open_mutex); -if (err <0 ) -return err; -return 0 ; +guard (mutex)(&chip->open_mutex); +return snd_atiixp_pcm_open (substream, &chip->dmas[ATI_DMA_PLAYBACK ],0 ); }static int snd_atiixp_playback_close (struct snd_pcm_substream *substream) {struct atiixp_modem *chip =snd_pcm_substream_chip (substream); -int err; -mutex_lock (&chip->open_mutex); - err =snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]); -mutex_unlock (&chip->open_mutex); -return err; + +guard (mutex)(&chip->open_mutex); +return snd_atiixp_pcm_close (substream, &chip->dmas[ATI_DMA_PLAYBACK ]); }static int snd_atiixp_capture_open (struct snd_pcm_substream *substream)
Signature · 1 line
2.50.1
PATCH 11/61 ALSA: atiixp: 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/pci/atiixp.c | 38 ++++++++++++++++---------------------- sound/pci/atiixp_modem.c | 32 ++++++++++++++------------------ 2 files changed, 30 insertions(+), 40 deletions(-)
sound/pci/atiixp.c +16 -22
@@ -345,7 +345,6 @@ static int atiixp_build_dma_packets(struct atiixp *chip, struct atiixp_dma *dma, {unsigned int i;u32 addr, desc_addr; -unsigned long flags;if (periods >ATI_MAX_DESCRIPTORS )return -ENOMEM ;
@@ -363,11 +362,11 @@ static int atiixp_build_dma_packets(struct atiixp *chip, struct atiixp_dma *dma,return 0 ;/* reset DMA before changing the descriptor table */ -spin_lock_irqsave (&chip->reg_lock, flags); -writel (0 , chip->remap_addr + dma->ops->llp_offset); - dma->ops->enable_dma (chip,0 ); - dma->ops->enable_dma (chip,1 ); -spin_unlock_irqrestore (&chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &chip->reg_lock) { +writel (0 , chip->remap_addr + dma->ops->llp_offset); + dma->ops->enable_dma (chip,0 ); + dma->ops->enable_dma (chip,1 ); + }/* fill the entries */ addr = (u32 )substream->runtime->dma_addr;
@@ -711,7 +710,7 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) !dma->ops->flush_dma))return -EINVAL ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :
@@ -745,7 +744,6 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)snd_atiixp_check_bus_busy (chip); } } -spin_unlock (&chip->reg_lock);return err; }
@@ -859,7 +857,7 @@ static int snd_atiixp_spdif_prepare(struct snd_pcm_substream *substream) {struct atiixp *chip =snd_pcm_substream_chip (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);if (chip->spdif_over_aclink) {unsigned int data;/* enable slots 10/11 */
@@ -877,7 +875,6 @@ static int snd_atiixp_spdif_prepare(struct snd_pcm_substream *substream)atiixp_update (chip,CMD ,ATI_REG_CMD_SPDF_CONFIG_MASK ,0 );atiixp_update (chip,CMD ,ATI_REG_CMD_INTERLEAVE_SPDF ,0 ); } -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -887,7 +884,7 @@ static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream)struct atiixp *chip =snd_pcm_substream_chip (substream);unsigned int data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); data =atiixp_read (chip,OUT_DMA_SLOT ) & ~ATI_REG_OUT_DMA_SLOT_MASK ;switch (substream->runtime->channels) {case 8 :
@@ -922,7 +919,6 @@ static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream) atiixp_update(chip, 6CH_REORDER, ATI_REG_6CH_REORDER_EN, substream->runtime->channels >=6 ?ATI_REG_6CH_REORDER_EN :0 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -931,11 +927,10 @@ static int snd_atiixp_capture_prepare(struct snd_pcm_substream *substream) {struct atiixp *chip =snd_pcm_substream_chip (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);atiixp_update (chip,CMD ,ATI_REG_CMD_INTERLEAVE_IN , substream->runtime->format ==SNDRV_PCM_FORMAT_S16_LE ?ATI_REG_CMD_INTERLEAVE_IN :0 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1043,9 +1038,9 @@ static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream, runtime->private_data = dma;/* enable DMA bits */ -spin_lock_irq (&chip->reg_lock); - dma->ops->enable_dma (chip,1 ); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + dma->ops->enable_dma (chip,1 ); + } dma->opened =1 ;return 0 ;
@@ -1058,9 +1053,9 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,/* disable DMA bits */ if (snd_BUG_ON (!dma->ops || !dma->ops->enable_dma))return -EINVAL ; -spin_lock_irq (&chip->reg_lock); - dma->ops->enable_dma (chip,0 ); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + dma->ops->enable_dma (chip,0 ); + } dma->substream =NULL ; dma->opened =0 ;return 0 ;
@@ -1348,10 +1343,9 @@ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id)if (status &CODEC_CHECK_BITS ) {unsigned int detected; detected = status &CODEC_CHECK_BITS ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); chip->codec_not_ready_bits |= detected;atiixp_update (chip,IER , detected,0 );/* disable the detected irqs */ -spin_unlock (&chip->reg_lock); }/* ack */
sound/pci/atiixp_modem.c +14 -18
@@ -314,7 +314,6 @@ static int atiixp_build_dma_packets(struct atiixp_modem *chip, {unsigned int i;u32 addr, desc_addr; -unsigned long flags;if (periods >ATI_MAX_DESCRIPTORS )return -ENOMEM ;
@@ -330,11 +329,11 @@ static int atiixp_build_dma_packets(struct atiixp_modem *chip,return 0 ;/* reset DMA before changing the descriptor table */ -spin_lock_irqsave (&chip->reg_lock, flags); -writel (0 , chip->remap_addr + dma->ops->llp_offset); - dma->ops->enable_dma (chip,0 ); - dma->ops->enable_dma (chip,1 ); -spin_unlock_irqrestore (&chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &chip->reg_lock) { +writel (0 , chip->remap_addr + dma->ops->llp_offset); + dma->ops->enable_dma (chip,0 ); + dma->ops->enable_dma (chip,1 ); + }/* fill the entries */ addr = (u32 )substream->runtime->dma_addr;
@@ -661,7 +660,7 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) !dma->ops->flush_dma))return -EINVAL ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : dma->ops->enable_transfer (chip,1 );
@@ -682,7 +681,6 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)snd_atiixp_check_bus_busy (chip); } } -spin_unlock (&chip->reg_lock);return err; }
@@ -753,13 +751,12 @@ static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream)struct atiixp_modem *chip =snd_pcm_substream_chip (substream);unsigned int data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);/* set output threshold */ data =atiixp_read (chip,MODEM_OUT_FIFO ); data &= ~ATI_REG_MODEM_OUT1_DMA_THRESHOLD_MASK ; data |=0x04 <<ATI_REG_MODEM_OUT1_DMA_THRESHOLD_SHIFT ;atiixp_write (chip,MODEM_OUT_FIFO , data); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -864,9 +861,9 @@ static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream, runtime->private_data = dma;/* enable DMA bits */ -spin_lock_irq (&chip->reg_lock); - dma->ops->enable_dma (chip,1 ); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + dma->ops->enable_dma (chip,1 ); + } dma->opened =1 ;return 0 ;
@@ -879,9 +876,9 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,/* disable DMA bits */ if (snd_BUG_ON (!dma->ops || !dma->ops->enable_dma))return -EINVAL ; -spin_lock_irq (&chip->reg_lock); - dma->ops->enable_dma (chip,0 ); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + dma->ops->enable_dma (chip,0 ); + } dma->substream =NULL ; dma->opened =0 ;return 0 ;
@@ -1013,10 +1010,9 @@ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id)if (status &CODEC_CHECK_BITS ) {unsigned int detected; detected = status &CODEC_CHECK_BITS ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); chip->codec_not_ready_bits |= detected;atiixp_update (chip,IER , detected,0 );/* disable the detected irqs */ -spin_unlock (&chip->reg_lock); }/* ack */
Signature · 1 line
2.50.1
PATCH 12/61 ALSA: aw2: 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/pci/aw2/aw2-alsa.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/pci/aw2/aw2-alsa.c +2 -6
@@ -347,7 +347,7 @@ static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;unsigned long period_size, buffer_size; -mutex_lock (&chip->mtx); +guard (mutex)(&chip->mtx); period_size =snd_pcm_lib_period_bytes (substream); buffer_size =snd_pcm_lib_buffer_bytes (substream);
@@ -363,8 +363,6 @@ static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream) snd_pcm_period_elapsed, (void *)substream); -mutex_unlock (&chip->mtx); -return 0 ; }
@@ -376,7 +374,7 @@ static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;unsigned long period_size, buffer_size; -mutex_lock (&chip->mtx); +guard (mutex)(&chip->mtx); period_size =snd_pcm_lib_period_bytes (substream); buffer_size =snd_pcm_lib_buffer_bytes (substream);
@@ -392,8 +390,6 @@ static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream) snd_pcm_period_elapsed, (void *)substream); -mutex_unlock (&chip->mtx); -return 0 ; }
Signature · 1 line
2.50.1
PATCH 13/61 ALSA: aw2: 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/pci/aw2/aw2-alsa.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
sound/pci/aw2/aw2-alsa.c +8 -10
@@ -397,10 +397,10 @@ static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)static int snd_aw2_pcm_trigger_playback (struct snd_pcm_substream *substream,int cmd) { -int status =0 ;struct aw2_pcm_device *pcm_device =snd_pcm_substream_chip (substream);struct aw2 *chip = pcm_device->chip; -spin_lock (&chip->reg_lock); + +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : snd_aw2_saa7146_pcm_trigger_start_playback(&chip->saa7146,
@@ -413,20 +413,19 @@ static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream, stream_number);break ;default : - status = -EINVAL ; +return -EINVAL ; } -spin_unlock (&chip->reg_lock); -return status; +return 0 ; }/* capture trigger callback */ static int snd_aw2_pcm_trigger_capture (struct snd_pcm_substream *substream,int cmd) { -int status =0 ;struct aw2_pcm_device *pcm_device =snd_pcm_substream_chip (substream);struct aw2 *chip = pcm_device->chip; -spin_lock (&chip->reg_lock); + +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : snd_aw2_saa7146_pcm_trigger_start_capture(&chip->saa7146,
@@ -439,10 +438,9 @@ static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream, stream_number);break ;default : - status = -EINVAL ; +return -EINVAL ; } -spin_unlock (&chip->reg_lock); -return status; +return 0 ; }/* playback pointer callback */
Signature · 1 line
2.50.1
PATCH 14/61 ALSA: bt87x: 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/pci/bt87x.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
sound/pci/bt87x.c +10 -16
@@ -431,10 +431,10 @@ static int snd_bt87x_close(struct snd_pcm_substream *substream) {struct snd_bt87x *chip =snd_pcm_substream_chip (substream); -spin_lock_irq (&chip->reg_lock); - chip->reg_control |=CTL_A_PWRDN ; -snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->reg_control |=CTL_A_PWRDN ; +snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); + } chip->substream =NULL ;clear_bit (0 , &chip->opened);
@@ -466,20 +466,19 @@ static int snd_bt87x_prepare(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;int decimation; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->reg_control &= ~(CTL_DA_SDR_MASK |CTL_DA_SBR ); decimation = (ANALOG_CLOCK + runtime->rate /4 ) / runtime->rate; chip->reg_control |= decimation <<CTL_DA_SDR_SHIFT ;if (runtime->format ==SNDRV_PCM_FORMAT_S8 ) chip->reg_control |=CTL_DA_SBR ;snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); -spin_unlock_irq (&chip->reg_lock);return 0 ; }static int snd_bt87x_start (struct snd_bt87x *chip) { -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); chip->current_line =0 ; chip->reg_control |=CTL_FIFO_ENABLE |CTL_RISC_ENABLE |CTL_ACAP_EN ;snd_bt87x_writel (chip,REG_RISC_STRT_ADD , chip->dma_risc.addr);
@@ -487,18 +486,16 @@ static int snd_bt87x_start(struct snd_bt87x *chip) chip->line_bytes | (chip->lines << 16));snd_bt87x_writel (chip,REG_INT_MASK , chip->interrupt_mask);snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); -spin_unlock (&chip->reg_lock);return 0 ; }static int snd_bt87x_stop (struct snd_bt87x *chip) { -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); chip->reg_control &= ~(CTL_FIFO_ENABLE |CTL_RISC_ENABLE |CTL_ACAP_EN );snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control);snd_bt87x_writel (chip,REG_INT_MASK ,0 );snd_bt87x_writel (chip,REG_INT_STAT ,MY_INTERRUPTS ); -spin_unlock (&chip->reg_lock);return 0 ; }
@@ -560,13 +557,12 @@ static int snd_bt87x_capture_volume_put(struct snd_kcontrol *kcontrol,u32 old_control;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_GAIN_MASK ) | (value->value.integer.value[0 ] <<CTL_A_GAIN_SHIFT );snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); changed = old_control != chip->reg_control; -spin_unlock_irq (&chip->reg_lock);return changed; }
@@ -596,13 +592,12 @@ static int snd_bt87x_capture_boost_put(struct snd_kcontrol *kcontrol,u32 old_control;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_G2X ) | (value->value.integer.value[0 ] ?CTL_A_G2X :0 );snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); changed = chip->reg_control != old_control; -spin_unlock_irq (&chip->reg_lock);return changed; }
@@ -638,13 +633,12 @@ static int snd_bt87x_capture_source_put(struct snd_kcontrol *kcontrol,u32 old_control;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_SEL_MASK ) | (value->value.enumerated.item[0 ] <<CTL_A_SEL_SHIFT );snd_bt87x_writel (chip,REG_GPIO_DMA_CTL , chip->reg_control); changed = chip->reg_control != old_control; -spin_unlock_irq (&chip->reg_lock);return changed; }
Signature · 1 line
2.50.1
PATCH 15/61 ALSA: ca0106: 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/pci/ca0106/ca0106_main.c | 33 ++----- sound/pci/ca0106/ca0106_proc.c | 28 +++--- sound/pci/ca0106/ca_midi.c | 169 +++++++++++++++------------------ 3 files changed, 96 insertions(+), 134 deletions(-)
sound/pci/ca0106/ca0106_main.c +9 -24
@@ -332,16 +332,13 @@ unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu, unsigned int reg, unsigned int chn) { -unsigned long flags; -unsigned int regptr, val; +unsigned int regptr; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (regptr, emu->port +CA0106_PTR ); - val =inl (emu->port +CA0106_DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); -return val; +return inl (emu->port +CA0106_DATA ); } void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
@@ -350,14 +347,12 @@ void snd_ca0106_ptr_write(struct snd_ca0106 *emu, unsigned int data) {unsigned int regptr; -unsigned long flags; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (regptr, emu->port +CA0106_PTR );outl (data, emu->port +CA0106_DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); } int snd_ca0106_spi_write(struct snd_ca0106 * emu,
@@ -451,24 +446,20 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,static void snd_ca0106_intr_enable (struct snd_ca0106 *emu,unsigned int intrenb) { -unsigned long flags;unsigned int intr_enable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); intr_enable =inl (emu->port +CA0106_INTE ) | intrenb;outl (intr_enable, emu->port +CA0106_INTE ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_ca0106_intr_disable (struct snd_ca0106 *emu,unsigned int intrenb) { -unsigned long flags;unsigned int intr_enable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); intr_enable =inl (emu->port +CA0106_INTE ) & ~intrenb;outl (intr_enable, emu->port +CA0106_INTE ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }
@@ -1138,26 +1129,20 @@ static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97, unsigned short reg) {struct snd_ca0106 *emu = ac97->private_data; -unsigned long flags; -unsigned short val; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outb (reg, emu->port +CA0106_AC97ADDRESS ); - val =inw (emu->port +CA0106_AC97DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); -return val; +return inw (emu->port +CA0106_AC97DATA ); }static void snd_ca0106_ac97_write (struct snd_ac97 *ac97,unsigned short reg,unsigned short val) {struct snd_ca0106 *emu = ac97->private_data; -unsigned long flags; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outb (reg, emu->port +CA0106_AC97ADDRESS );outw (val, emu->port +CA0106_AC97DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static int snd_ca0106_ac97 (struct snd_ca0106 *chip)
sound/pci/ca0106/ca0106_proc.c +13 -15
@@ -281,16 +281,14 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry, struct snd_info_buffer *buffer) {struct snd_ca0106 *emu = entry->private_data; -unsigned long flags;char line[64 ];u32 reg, val;while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ;if (reg <0x40 && val <=0xffffffff ) { -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (val, emu->port + (reg &0xfffffffc )); -spin_unlock_irqrestore (&emu->emu_lock, flags); } } }
@@ -300,13 +298,13 @@ static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry, {struct snd_ca0106 *emu = entry->private_data;unsigned long value; -unsigned long flags;int i; +snd_iprintf (buffer,"Registers:\n\n" );for (i =0 ; i <0x20 ; i+=4 ) { -spin_lock_irqsave (&emu->emu_lock, flags); - value =inl (emu->port + i); -spin_unlock_irqrestore (&emu->emu_lock, flags); + scoped_guard(spinlock_irqsave, &emu->emu_lock) { + value =inl (emu->port + i); + }snd_iprintf (buffer,"Register %02X: %08lX\n" , i, value); } }
@@ -316,13 +314,13 @@ static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry, {struct snd_ca0106 *emu = entry->private_data;unsigned int value; -unsigned long flags;int i; +snd_iprintf (buffer,"Registers:\n\n" );for (i =0 ; i <0x20 ; i+=2 ) { -spin_lock_irqsave (&emu->emu_lock, flags); - value =inw (emu->port + i); -spin_unlock_irqrestore (&emu->emu_lock, flags); + scoped_guard(spinlock_irqsave, &emu->emu_lock) { + value =inw (emu->port + i); + }snd_iprintf (buffer,"Register %02X: %04X\n" , i, value); } }
@@ -332,13 +330,13 @@ static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry, {struct snd_ca0106 *emu = entry->private_data;unsigned int value; -unsigned long flags;int i; +snd_iprintf (buffer,"Registers:\n\n" );for (i =0 ; i <0x20 ; i+=1 ) { -spin_lock_irqsave (&emu->emu_lock, flags); - value =inb (emu->port + i); -spin_unlock_irqrestore (&emu->emu_lock, flags); + scoped_guard(spinlock_irqsave, &emu->emu_lock) { + value =inb (emu->port + i); + }snd_iprintf (buffer,"Register %02X: %02X\n" , i, value); } }
sound/pci/ca0106/ca_midi.c +74 -95
247 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 16/61 ALSA: cmipci: 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/pci/cmipci.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
sound/pci/cmipci.c +6 -14
@@ -664,14 +664,11 @@ static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream, {struct cmipci *cm =snd_pcm_substream_chip (substream);if (params_channels (hw_params) >2 ) { -mutex_lock (&cm->open_mutex); -if (cm->opened[CM_CH_PLAY ]) { -mutex_unlock (&cm->open_mutex); +guard (mutex)(&cm->open_mutex); +if (cm->opened[CM_CH_PLAY ])return -EBUSY ; - }/* reserve the channel A */ cm->opened[CM_CH_PLAY ] =CM_OPEN_PLAYBACK_MULTI ; -mutex_unlock (&cm->open_mutex); }return 0 ; }
@@ -1582,11 +1579,9 @@ static int open_device_check(struct cmipci *cm, int mode, struct snd_pcm_substre* pcm framework doesn't pass file pointer before actually opened, * we can't know whether blocking mode or not in open callback.. */ -mutex_lock (&cm->open_mutex); -if (cm->opened[ch]) { -mutex_unlock (&cm->open_mutex); +guard (mutex)(&cm->open_mutex); +if (cm->opened[ch])return -EBUSY ; - } cm->opened[ch] = mode; cm->channel[ch].substream = subs;if (! (mode &CM_OPEN_DAC )) {
@@ -1596,7 +1591,6 @@ static int open_device_check(struct cmipci *cm, int mode, struct snd_pcm_substresnd_cmipci_clear_bit (cm,CM_REG_MISC_CTRL ,CM_ENDBDAC );spin_unlock_irq (&cm->reg_lock); } -mutex_unlock (&cm->open_mutex);return 0 ; }
@@ -1604,7 +1598,7 @@ static void close_device_check(struct cmipci *cm, int mode) {int ch = mode &CM_OPEN_CH_MASK ; -mutex_lock (&cm->open_mutex); +guard (mutex)(&cm->open_mutex);if (cm->opened[ch] == mode) {if (cm->channel[ch].substream) {snd_cmipci_ch_reset (cm, ch);
@@ -1620,7 +1614,6 @@ static void close_device_check(struct cmipci *cm, int mode)spin_unlock_irq (&cm->reg_lock); } } -mutex_unlock (&cm->open_mutex); }/*
@@ -1685,7 +1678,7 @@ static int snd_cmipci_playback2_open(struct snd_pcm_substream *substream)if (err <0 )return err; runtime->hw = snd_cmipci_playback2; -mutex_lock (&cm->open_mutex); +guard (mutex)(&cm->open_mutex);if (! cm->opened[CM_CH_PLAY ]) {if (cm->can_multi_ch) { runtime->hw.channels_max = cm->max_channels;
@@ -1697,7 +1690,6 @@ static int snd_cmipci_playback2_open(struct snd_pcm_substream *substream)snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_CHANNELS , &hw_constraints_channels_8); } } -mutex_unlock (&cm->open_mutex);if (cm->chip_version ==68 ) { runtime->hw.rates |=SNDRV_PCM_RATE_88200 |SNDRV_PCM_RATE_96000 ;
Signature · 1 line
2.50.1
PATCH 17/61 ALSA: cmipci: 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/pci/cmipci.c | 165 +++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 96 deletions(-)
sound/pci/cmipci.c +69 -96
@@ -712,7 +712,7 @@ static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int chann }if (cm->can_multi_ch) { -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);if (channels >2 ) {snd_cmipci_set_bit (cm,CM_REG_LEGACY_CTRL ,CM_NXCHG );snd_cmipci_set_bit (cm,CM_REG_MISC_CTRL ,CM_XCHGDAC );
@@ -735,7 +735,6 @@ static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int channsnd_cmipci_set_bit (cm,CM_REG_CHFORMAT ,CM_CHB3D ); elsesnd_cmipci_clear_bit (cm ,CM_REG_CHFORMAT ,CM_CHB3D ); -spin_unlock_irq (&cm->reg_lock); }return 0 ; }
@@ -776,7 +775,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, period_size = (period_size * runtime->channels) /2 ; } -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);/* set buffer address */ reg = rec->ch ?CM_REG_CH1_FRAME1 :CM_REG_CH0_FRAME1 ;
@@ -842,7 +841,6 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, } rec->running =0 ; -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -854,14 +852,13 @@ static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec, int cmd) {unsigned int inthld, chen, reset, pause; -int result =0 ; inthld =CM_CH0_INT_EN << rec->ch; chen =CM_CHEN0 << rec->ch; reset =CM_RST_CH0 << rec->ch; pause =CM_PAUSE0 << rec->ch; -spin_lock (&cm->reg_lock); +guard (spinlock)(&cm->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : rec->running =1 ;
@@ -893,11 +890,9 @@ static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec,snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl);break ;default : - result = -EINVAL ; -break ; +return -EINVAL ; } -spin_unlock (&cm->reg_lock); -return result; +return 0 ; }/*
@@ -987,10 +982,9 @@ static int snd_cmipci_spdif_default_get(struct snd_kcontrol *kcontrol,struct cmipci *chip =snd_kcontrol_chip (kcontrol);int i; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i <4 ; i++) ucontrol->value.iec958.status[i] = (chip->dig_status >> (i *8 )) &0xff ; -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1002,12 +996,11 @@ static int snd_cmipci_spdif_default_put(struct snd_kcontrol *kcontrol,unsigned int val; val =0 ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i <4 ; i++) val |= (unsigned int )ucontrol->value.iec958.status[i] << (i *8 ); change = val != chip->dig_status; chip->dig_status = val; -spin_unlock_irq (&chip->reg_lock);return change; }
@@ -1061,10 +1054,9 @@ static int snd_cmipci_spdif_stream_get(struct snd_kcontrol *kcontrol,struct cmipci *chip =snd_kcontrol_chip (kcontrol);int i; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i <4 ; i++) ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i *8 )) &0xff ; -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1076,12 +1068,11 @@ static int snd_cmipci_spdif_stream_put(struct snd_kcontrol *kcontrol,unsigned int val; val =0 ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i <4 ; i++) val |= (unsigned int )ucontrol->value.iec958.status[i] << (i *8 ); change = val != chip->dig_pcm_status; chip->dig_pcm_status = val; -spin_unlock_irq (&chip->reg_lock);return change; }
@@ -1225,7 +1216,7 @@ static int setup_spdif_playback(struct cmipci *cm, struct snd_pcm_substream *subreturn err; } -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); cm->spdif_playback_avail = up;if (up) {/* they are controlled via "IEC958 Output Switch" */
@@ -1251,7 +1242,6 @@ static int setup_spdif_playback(struct cmipci *cm, struct snd_pcm_substream *subsnd_cmipci_clear_bit (cm,CM_REG_FUNCTRL1 ,CM_PLAYBACK_SPDF );setup_ac3 (cm, subs,0 ,0 ); } -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -1317,32 +1307,32 @@ static void snd_cmipci_silence_hack(struct cmipci *cm, struct cmipci_pcm *rec)/* configure for 16 bits, 2 channels, 8 kHz */ if (runtime->channels >2 )set_dac_channels (cm, rec,2 ); -spin_lock_irq (&cm->reg_lock); - val =snd_cmipci_read (cm,CM_REG_FUNCTRL1 ); - val &= ~(CM_ASFC_MASK << (rec->ch *3 )); - val |= (4 <<CM_ASFC_SHIFT ) << (rec->ch *3 ); -snd_cmipci_write (cm,CM_REG_FUNCTRL1 , val); - val =snd_cmipci_read (cm,CM_REG_CHFORMAT ); - val &= ~(CM_CH0FMT_MASK << (rec->ch *2 )); - val |= (3 <<CM_CH0FMT_SHIFT ) << (rec->ch *2 ); -if (cm->can_96k) - val &= ~(CM_CH0_SRATE_MASK << (rec->ch *2 )); -snd_cmipci_write (cm,CM_REG_CHFORMAT , val); + scoped_guard(spinlock_irq, &cm->reg_lock) { + val =snd_cmipci_read (cm,CM_REG_FUNCTRL1 ); + val &= ~(CM_ASFC_MASK << (rec->ch *3 )); + val |= (4 <<CM_ASFC_SHIFT ) << (rec->ch *3 ); +snd_cmipci_write (cm,CM_REG_FUNCTRL1 , val); + val =snd_cmipci_read (cm,CM_REG_CHFORMAT ); + val &= ~(CM_CH0FMT_MASK << (rec->ch *2 )); + val |= (3 <<CM_CH0FMT_SHIFT ) << (rec->ch *2 ); +if (cm->can_96k) + val &= ~(CM_CH0_SRATE_MASK << (rec->ch *2 )); +snd_cmipci_write (cm,CM_REG_CHFORMAT , val); -/* start stream (we don't need interrupts) */ - cm->ctrl |=CM_CHEN0 << rec->ch; -snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl); -spin_unlock_irq (&cm->reg_lock); +/* start stream (we don't need interrupts) */ + cm->ctrl |=CM_CHEN0 << rec->ch; +snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl); + }msleep (1 );/* stop and reset stream */ -spin_lock_irq (&cm->reg_lock); - cm->ctrl &= ~(CM_CHEN0 << rec->ch); - val =CM_RST_CH0 << rec->ch; -snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl | val); -snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl & ~val); -spin_unlock_irq (&cm->reg_lock); + scoped_guard(spinlock_irq, &cm->reg_lock) { + cm->ctrl &= ~(CM_CHEN0 << rec->ch); + val =CM_RST_CH0 << rec->ch; +snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl | val); +snd_cmipci_write (cm,CM_REG_FUNCTRL0 , cm->ctrl & ~val); + } rec->needs_silencing =0 ; }
@@ -1376,20 +1366,19 @@ static int snd_cmipci_capture_spdif_prepare(struct snd_pcm_substream *substream) {struct cmipci *cm =snd_pcm_substream_chip (substream); -spin_lock_irq (&cm->reg_lock); -snd_cmipci_set_bit (cm,CM_REG_FUNCTRL1 ,CM_CAPTURE_SPDF ); -if (cm->can_96k) { -if (substream->runtime->rate >48000 ) -snd_cmipci_set_bit (cm,CM_REG_CHFORMAT ,CM_DBLSPDS ); + scoped_guard(spinlock_irq, &cm->reg_lock) { +snd_cmipci_set_bit (cm,CM_REG_FUNCTRL1 ,CM_CAPTURE_SPDF ); +if (cm->can_96k) { +if (substream->runtime->rate >48000 ) +snd_cmipci_set_bit (cm,CM_REG_CHFORMAT ,CM_DBLSPDS ); +else +snd_cmipci_clear_bit (cm,CM_REG_CHFORMAT ,CM_DBLSPDS ); + } +if (snd_pcm_format_width (substream->runtime->format) >16 ) +snd_cmipci_set_bit (cm,CM_REG_MISC_CTRL ,CM_SPD32SEL );else -snd_cmipci_clear_bit (cm,CM_REG_CHFORMAT ,CM_DBLSPDS ); +snd_cmipci_clear_bit (cm,CM_REG_MISC_CTRL ,CM_SPD32SEL ); } -if (snd_pcm_format_width (substream->runtime->format) >16 ) -snd_cmipci_set_bit (cm,CM_REG_MISC_CTRL ,CM_SPD32SEL ); -else -snd_cmipci_clear_bit (cm,CM_REG_MISC_CTRL ,CM_SPD32SEL ); - -spin_unlock_irq (&cm->reg_lock);return snd_cmipci_pcm_prepare (cm, &cm->channel[CM_CH_CAPT ], substream); }
@@ -1398,10 +1387,9 @@ static int snd_cmipci_capture_spdif_hw_free(struct snd_pcm_substream *subs) {struct cmipci *cm =snd_pcm_substream_chip (subs); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);snd_cmipci_clear_bit (cm,CM_REG_FUNCTRL1 ,CM_CAPTURE_SPDF );snd_cmipci_clear_bit (cm,CM_REG_MISC_CTRL ,CM_SPD32SEL ); -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -1421,14 +1409,14 @@ static irqreturn_t snd_cmipci_interrupt(int irq, void *dev_id)return IRQ_NONE ;/* acknowledge interrupt */ -spin_lock (&cm->reg_lock); -if (status &CM_CHINT0 ) - mask |=CM_CH0_INT_EN ; -if (status &CM_CHINT1 ) - mask |=CM_CH1_INT_EN ; -snd_cmipci_clear_bit (cm,CM_REG_INT_HLDCLR , mask); -snd_cmipci_set_bit (cm,CM_REG_INT_HLDCLR , mask); -spin_unlock (&cm->reg_lock); + scoped_guard(spinlock, &cm->reg_lock) { +if (status &CM_CHINT0 ) + mask |=CM_CH0_INT_EN ; +if (status &CM_CHINT1 ) + mask |=CM_CH1_INT_EN ; +snd_cmipci_clear_bit (cm,CM_REG_INT_HLDCLR , mask); +snd_cmipci_set_bit (cm,CM_REG_INT_HLDCLR , mask); + }if (cm->rmidi && (status &CM_UARTINT ))snd_mpu401_uart_interrupt (irq, cm->rmidi->private_data);
@@ -1587,9 +1575,8 @@ static int open_device_check(struct cmipci *cm, int mode, struct snd_pcm_substreif (! (mode &CM_OPEN_DAC )) {/* disable dual DAC mode */ cm->channel[ch].is_dac =0 ; -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);snd_cmipci_clear_bit (cm,CM_REG_MISC_CTRL ,CM_ENDBDAC ); -spin_unlock_irq (&cm->reg_lock); }return 0 ; }
@@ -1609,9 +1596,8 @@ static void close_device_check(struct cmipci *cm, int mode)if (! cm->channel[ch].is_dac) {/* enable dual DAC mode again */ cm->channel[ch].is_dac =1 ; -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);snd_cmipci_set_bit (cm,CM_REG_MISC_CTRL ,CM_ENDBDAC ); -spin_unlock_irq (&cm->reg_lock); } } }
@@ -2002,7 +1988,7 @@ static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol,int val;cmipci_sb_reg_decode (®, kcontrol->private_value); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); val = (snd_cmipci_mixer_read (cm, reg.left_reg) >> reg.left_shift) & reg.mask;if (reg.invert) val = reg.mask - val;
@@ -2013,7 +1999,6 @@ static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol, val = reg.mask - val; ucontrol->value.integer.value[1 ] = val; } -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -2037,7 +2022,7 @@ static int snd_cmipci_put_volume(struct snd_kcontrol *kcontrol, right <<= reg.right_shift; }else right =0 ; -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); oleft =snd_cmipci_mixer_read (cm, reg.left_reg); left |= oleft & ~(reg.mask << reg.left_shift); change = left != oleft;
@@ -2052,7 +2037,6 @@ static int snd_cmipci_put_volume(struct snd_kcontrol *kcontrol,snd_cmipci_mixer_write (cm, reg.right_reg, right); }else snd_cmipci_mixer_write (cm, reg.left_reg, left); -spin_unlock_irq (&cm->reg_lock);return change; }
@@ -2084,10 +2068,9 @@ static int snd_cmipci_get_input_sw(struct snd_kcontrol *kcontrol,int val1, val2;cmipci_sb_reg_decode (®, kcontrol->private_value); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); val1 =snd_cmipci_mixer_read (cm, reg.left_reg); val2 =snd_cmipci_mixer_read (cm, reg.right_reg); -spin_unlock_irq (&cm->reg_lock); ucontrol->value.integer.value[0 ] = (val1 >> reg.left_shift) &1 ; ucontrol->value.integer.value[1 ] = (val2 >> reg.left_shift) &1 ; ucontrol->value.integer.value[2 ] = (val1 >> reg.right_shift) &1 ;
@@ -2104,7 +2087,7 @@ static int snd_cmipci_put_input_sw(struct snd_kcontrol *kcontrol,int val1, val2, oval1, oval2;cmipci_sb_reg_decode (®, kcontrol->private_value); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); oval1 =snd_cmipci_mixer_read (cm, reg.left_reg); oval2 =snd_cmipci_mixer_read (cm, reg.right_reg); val1 = oval1 & ~((1 << reg.left_shift) | (1 << reg.right_shift));
@@ -2116,7 +2099,6 @@ static int snd_cmipci_put_input_sw(struct snd_kcontrol *kcontrol, change = val1 != oval1 || val2 != oval2;snd_cmipci_mixer_write (cm, reg.left_reg, val1);snd_cmipci_mixer_write (cm, reg.right_reg, val2); -spin_unlock_irq (&cm->reg_lock);return change; }
@@ -2174,7 +2156,7 @@ static int snd_cmipci_get_native_mixer(struct snd_kcontrol *kcontrol,unsigned char oreg, val;cmipci_sb_reg_decode (®, kcontrol->private_value); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); oreg =inb (cm->iobase + reg.left_reg); val = (oreg >> reg.left_shift) & reg.mask;if (reg.invert)
@@ -2186,7 +2168,6 @@ static int snd_cmipci_get_native_mixer(struct snd_kcontrol *kcontrol, val = reg.mask - val; ucontrol->value.integer.value[1 ] = val; } -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -2198,7 +2179,7 @@ static int snd_cmipci_put_native_mixer(struct snd_kcontrol *kcontrol,unsigned char oreg, nreg, val;cmipci_sb_reg_decode (®, kcontrol->private_value); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); oreg =inb (cm->iobase + reg.left_reg); val = ucontrol->value.integer.value[0 ] & reg.mask;if (reg.invert)
@@ -2213,7 +2194,6 @@ static int snd_cmipci_put_native_mixer(struct snd_kcontrol *kcontrol, nreg |= (val << reg.right_shift); }outb (nreg, cm->iobase + reg.left_reg); -spin_unlock_irq (&cm->reg_lock);return (nreg != oreg); }
@@ -2300,10 +2280,9 @@ static int _snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,unsigned int val;struct cmipci *cm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);if (args->ac3_sensitive && cm->mixer_insensitive) { ucontrol->value.integer.value[0 ] =0 ; -spin_unlock_irq (&cm->reg_lock);return 0 ; }if (args->is_byte)
@@ -2311,7 +2290,6 @@ static int _snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,else val =snd_cmipci_read (cm, args->reg); ucontrol->value.integer.value[0 ] = ((val & args->mask) == args->mask_on) ?1 :0 ; -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -2333,10 +2311,9 @@ static int _snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,int change;struct cmipci *cm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);if (args->ac3_sensitive && cm->mixer_insensitive) {/* ignored */ -spin_unlock_irq (&cm->reg_lock);return 0 ; }if (args->is_byte)
@@ -2356,7 +2333,6 @@ static int _snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,else snd_cmipci_write (cm, args->reg, val); } -spin_unlock_irq (&cm->reg_lock);return change; }
@@ -2489,9 +2465,8 @@ static int snd_cmipci_line_in_mode_get(struct snd_kcontrol *kcontrol, {struct cmipci *cm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); ucontrol->value.enumerated.item[0 ] =get_line_in_mode (cm); -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -2501,7 +2476,7 @@ static int snd_cmipci_line_in_mode_put(struct snd_kcontrol *kcontrol,struct cmipci *cm =snd_kcontrol_chip (kcontrol);int change; -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);if (ucontrol->value.enumerated.item[0 ] ==2 ) change =snd_cmipci_set_bit (cm,CM_REG_LEGACY_CTRL ,CM_CENTR2LIN |CM_BASE2LIN );else
@@ -2510,7 +2485,6 @@ static int snd_cmipci_line_in_mode_put(struct snd_kcontrol *kcontrol, change |=snd_cmipci_set_bit_b (cm,CM_REG_MIXER1 ,CM_REAR2LIN ); else change |= snd_cmipci_clear_bit_b(cm, CM_REG_MIXER1, CM_REAR2LIN); -spin_unlock_irq (&cm->reg_lock);return change; }
@@ -2526,11 +2500,11 @@ static int snd_cmipci_mic_in_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct cmipci *cm =snd_kcontrol_chip (kcontrol); +/* same bit as spdi_phase */ -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock); ucontrol->value.enumerated.item[0 ] = (snd_cmipci_read_b (cm,CM_REG_MISC ) &CM_SPDIF_INVERSE ) ?1 :0 ; -spin_unlock_irq (&cm->reg_lock);return 0 ; }
@@ -2540,12 +2514,11 @@ static int snd_cmipci_mic_in_mode_put(struct snd_kcontrol *kcontrol,struct cmipci *cm =snd_kcontrol_chip (kcontrol);int change; -spin_lock_irq (&cm->reg_lock); +guard (spinlock_irq)(&cm->reg_lock);if (ucontrol->value.enumerated.item[0 ]) change =snd_cmipci_set_bit_b (cm,CM_REG_MISC ,CM_SPDIF_INVERSE );else change =snd_cmipci_clear_bit_b (cm,CM_REG_MISC ,CM_SPDIF_INVERSE ); -spin_unlock_irq (&cm->reg_lock);return change; }
@@ -2627,9 +2600,9 @@ static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)strscpy (card->mixername,"CMedia PCI" ); -spin_lock_irq (&cm->reg_lock); -snd_cmipci_mixer_write (cm,0x00 ,0x00 );/* mixer reset */ -spin_unlock_irq (&cm->reg_lock); + scoped_guard(spinlock_irq, &cm->reg_lock) { +snd_cmipci_mixer_write (cm,0x00 ,0x00 );/* mixer reset */ + }for (idx =0 ; idx <ARRAY_SIZE (snd_cmipci_mixers); idx++) {if (cm->chip_version ==68 ) {// 8768 has no PCM volume
Signature · 1 line
2.50.1
PATCH 18/61 ALSA: cs4281: 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/pci/cs4281.c | 53 +++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 34 deletions(-)
sound/pci/cs4281.c +19 -34
@@ -651,7 +651,7 @@ static int snd_cs4281_trigger(struct snd_pcm_substream *substream, int cmd)struct cs4281_dma *dma = substream->runtime->private_data;struct cs4281 *chip =snd_pcm_substream_chip (substream); -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_PAUSE_PUSH : dma->valDCR |=BA0_DCR_MSK ;
@@ -678,13 +678,11 @@ static int snd_cs4281_trigger(struct snd_pcm_substream *substream, int cmd) dma->valFCR &= ~BA0_FCR_FEN ;break ;default : -spin_unlock (&chip->reg_lock);return -EINVAL ; }snd_cs4281_pokeBA0 (chip, dma->regDMR, dma->valDMR);snd_cs4281_pokeBA0 (chip, dma->regFCR, dma->valFCR);snd_cs4281_pokeBA0 (chip, dma->regDCR, dma->valDCR); -spin_unlock (&chip->reg_lock);return 0 ; }
@@ -782,9 +780,8 @@ static int snd_cs4281_playback_prepare(struct snd_pcm_substream *substream)struct cs4281_dma *dma = runtime->private_data;struct cs4281 *chip =snd_pcm_substream_chip (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);snd_cs4281_mode (chip, dma, runtime,0 ,1 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -794,9 +791,8 @@ static int snd_cs4281_capture_prepare(struct snd_pcm_substream *substream)struct cs4281_dma *dma = runtime->private_data;struct cs4281 *chip =snd_pcm_substream_chip (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);snd_cs4281_mode (chip, dma, runtime,1 ,1 ); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1580,7 +1576,7 @@ static int snd_cs4281_midi_input_open(struct snd_rawmidi_substream *substream) {struct cs4281 *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->midcr |=BA0_MIDCR_RXE ; chip->midi_input = substream;if (!(chip->uartm &CS4281_MODE_OUTPUT )) {
@@ -1588,7 +1584,6 @@ static int snd_cs4281_midi_input_open(struct snd_rawmidi_substream *substream) }else {snd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1596,7 +1591,7 @@ static int snd_cs4281_midi_input_close(struct snd_rawmidi_substream *substream) {struct cs4281 *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->midcr &= ~(BA0_MIDCR_RXE |BA0_MIDCR_RIE ); chip->midi_input =NULL ;if (!(chip->uartm &CS4281_MODE_OUTPUT )) {
@@ -1605,7 +1600,6 @@ static int snd_cs4281_midi_input_close(struct snd_rawmidi_substream *substream)snd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } chip->uartm &= ~CS4281_MODE_INPUT ; -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1613,7 +1607,7 @@ static int snd_cs4281_midi_output_open(struct snd_rawmidi_substream *substream) {struct cs4281 *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->uartm |=CS4281_MODE_OUTPUT ; chip->midcr |=BA0_MIDCR_TXE ; chip->midi_output = substream;
@@ -1622,7 +1616,6 @@ static int snd_cs4281_midi_output_open(struct snd_rawmidi_substream *substream) }else {snd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -1630,7 +1623,7 @@ static int snd_cs4281_midi_output_close(struct snd_rawmidi_substream *substream) {struct cs4281 *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->midcr &= ~(BA0_MIDCR_TXE |BA0_MIDCR_TIE ); chip->midi_output =NULL ;if (!(chip->uartm &CS4281_MODE_INPUT )) {
@@ -1639,16 +1632,14 @@ static int snd_cs4281_midi_output_close(struct snd_rawmidi_substream *substream)snd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } chip->uartm &= ~CS4281_MODE_OUTPUT ; -spin_unlock_irq (&chip->reg_lock);return 0 ; }static void snd_cs4281_midi_input_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct cs4281 *chip = substream->rmidi->private_data; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);if (up) {if ((chip->midcr &BA0_MIDCR_RIE ) ==0 ) { chip->midcr |=BA0_MIDCR_RIE ;
@@ -1660,16 +1651,14 @@ static void snd_cs4281_midi_input_trigger(struct snd_rawmidi_substream *substreasnd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } } -spin_unlock_irqrestore (&chip->reg_lock, flags); }static void snd_cs4281_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct cs4281 *chip = substream->rmidi->private_data;unsigned char byte; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);if (up) {if ((chip->midcr &BA0_MIDCR_TIE ) ==0 ) { chip->midcr |=BA0_MIDCR_TIE ;
@@ -1690,7 +1679,6 @@ static void snd_cs4281_midi_output_trigger(struct snd_rawmidi_substream *substresnd_cs4281_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } } -spin_unlock_irqrestore (&chip->reg_lock, flags); } static const struct snd_rawmidi_ops snd_cs4281_midi_output =
@@ -1743,10 +1731,12 @@ static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id) }if (status & (BA0_HISR_DMA (0 )|BA0_HISR_DMA (1 )|BA0_HISR_DMA (2 )|BA0_HISR_DMA (3 ))) { -for (dma =0 ; dma <4 ; dma++) +for (dma =0 ; dma <4 ; dma++) { +bool period_elapsed = false; + cdma = &chip->dma[dma]; +if (status &BA0_HISR_DMA (dma)) { - cdma = &chip->dma[dma]; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);/* ack DMA IRQ */ val =snd_cs4281_peekBA0 (chip, cdma->regHDSR);/* workaround, sometimes CS4281 acknowledges */
@@ -1755,24 +1745,23 @@ static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id)if ((val &BA0_HDSR_DHTC ) && !(cdma->frag &1 )) { cdma->frag--; chip->spurious_dhtc_irq++; -spin_unlock (&chip->reg_lock);continue ; }if ((val &BA0_HDSR_DTC ) && (cdma->frag &1 )) { cdma->frag--; chip->spurious_dtc_irq++; -spin_unlock (&chip->reg_lock);continue ; } -spin_unlock (&chip->reg_lock); -snd_pcm_period_elapsed (cdma->substream); } +if (period_elapsed) +snd_pcm_period_elapsed (cdma->substream); + } }if ((status &BA0_HISR_MIDI ) && chip->rmidi) {unsigned char c; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);while ((snd_cs4281_peekBA0 (chip,BA0_MIDSR ) &BA0_MIDSR_RBE ) ==0 ) { c =snd_cs4281_peekBA0 (chip,BA0_MIDRP );if ((chip->midcr &BA0_MIDCR_RIE ) ==0 )
@@ -1789,7 +1778,6 @@ static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id) }snd_cs4281_pokeBA0 (chip,BA0_MIDWP , c); } -spin_unlock (&chip->reg_lock); }/* EOI to the PCI part... reenables interrupts */
@@ -1805,7 +1793,6 @@ static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id)static void snd_cs4281_opl3_command (struct snd_opl3 *opl3,unsigned short cmd,unsigned char val) { -unsigned long flags;struct cs4281 *chip = opl3->private_data;void __iomem *port;
@@ -1814,15 +1801,13 @@ static void snd_cs4281_opl3_command(struct snd_opl3 *opl3, unsigned short cmd,else port = chip->ba0 +BA0_B0AP ;/* left port */ -spin_lock_irqsave (&opl3->reg_lock, flags); +guard (spinlock_irqsave)(&opl3->reg_lock);writel ((unsigned int )cmd, port);udelay (10 );writel ((unsigned int )val, port +4 );udelay (30 ); - -spin_unlock_irqrestore (&opl3->reg_lock, flags); } static int __snd_cs4281_probe(struct pci_dev *pci,
Signature · 1 line
2.50.1
PATCH 19/61 ALSA: cs46xx: 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/pci/cs46xx/cs46xx_lib.c | 87 +++++++++++------------------ sound/pci/cs46xx/dsp_spos.c | 66 +++++++++------------- sound/pci/cs46xx/dsp_spos_scb_lib.c | 3 +- 3 files changed, 59 insertions(+), 97 deletions(-)
sound/pci/cs46xx/cs46xx_lib.c +32 -55
@@ -1093,24 +1093,17 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,if (snd_BUG_ON (!sample_rate))return -ENXIO ; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex); -if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) { -mutex_unlock (&chip->spos_mutex); +if (_cs46xx_adjust_sample_rate (chip, cpcm, sample_rate))return -ENXIO ; - }snd_BUG_ON (!cpcm->pcm_channel); -if (!cpcm->pcm_channel) { -mutex_unlock (&chip->spos_mutex); +if (!cpcm->pcm_channel)return -ENXIO ; - } - -if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size)) { -mutex_unlock (&chip->spos_mutex); +if (cs46xx_dsp_pcm_channel_set_period (chip, cpcm->pcm_channel, period_size))return -EINVAL ; - } dev_dbg(chip->card->dev, "period_size (%d), periods (%d) buffer_size(%d)\n",
@@ -1144,12 +1137,8 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,if (runtime->dma_area == cpcm->hw_buf.area)snd_pcm_set_runtime_buffer (substream,NULL ); err =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (hw_params)); -if (err <0 ) { -#ifdef CONFIG_SND_CS46XX_NEW_DSP -mutex_unlock (&chip->spos_mutex); -#endif +if (err <0 )return err; - }#ifdef CONFIG_SND_CS46XX_NEW_DSP if (cpcm->pcm_channel_id ==DSP_PCM_MAIN_CHANNEL ) {
@@ -1169,10 +1158,6 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, } -#ifdef CONFIG_SND_CS46XX_NEW_DSP -mutex_unlock (&chip->spos_mutex); -#endif -return 0 ; }
@@ -1495,16 +1480,14 @@ static int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,in cpcm->substream = substream;#ifdef CONFIG_SND_CS46XX_NEW_DSP -mutex_lock (&chip->spos_mutex); - cpcm->pcm_channel =NULL ; - cpcm->pcm_channel_id = pcm_channel_id; - + scoped_guard(mutex, &chip->spos_mutex) { + cpcm->pcm_channel =NULL ; + cpcm->pcm_channel_id = pcm_channel_id; + }snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_BYTES , &hw_constraints_period_sizes); - -mutex_unlock (&chip->spos_mutex);#else chip->playback_pcm = cpcm;/* HACK */ #endif
@@ -1541,9 +1524,9 @@ static int snd_cs46xx_playback_open_iec958(struct snd_pcm_substream *substream)dev_dbg (chip->card->dev,"open raw iec958 channel\n" ); -mutex_lock (&chip->spos_mutex); -cs46xx_iec958_pre_open (chip); -mutex_unlock (&chip->spos_mutex); + scoped_guard(mutex, &chip->spos_mutex) { +cs46xx_iec958_pre_open (chip); + }return _cs46xx_playback_open_channel (substream,DSP_IEC958_CHANNEL ); }
@@ -1559,9 +1542,9 @@ static int snd_cs46xx_playback_close_iec958(struct snd_pcm_substream *substream) err =snd_cs46xx_playback_close (substream); -mutex_lock (&chip->spos_mutex); -cs46xx_iec958_post_close (chip); -mutex_unlock (&chip->spos_mutex); + scoped_guard(mutex, &chip->spos_mutex) { +cs46xx_iec958_post_close (chip); + }return err; }
@@ -1602,12 +1585,12 @@ static int snd_cs46xx_playback_close(struct snd_pcm_substream *substream)if (!cpcm)return -ENXIO ;#ifdef CONFIG_SND_CS46XX_NEW_DSP -mutex_lock (&chip->spos_mutex); -if (cpcm->pcm_channel) { -cs46xx_dsp_destroy_pcm_channel (chip,cpcm->pcm_channel); - cpcm->pcm_channel =NULL ; + scoped_guard(mutex, &chip->spos_mutex) { +if (cpcm->pcm_channel) { +cs46xx_dsp_destroy_pcm_channel (chip, cpcm->pcm_channel); + cpcm->pcm_channel =NULL ; + } } -mutex_unlock (&chip->spos_mutex);#else chip->playback_pcm =NULL ;#endif
@@ -1982,15 +1965,15 @@ static int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol,switch (kcontrol->private_value) {case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT : -mutex_lock (&chip->spos_mutex); - change = (chip->dsp_spos_instance->spdif_status_out &DSP_SPDIF_STATUS_OUTPUT_ENABLED ); -if (ucontrol->value.integer.value[0 ] && !change) -cs46xx_dsp_enable_spdif_out (chip); -else if (change && !ucontrol->value.integer.value[0 ]) -cs46xx_dsp_disable_spdif_out (chip); + scoped_guard(mutex, &chip->spos_mutex) { + change = (chip->dsp_spos_instance->spdif_status_out &DSP_SPDIF_STATUS_OUTPUT_ENABLED ); +if (ucontrol->value.integer.value[0 ] && !change) +cs46xx_dsp_enable_spdif_out (chip); +else if (change && !ucontrol->value.integer.value[0 ]) +cs46xx_dsp_disable_spdif_out (chip); - res = (change != (chip->dsp_spos_instance->spdif_status_out &DSP_SPDIF_STATUS_OUTPUT_ENABLED )); -mutex_unlock (&chip->spos_mutex); + res = (change != (chip->dsp_spos_instance->spdif_status_out &DSP_SPDIF_STATUS_OUTPUT_ENABLED )); + }break ;case CS46XX_MIXER_SPDIF_INPUT_ELEMENT : change = chip->dsp_spos_instance->spdif_status_in;
@@ -2131,12 +2114,11 @@ static int snd_cs46xx_spdif_default_get(struct snd_kcontrol *kcontrol,struct snd_cs46xx *chip =snd_kcontrol_chip (kcontrol);struct dsp_spos_instance * ins = chip->dsp_spos_instance; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex); ucontrol->value.iec958.status[0 ] =_wrap_all_bits ((ins->spdif_csuv_default >>24 ) &0xff ); ucontrol->value.iec958.status[1 ] =_wrap_all_bits ((ins->spdif_csuv_default >>16 ) &0xff ); ucontrol->value.iec958.status[2 ] =0 ; ucontrol->value.iec958.status[3 ] =_wrap_all_bits ((ins->spdif_csuv_default) &0xff ); -mutex_unlock (&chip->spos_mutex);return 0 ; }
@@ -2149,7 +2131,7 @@ static int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol,unsigned int val;int change; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex); val = ((unsigned int )_wrap_all_bits (ucontrol->value.iec958.status[0 ]) <<24 ) | ((unsigned int )_wrap_all_bits (ucontrol->value.iec958.status[2 ]) <<16 ) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) |
@@ -2163,8 +2145,6 @@ static int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol,if ( !(ins->spdif_status_out &DSP_SPDIF_STATUS_PLAYBACK_OPEN ) )cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV ,val); -mutex_unlock (&chip->spos_mutex); -return change; }
@@ -2184,12 +2164,11 @@ static int snd_cs46xx_spdif_stream_get(struct snd_kcontrol *kcontrol,struct snd_cs46xx *chip =snd_kcontrol_chip (kcontrol);struct dsp_spos_instance * ins = chip->dsp_spos_instance; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex); ucontrol->value.iec958.status[0 ] =_wrap_all_bits ((ins->spdif_csuv_stream >>24 ) &0xff ); ucontrol->value.iec958.status[1 ] =_wrap_all_bits ((ins->spdif_csuv_stream >>16 ) &0xff ); ucontrol->value.iec958.status[2 ] =0 ; ucontrol->value.iec958.status[3 ] =_wrap_all_bits ((ins->spdif_csuv_stream) &0xff ); -mutex_unlock (&chip->spos_mutex);return 0 ; }
@@ -2202,7 +2181,7 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol,unsigned int val;int change; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex); val = ((unsigned int )_wrap_all_bits (ucontrol->value.iec958.status[0 ]) <<24 ) | ((unsigned int )_wrap_all_bits (ucontrol->value.iec958.status[1 ]) <<16 ) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) |
@@ -2216,8 +2195,6 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol,if ( ins->spdif_status_out &DSP_SPDIF_STATUS_PLAYBACK_OPEN )cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV ,val); -mutex_unlock (&chip->spos_mutex); -return change; }
sound/pci/cs46xx/dsp_spos.c +26 -40
209 lines not on this page · raw message
sound/pci/cs46xx/dsp_spos_scb_lib.c +1 -2
@@ -63,7 +63,7 @@ static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,int j,col;void __iomem *dst = chip->region.idx[1 ].remap_addr +DSP_PARAMETER_BYTE_OFFSET ; -mutex_lock (&chip->spos_mutex); +guard (mutex)(&chip->spos_mutex);snd_iprintf (buffer,"%04x %s:\n" ,scb->address,scb->scb_name);for (col =0 ,j =0 ;j <0x10 ; j++,col++) {
@@ -91,7 +91,6 @@ static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry, scb->task_entry->address); snd_iprintf(buffer,"index [%d] ref_count [%d]\n",scb->index,scb->ref_count); - mutex_unlock(&chip->spos_mutex); }#endif
Signature · 1 line
2.50.1
PATCH 20/61 ALSA: cs46xx: 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/pci/cs46xx/cs46xx_lib.c | 113 ++++++++++++---------------- sound/pci/cs46xx/dsp_spos.c | 4 +- sound/pci/cs46xx/dsp_spos_scb_lib.c | 60 +++++---------- 3 files changed, 69 insertions(+), 108 deletions(-)
sound/pci/cs46xx/cs46xx_lib.c +48 -65
@@ -707,7 +707,6 @@ static void snd_cs46xx_proc_stop(struct snd_cs46xx *chip)static void snd_cs46xx_set_play_sample_rate (struct snd_cs46xx *chip,unsigned int rate) { -unsigned long flags;unsigned int tmp1, tmp2;unsigned int phiIncr;unsigned int correctionPerGOF, correctionPerSec;
@@ -744,16 +743,14 @@ static void snd_cs46xx_set_play_sample_rate(struct snd_cs46xx *chip, unsigned in/* * Fill in the SampleRateConverter control block. */ -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);snd_cs46xx_poke (chip,BA1_PSRC , ((correctionPerSec <<16 ) &0xFFFF0000 ) | (correctionPerGOF &0xFFFF ));snd_cs46xx_poke (chip,BA1_PPI , phiIncr); -spin_unlock_irqrestore (&chip->reg_lock, flags); }static void snd_cs46xx_set_capture_sample_rate (struct snd_cs46xx *chip,unsigned int rate) { -unsigned long flags;unsigned int phiIncr, coeffIncr, tmp1, tmp2;unsigned int correctionPerGOF, correctionPerSec, initialDelay;unsigned int frameGroupLength, cnt;
@@ -818,14 +815,14 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned/* * Fill in the VariDecimate control block. */ -spin_lock_irqsave (&chip->reg_lock, flags); -snd_cs46xx_poke (chip,BA1_CSRC , - ((correctionPerSec <<16 ) &0xFFFF0000 ) | (correctionPerGOF &0xFFFF )); -snd_cs46xx_poke (chip,BA1_CCI , coeffIncr); -snd_cs46xx_poke (chip,BA1_CD , - (((BA1_VARIDEC_BUF_1 + (initialDelay <<2 )) <<16 ) &0xFFFF0000 ) |0x80 ); -snd_cs46xx_poke (chip,BA1_CPI , phiIncr); -spin_unlock_irqrestore (&chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &chip->reg_lock) { +snd_cs46xx_poke (chip,BA1_CSRC , + ((correctionPerSec <<16 ) &0xFFFF0000 ) | (correctionPerGOF &0xFFFF )); +snd_cs46xx_poke (chip,BA1_CCI , coeffIncr); +snd_cs46xx_poke (chip,BA1_CD , + (((BA1_VARIDEC_BUF_1 + (initialDelay <<2 )) <<16 ) &0xFFFF0000 ) |0x80 ); +snd_cs46xx_poke (chip,BA1_CPI , phiIncr); + }/* * Figure out the frame group length for the write back task. Basically,
@@ -848,13 +845,12 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned/* * Fill in the WriteBack control block. */ -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);snd_cs46xx_poke (chip,BA1_CFG1 , frameGroupLength);snd_cs46xx_poke (chip,BA1_CFG2 , (0x00800000 | frameGroupLength));snd_cs46xx_poke (chip,BA1_CCST ,0x0000FFFF );snd_cs46xx_poke (chip,BA1_CSPB , ((65536 * rate) /24000 ));snd_cs46xx_poke (chip, (BA1_CSPB +4 ),0x0000FFFF ); -spin_unlock_irqrestore (&chip->reg_lock, flags); }/*
@@ -969,15 +965,14 @@ static int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream,if (substream->runtime->periods !=CS46XX_FRAGS )snd_cs46xx_playback_transfer (substream);#else -spin_lock (&chip->reg_lock); -if (substream->runtime->periods !=CS46XX_FRAGS ) -snd_cs46xx_playback_transfer (substream); - {unsigned int tmp; - tmp =snd_cs46xx_peek (chip,BA1_PCTL ); - tmp &=0x0000ffff ; -snd_cs46xx_poke (chip,BA1_PCTL , chip->play_ctl | tmp); + scoped_guard(spinlock, &chip->reg_lock) { +unsigned int tmp; +if (substream->runtime->periods !=CS46XX_FRAGS ) +snd_cs46xx_playback_transfer (substream); + tmp =snd_cs46xx_peek (chip,BA1_PCTL ); + tmp &=0x0000ffff ; +snd_cs46xx_poke (chip,BA1_PCTL , chip->play_ctl | tmp); } -spin_unlock (&chip->reg_lock);#endif break ;case SNDRV_PCM_TRIGGER_STOP :
@@ -990,13 +985,12 @@ static int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream,if (!cpcm->pcm_channel->unlinked)cs46xx_dsp_pcm_unlink (chip,cpcm->pcm_channel);#else -spin_lock (&chip->reg_lock); - {unsigned int tmp; - tmp =snd_cs46xx_peek (chip,BA1_PCTL ); - tmp &=0x0000ffff ; -snd_cs46xx_poke (chip,BA1_PCTL , tmp); + scoped_guard(spinlock, &chip->reg_lock) { +unsigned int tmp; + tmp =snd_cs46xx_peek (chip,BA1_PCTL ); + tmp &=0x0000ffff ; +snd_cs46xx_poke (chip,BA1_PCTL , tmp); } -spin_unlock (&chip->reg_lock);#endif break ;default :
@@ -1012,9 +1006,8 @@ static int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream, {struct snd_cs46xx *chip =snd_pcm_substream_chip (substream);unsigned int tmp; -int result =0 ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -1029,12 +1022,9 @@ static int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream,snd_cs46xx_poke (chip,BA1_CCTL , tmp);break ;default : - result = -EINVAL ; -break ; +return -EINVAL ; } -spin_unlock (&chip->reg_lock); - -return result; +return 0 ; }#ifdef CONFIG_SND_CS46XX_NEW_DSP
@@ -1371,7 +1361,7 @@ static irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id)if ((status1 &HISR_MIDI ) && chip->rmidi) {unsigned char c; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);while ((snd_cs46xx_peekBA0 (chip,BA0_MIDSR ) &MIDSR_RBE ) ==0 ) { c =snd_cs46xx_peekBA0 (chip,BA0_MIDRP );if ((chip->midcr &MIDCR_RIE ) ==0 )
@@ -1388,7 +1378,6 @@ static irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id) }snd_cs46xx_pokeBA0 (chip,BA0_MIDWP , c); } -spin_unlock (&chip->reg_lock); }/* * EOI to the PCI part....reenables interrupts
@@ -2509,7 +2498,7 @@ static int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream)struct snd_cs46xx *chip = substream->rmidi->private_data; chip->active_ctrl (chip,1 ); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->uartm |=CS46XX_MODE_INPUT ; chip->midcr |=MIDCR_RXE ; chip->midi_input = substream;
@@ -2518,7 +2507,6 @@ static int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream) }else {snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -2526,16 +2514,16 @@ static int snd_cs46xx_midi_input_close(struct snd_rawmidi_substream *substream) {struct snd_cs46xx *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); - chip->midcr &= ~(MIDCR_RXE |MIDCR_RIE ); - chip->midi_input =NULL ; -if (!(chip->uartm &CS46XX_MODE_OUTPUT )) { -snd_cs46xx_midi_reset (chip); - }else { -snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->midcr &= ~(MIDCR_RXE |MIDCR_RIE ); + chip->midi_input =NULL ; +if (!(chip->uartm &CS46XX_MODE_OUTPUT )) { +snd_cs46xx_midi_reset (chip); + }else { +snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); + } + chip->uartm &= ~CS46XX_MODE_INPUT ; } - chip->uartm &= ~CS46XX_MODE_INPUT ; -spin_unlock_irq (&chip->reg_lock); chip->active_ctrl (chip,-1 );return 0 ; }
@@ -2546,7 +2534,7 @@ static int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) chip->active_ctrl (chip,1 ); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->uartm |=CS46XX_MODE_OUTPUT ; chip->midcr |=MIDCR_TXE ; chip->midi_output = substream;
@@ -2555,7 +2543,6 @@ static int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) }else {snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -2563,26 +2550,25 @@ static int snd_cs46xx_midi_output_close(struct snd_rawmidi_substream *substream) {struct snd_cs46xx *chip = substream->rmidi->private_data; -spin_lock_irq (&chip->reg_lock); - chip->midcr &= ~(MIDCR_TXE |MIDCR_TIE ); - chip->midi_output =NULL ; -if (!(chip->uartm &CS46XX_MODE_INPUT )) { -snd_cs46xx_midi_reset (chip); - }else { -snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->midcr &= ~(MIDCR_TXE |MIDCR_TIE ); + chip->midi_output =NULL ; +if (!(chip->uartm &CS46XX_MODE_INPUT )) { +snd_cs46xx_midi_reset (chip); + }else { +snd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); + } + chip->uartm &= ~CS46XX_MODE_OUTPUT ; } - chip->uartm &= ~CS46XX_MODE_OUTPUT ; -spin_unlock_irq (&chip->reg_lock); chip->active_ctrl (chip,-1 );return 0 ; }static void snd_cs46xx_midi_input_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct snd_cs46xx *chip = substream->rmidi->private_data; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);if (up) {if ((chip->midcr &MIDCR_RIE ) ==0 ) { chip->midcr |=MIDCR_RIE ;
@@ -2594,16 +2580,14 @@ static void snd_cs46xx_midi_input_trigger(struct snd_rawmidi_substream *substreasnd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } } -spin_unlock_irqrestore (&chip->reg_lock, flags); }static void snd_cs46xx_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) { -unsigned long flags;struct snd_cs46xx *chip = substream->rmidi->private_data;unsigned char byte; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);if (up) {if ((chip->midcr &MIDCR_TIE ) ==0 ) { chip->midcr |=MIDCR_TIE ;
@@ -2624,7 +2608,6 @@ static void snd_cs46xx_midi_output_trigger(struct snd_rawmidi_substream *substresnd_cs46xx_pokeBA0 (chip,BA0_MIDCR , chip->midcr); } } -spin_unlock_irqrestore (&chip->reg_lock, flags); } static const struct snd_rawmidi_ops snd_cs46xx_midi_output =
sound/pci/cs46xx/dsp_spos.c +1 -3
@@ -1696,7 +1696,7 @@ int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip) ins->spdif_in_src, SCB_ON_PARENT_SUBLIST_SCB); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);/* reset SPDIF input sample buffer pointer */ /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
@@ -1709,8 +1709,6 @@ int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)/* unmute SRC volume */ cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff ,0x7fff ); -spin_unlock_irq (&chip->reg_lock); -/* set SPDIF input sample rate and unmute NOTE: only 48khz support for SPDIF input this time */ /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
sound/pci/cs46xx/dsp_spos_scb_lib.c +20 -40
157 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 21/61 ALSA: cs5535audio: 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/pci/cs5535audio/cs5535audio.c | 14 ++++++++------ sound/pci/cs5535audio/cs5535audio_pcm.c | 12 ++++-------- 2 files changed, 12 insertions(+), 14 deletions(-)
sound/pci/cs5535audio/cs5535audio.c +8 -6
@@ -176,9 +176,10 @@ static int snd_cs5535audio_mixer(struct cs5535audio *cs5535au)static void process_bm0_irq (struct cs5535audio *cs5535au) {u8 bm_stat; -spin_lock (&cs5535au->reg_lock); - bm_stat =cs_readb (cs5535au,ACC_BM0_STATUS ); -spin_unlock (&cs5535au->reg_lock); + + scoped_guard(spinlock, &cs5535au->reg_lock) { + bm_stat =cs_readb (cs5535au,ACC_BM0_STATUS ); + }if (bm_stat &EOP ) {snd_pcm_period_elapsed (cs5535au->playback_substream); }else {
@@ -191,9 +192,10 @@ static void process_bm0_irq(struct cs5535audio *cs5535au)static void process_bm1_irq (struct cs5535audio *cs5535au) {u8 bm_stat; -spin_lock (&cs5535au->reg_lock); - bm_stat =cs_readb (cs5535au,ACC_BM1_STATUS ); -spin_unlock (&cs5535au->reg_lock); + + scoped_guard(spinlock, &cs5535au->reg_lock) { + bm_stat =cs_readb (cs5535au,ACC_BM1_STATUS ); + }if (bm_stat &EOP )snd_pcm_period_elapsed (cs5535au->capture_substream); }
sound/pci/cs5535audio/cs5535audio_pcm.c +4 -8
@@ -150,10 +150,9 @@ static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au, dma->substream = substream; dma->period_bytes = period_bytes; dma->periods = periods; -spin_lock_irq (&cs5535au->reg_lock); +guard (spinlock_irq)(&cs5535au->reg_lock); dma->ops->disable_dma (cs5535au); dma->ops->setup_prd (cs5535au, jmpprd_addr); -spin_unlock_irq (&cs5535au->reg_lock);return 0 ; }
@@ -276,9 +275,8 @@ static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd) {struct cs5535audio *cs5535au =snd_pcm_substream_chip (substream);struct cs5535audio_dma *dma = substream->runtime->private_data; -int err =0 ; -spin_lock (&cs5535au->reg_lock); +guard (spinlock)(&cs5535au->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_PAUSE_PUSH : dma->ops->pause_dma (cs5535au);
@@ -300,11 +298,9 @@ static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)break ;default :dev_err (cs5535au->card->dev,"unhandled trigger\n" ); - err = -EINVAL ; -break ; +return -EINVAL ; } -spin_unlock (&cs5535au->reg_lock); -return err; +return 0 ; } static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
Signature · 1 line
2.50.1
PATCH 22/61 ALSA: ctxfi: 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/pci/ctxfi/ctatc.c | 28 +++++++++++++--------------- sound/pci/ctxfi/ctvmem.c | 16 ++++++---------- 2 files changed, 19 insertions(+), 25 deletions(-)
sound/pci/ctxfi/ctatc.c +13 -15
@@ -295,10 +295,10 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) src = apcm->src;for (i =0 ; i < n_amixer; i++) { amixer = apcm->amixers[i]; -mutex_lock (&atc->atc_mutex); - amixer->ops->setup (amixer, &src->rsc, -INIT_VOL , atc->pcm[i+device*2 ]); -mutex_unlock (&atc->atc_mutex); + scoped_guard(mutex, &atc->atc_mutex) { + amixer->ops->setup (amixer, &src->rsc, +INIT_VOL , atc->pcm[i+device*2 ]); + } src = src->ops->next_interleave (src);if (!src) src = apcm->src;
@@ -874,7 +874,7 @@ spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm)return -ENOENT ; } -mutex_lock (&atc->atc_mutex); +guard (mutex)(&atc->atc_mutex); dao->ops->get_spos (dao, &status);if (((status >>24 ) &IEC958_AES3_CON_FS ) != iec958_con_fs) { status &= ~(IEC958_AES3_CON_FS <<24 );
@@ -884,7 +884,6 @@ spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm) }if ((rate != atc->pll_rate) && (32000 != rate)) err =atc_pll_init (atc, rate); -mutex_unlock (&atc->atc_mutex);return err; }
@@ -921,13 +920,13 @@ spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) src = apcm->src; }/* Connect to SPDIFOO */ -mutex_lock (&atc->atc_mutex); - dao = container_of(atc->daios[SPDIFOO], struct dao, daio); - amixer = apcm->amixers[0 ]; - dao->ops->set_left_input (dao, &amixer->rsc); - amixer = apcm->amixers[1 ]; - dao->ops->set_right_input (dao, &amixer->rsc); -mutex_unlock (&atc->atc_mutex); + scoped_guard(mutex, &atc->atc_mutex) { + dao = container_of(atc->daios[SPDIFOO], struct dao, daio); + amixer = apcm->amixers[0 ]; + dao->ops->set_left_input (dao, &amixer->rsc); + amixer = apcm->amixers[1 ]; + dao->ops->set_right_input (dao, &amixer->rsc); + }ct_timer_prepare (apcm->timer);
@@ -1115,7 +1114,7 @@ static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state)struct rsc *rscs[2 ] = {NULL };unsigned int spos =0 ; -mutex_lock (&atc->atc_mutex); +guard (mutex)(&atc->atc_mutex); dao = container_of(atc->daios[SPDIFOO], struct dao, daio); da_dsc.msr = state ?1 : atc->msr; da_dsc.passthru = state ?1 :0 ;
@@ -1133,7 +1132,6 @@ static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state) } dao->ops->set_spos (dao, spos); dao->ops->commit_write (dao); -mutex_unlock (&atc->atc_mutex);return err; }
sound/pci/ctxfi/ctvmem.c +6 -10
@@ -29,7 +29,7 @@static struct ct_vm_block *get_vm_block (struct ct_vm *vm,unsigned int size,struct ct_atc *atc) { -struct ct_vm_block *block =NULL , *entry; +struct ct_vm_block *block, *entry;struct list_head *pos; size =CT_PAGE_ALIGN (size);
@@ -39,26 +39,25 @@ get_vm_block(struct ct_vm *vm, unsigned int size, struct ct_atc *atc)return NULL ; } -mutex_lock (&vm->lock); +guard (mutex)(&vm->lock);list_for_each (pos, &vm->unused) { entry = list_entry(pos, struct ct_vm_block, list);if (entry->size >= size)break ;/* found a block that is big enough */ }if (pos == &vm->unused) - goto out; +return NULL ;if (entry->size == size) {/* Move the vm node from unused list to used list directly */ list_move (&entry->list, &vm->used); vm->size -= size; - block = entry; - goto out; +return entry; } block =kzalloc (sizeof (*block),GFP_KERNEL );if (!block) - goto out; +return NULL ; block->addr = entry->addr; block->size = size;
@@ -67,8 +66,6 @@ get_vm_block(struct ct_vm *vm, unsigned int size, struct ct_atc *atc) entry->size -= size; vm->size -= size; - out: -mutex_unlock (&vm->lock);return block; }
@@ -79,7 +76,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block) block->size =CT_PAGE_ALIGN (block->size); -mutex_lock (&vm->lock); +guard (mutex)(&vm->lock);list_del (&block->list); vm->size += block->size;
@@ -116,7 +113,6 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block) pos = pre; pre = pos->prev; } -mutex_unlock (&vm->lock); }/* Map host addr (kmalloced/vmalloced) to device logical addr. */
Signature · 1 line
2.50.1
PATCH 23/61 ALSA: ctxfi: 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/pci/ctxfi/ctamixer.c | 67 +++++++++++------------- sound/pci/ctxfi/ctdaio.c | 42 ++++++--------- sound/pci/ctxfi/cthw20k1.c | 39 +++----------- sound/pci/ctxfi/ctsrc.c | 101 +++++++++++++++---------------------- sound/pci/ctxfi/cttimer.c | 63 +++++++++-------------- 5 files changed, 115 insertions(+), 197 deletions(-)
sound/pci/ctxfi/ctamixer.c +30 -37
@@ -231,7 +231,6 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,int err, i;unsigned int idx;struct amixer *amixer; -unsigned long flags; *ramixer =NULL ;
@@ -243,15 +242,15 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,/* Check whether there are sufficient * amixer resources to meet request. */ err =0 ; -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i =0 ; i < desc->msr; i++) { - err =mgr_get_resource (&mgr->mgr,1 , &idx); -if (err) -break ; + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i =0 ; i < desc->msr; i++) { + err =mgr_get_resource (&mgr->mgr,1 , &idx); +if (err) +break ; - amixer->idx[i] = idx; + amixer->idx[i] = idx; + } } -spin_unlock_irqrestore (&mgr->mgr_lock, flags);if (err) {dev_err (mgr->card->dev,"Can't meet AMIXER resource request!\n" );
@@ -267,25 +266,23 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,return 0 ; error: -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i--; i >=0 ; i--) -mgr_put_resource (&mgr->mgr,1 , amixer->idx[i]); + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i--; i >=0 ; i--) +mgr_put_resource (&mgr->mgr,1 , amixer->idx[i]); + } -spin_unlock_irqrestore (&mgr->mgr_lock, flags);kfree (amixer);return err; }static int put_amixer_rsc (struct amixer_mgr *mgr,struct amixer *amixer) { -unsigned long flags;int i; -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i =0 ; i < amixer->rsc.msr; i++) -mgr_put_resource (&mgr->mgr,1 , amixer->idx[i]); - -spin_unlock_irqrestore (&mgr->mgr_lock, flags); + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i =0 ; i < amixer->rsc.msr; i++) +mgr_put_resource (&mgr->mgr,1 , amixer->idx[i]); + }amixer_rsc_uninit (amixer);kfree (amixer);
@@ -387,7 +384,6 @@ static int get_sum_rsc(struct sum_mgr *mgr,int err, i;unsigned int idx;struct sum *sum; -unsigned long flags; *rsum =NULL ;
@@ -398,15 +394,15 @@ static int get_sum_rsc(struct sum_mgr *mgr,/* Check whether there are sufficient sum resources to meet request. */ err =0 ; -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i =0 ; i < desc->msr; i++) { - err =mgr_get_resource (&mgr->mgr,1 , &idx); -if (err) -break ; + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i =0 ; i < desc->msr; i++) { + err =mgr_get_resource (&mgr->mgr,1 , &idx); +if (err) +break ; - sum->idx[i] = idx; + sum->idx[i] = idx; + } } -spin_unlock_irqrestore (&mgr->mgr_lock, flags);if (err) {dev_err (mgr->card->dev,"Can't meet SUM resource request!\n" );
@@ -422,25 +418,22 @@ static int get_sum_rsc(struct sum_mgr *mgr,return 0 ; error: -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i--; i >=0 ; i--) -mgr_put_resource (&mgr->mgr,1 , sum->idx[i]); - -spin_unlock_irqrestore (&mgr->mgr_lock, flags); + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i--; i >=0 ; i--) +mgr_put_resource (&mgr->mgr,1 , sum->idx[i]); + }kfree (sum);return err; }static int put_sum_rsc (struct sum_mgr *mgr,struct sum *sum) { -unsigned long flags;int i; -spin_lock_irqsave (&mgr->mgr_lock, flags); -for (i =0 ; i < sum->rsc.msr; i++) -mgr_put_resource (&mgr->mgr,1 , sum->idx[i]); - -spin_unlock_irqrestore (&mgr->mgr_lock, flags); + scoped_guard(spinlock_irqsave, &mgr->mgr_lock) { +for (i =0 ; i < sum->rsc.msr; i++) +mgr_put_resource (&mgr->mgr,1 , sum->idx[i]); + }sum_rsc_uninit (sum);kfree (sum);
sound/pci/ctxfi/ctdaio.c +15 -27
97 lines not on this page · raw message
sound/pci/ctxfi/cthw20k1.c +6 -33
@@ -2091,57 +2091,30 @@ static int hw_resume(struct hw *hw, struct card_conf *info)static u32 hw_read_20kx (struct hw *hw,u32 reg) { -u32 value; -unsigned long flags; - -spin_lock_irqsave ( - &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags); + guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_20k1_lock);outl (reg, hw->io_base +0x0 ); - value =inl (hw->io_base +0x4 ); -spin_unlock_irqrestore ( - &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags); - -return value; +return inl (hw->io_base +0x4 ); }static void hw_write_20kx (struct hw *hw,u32 reg,u32 data) { -unsigned long flags; - -spin_lock_irqsave ( - &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags); + guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_20k1_lock);outl (reg, hw->io_base +0x0 );outl (data, hw->io_base +0x4 ); -spin_unlock_irqrestore ( - &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags); - }static u32 hw_read_pci (struct hw *hw,u32 reg) { -u32 value; -unsigned long flags; - -spin_lock_irqsave ( - &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags); + guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_pci_lock);outl (reg, hw->io_base +0x10 ); - value =inl (hw->io_base +0x14 ); -spin_unlock_irqrestore ( - &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags); - -return value; +return inl (hw->io_base +0x14 ); }static void hw_write_pci (struct hw *hw,u32 reg,u32 data) { -unsigned long flags; - -spin_lock_irqsave ( - &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags); + guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_pci_lock);outl (reg, hw->io_base +0x10 );outl (data, hw->io_base +0x14 ); -spin_unlock_irqrestore ( - &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags); }static const struct hw ct20k1_preset = {
sound/pci/ctxfi/ctsrc.c +41 -60
181 lines not on this page · raw message
sound/pci/ctxfi/cttimer.c +23 -40
159 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 24/61 ALSA: echoaudio: 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/pci/echoaudio/echoaudio.c | 36 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
sound/pci/echoaudio/echoaudio.c +14 -22
@@ -237,7 +237,7 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,struct snd_interval fixed;int err; -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);if (chip->can_set_rate) { err =0 ;
@@ -247,7 +247,6 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params, err =snd_interval_refine (rate, &fixed); } -mutex_unlock (&chip->mode_mutex);return err; }
@@ -415,7 +414,7 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream)int err, max_channels; max_channels =num_digital_busses_in (chip) - substream->number; -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);if (chip->digital_mode ==DIGITAL_MODE_ADAT ) err =pcm_open (substream, max_channels);else /* If the card has ADAT, subtract the 6 channels
@@ -424,24 +423,22 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream) err =pcm_open (substream, max_channels -ECHOCARD_HAS_ADAT );if (err <0 ) - goto din_exit; +return err; err =snd_pcm_hw_rule_add (substream->runtime,0 ,SNDRV_PCM_HW_PARAM_CHANNELS , hw_rule_capture_channels_by_format,NULL ,SNDRV_PCM_HW_PARAM_FORMAT ,-1 );if (err <0 ) - goto din_exit; +return err; err =snd_pcm_hw_rule_add (substream->runtime,0 ,SNDRV_PCM_HW_PARAM_FORMAT , hw_rule_capture_format_by_channels,NULL ,SNDRV_PCM_HW_PARAM_CHANNELS ,-1 );if (err <0 ) - goto din_exit; +return err; -din_exit: -mutex_unlock (&chip->mode_mutex); -return err; +return 0 ; }
@@ -454,7 +451,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)int err, max_channels; max_channels =num_digital_busses_out (chip) - substream->number; -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);if (chip->digital_mode ==DIGITAL_MODE_ADAT ) err =pcm_open (substream, max_channels);else /* If the card has ADAT, subtract the 6 channels
@@ -463,7 +460,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream) err =pcm_open (substream, max_channels -ECHOCARD_HAS_ADAT );if (err <0 ) - goto dout_exit; +return err; err = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
@@ -471,18 +468,16 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)NULL ,SNDRV_PCM_HW_PARAM_FORMAT , -1);if (err <0 ) - goto dout_exit; +return err; err =snd_pcm_hw_rule_add (substream->runtime,0 ,SNDRV_PCM_HW_PARAM_FORMAT , hw_rule_playback_format_by_channels,NULL ,SNDRV_PCM_HW_PARAM_CHANNELS ,-1 );if (err <0 ) - goto dout_exit; +return err; -dout_exit: -mutex_unlock (&chip->mode_mutex); - return err; + return 0; }#endif /* !ECHOCARD_HAS_VMIXER */
@@ -499,7 +494,7 @@ static int pcm_close(struct snd_pcm_substream *substream)* freed by its callback */ -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);dev_dbg (chip->card->dev,"pcm_open opencount=%d can_set_rate=%d, rate_set=%d" , chip->opencount, chip->can_set_rate, chip->rate_set);
@@ -516,7 +511,6 @@ static int pcm_close(struct snd_pcm_substream *substream)break ; } -mutex_unlock (&chip->mode_mutex);return 0 ; }
@@ -1440,7 +1434,7 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,if (dmode != chip->digital_mode) {/* mode_mutex is required to make this operation atomic wrt pcm_digital_*_open() and set_input_clock() functions. */ -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);/* Do not allow the user to change the digital mode when a pcm device is open because it also changes the number of channels
@@ -1460,7 +1454,6 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,if (changed >=0 ) changed =1 ;/* No errors */ } -mutex_unlock (&chip->mode_mutex); }return changed; }
@@ -1573,13 +1566,12 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,return -EINVAL ; dclock = chip->clock_source_list[eclock];if (chip->input_clock != dclock) { -mutex_lock (&chip->mode_mutex); +guard (mutex)(&chip->mode_mutex);spin_lock_irq (&chip->lock); changed =set_input_clock (chip, dclock);if (!changed) changed =1 ;/* no errors */ spin_unlock_irq (&chip->lock); -mutex_unlock (&chip->mode_mutex); }if (changed <0 )
Signature · 1 line
2.50.1
PATCH 25/61 ALSA: echoaudio: 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/pci/echoaudio/echoaudio.c | 92 ++++++++++++------------------ sound/pci/echoaudio/echoaudio_3g.c | 6 +- sound/pci/echoaudio/gina24_dsp.c | 3 +- sound/pci/echoaudio/layla24_dsp.c | 6 +- sound/pci/echoaudio/midi.c | 41 ++++++------- sound/pci/echoaudio/mona_dsp.c | 3 +- 6 files changed, 62 insertions(+), 89 deletions(-)
sound/pci/echoaudio/echoaudio.c +35 -57
@@ -531,22 +531,21 @@ static int init_engine(struct snd_pcm_substream *substream,/* Sets up che hardware. If it's already initialized, reset and * redo with the new parameters */ -spin_lock_irq (&chip->lock); -if (pipe->index >=0 ) { -dev_dbg (chip->card->dev,"hwp_ie free(%d)\n" , pipe->index); - err =free_pipes (chip, pipe); -snd_BUG_ON (err); - chip->substream[pipe->index] =NULL ; - } + scoped_guard(spinlock_irq, &chip->lock) { +if (pipe->index >=0 ) { +dev_dbg (chip->card->dev,"hwp_ie free(%d)\n" , pipe->index); + err =free_pipes (chip, pipe); +snd_BUG_ON (err); + chip->substream[pipe->index] =NULL ; + } - err =allocate_pipes (chip, pipe, pipe_index, interleave); -if (err <0 ) { -spin_unlock_irq (&chip->lock); -dev_err (chip->card->dev,"allocate_pipes(%d) err=%d\n" , - pipe_index, err); -return err; + err =allocate_pipes (chip, pipe, pipe_index, interleave); +if (err <0 ) { +dev_err (chip->card->dev,"allocate_pipes(%d) err=%d\n" , + pipe_index, err); +return err; + } } -spin_unlock_irq (&chip->lock);dev_dbg (chip->card->dev,"allocate_pipes()=%d\n" , pipe_index); dev_dbg(chip->card->dev,
@@ -594,9 +593,8 @@ static int init_engine(struct snd_pcm_substream *substream,smp_wmb (); chip->substream[pipe_index] = substream; chip->rate_set =1 ; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_sample_rate (chip, hw_params->rate_num / hw_params->rate_den); -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -658,14 +656,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) chip =snd_pcm_substream_chip (substream); pipe = (struct audiopipe *) substream->runtime->private_data; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);if (pipe->index >=0 ) {dev_dbg (chip->card->dev,"pcm_hw_free(%d)\n" , pipe->index);free_pipes (chip, pipe); chip->substream[pipe->index] =NULL ; pipe->index =-1 ; } -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -715,15 +712,12 @@ static int pcm_prepare(struct snd_pcm_substream *substream)* exclusive control */ -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); -if (snd_BUG_ON (!is_pipe_allocated (chip, pipe_index))) { -spin_unlock_irq (&chip->lock); +if (snd_BUG_ON (!is_pipe_allocated (chip, pipe_index)))return -EINVAL ; - }set_audio_format (chip, pipe_index, &format); -spin_unlock_irq (&chip->lock);return 0 ; }
@@ -747,7 +741,7 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) } } -spin_lock (&chip->lock); +guard (spinlock)(&chip->lock);switch (cmd) {case SNDRV_PCM_TRIGGER_RESUME :case SNDRV_PCM_TRIGGER_START :
@@ -795,7 +789,6 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)default : err = -EINVAL ; } -spin_unlock (&chip->lock);return err; }
@@ -1012,7 +1005,7 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol, changed =0 ; chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);for (c =0 ; c <num_busses_out (chip); c++) { gain = ucontrol->value.integer.value[c];/* Ignore out of range values */
@@ -1025,7 +1018,6 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol, }if (changed)update_output_line_level (chip); -spin_unlock_irq (&chip->lock);return changed; }
@@ -1093,7 +1085,7 @@ static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol, changed =0 ; chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);for (c =0 ; c <num_analog_busses_in (chip); c++) { gain = ucontrol->value.integer.value[c];/* Ignore out of range values */
@@ -1106,7 +1098,6 @@ static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol, }if (changed)update_input_line_level (chip); -spin_unlock_irq (&chip->lock);return changed; }
@@ -1162,7 +1153,7 @@ static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol, changed =0 ; chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);for (c =0 ; c <num_analog_busses_out (chip); c++) {if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) { set_nominal_level(chip, c,
@@ -1172,7 +1163,6 @@ static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol, }if (changed)update_output_line_level (chip); -spin_unlock_irq (&chip->lock);return changed; }
@@ -1225,7 +1215,7 @@ static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol, changed =0 ; chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);for (c =0 ; c <num_analog_busses_in (chip); c++) {if (chip->nominal_level[bx_analog_in (chip) + c] != ucontrol->value.integer.value[c]) {
@@ -1238,7 +1228,6 @@ static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol,update_output_line_level (chip);/* "Output" is not a mistake * here. */ -spin_unlock_irq (&chip->lock);return changed; }
@@ -1298,10 +1287,9 @@ static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol,if (gain <ECHOGAIN_MINOUT || gain >ECHOGAIN_MAXOUT )return -EINVAL ;if (chip->monitor_gain[out][in] != gain) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_monitor_gain (chip, out, in, gain);update_output_line_level (chip); -spin_unlock_irq (&chip->lock); changed =1 ; }return changed;
@@ -1361,10 +1349,9 @@ static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol,if (gain <ECHOGAIN_MINOUT || gain >ECHOGAIN_MAXOUT )return -EINVAL ;if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0 ]) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_vmixer_gain (chip, out, vch, ucontrol->value.integer.value[0 ]);update_vmixer_level (chip); -spin_unlock_irq (&chip->lock); changed =1 ; }return changed;
@@ -1500,9 +1487,8 @@ static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol, chip =snd_kcontrol_chip (kcontrol); mode = !!ucontrol->value.enumerated.item[0 ];if (mode != chip->professional_spdif) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_professional_spdif (chip, mode); -spin_unlock_irq (&chip->lock);return 1 ; }return 0 ;
@@ -1567,11 +1553,10 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol, dclock = chip->clock_source_list[eclock];if (chip->input_clock != dclock) {guard (mutex)(&chip->mode_mutex); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); changed =set_input_clock (chip, dclock);if (!changed) changed =1 ;/* no errors */ -spin_unlock_irq (&chip->lock); }if (changed <0 )
@@ -1615,9 +1600,8 @@ static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol, power = !!ucontrol->value.integer.value[0 ];if (chip->phantom_power != power) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); changed =set_phantom_power (chip, power); -spin_unlock_irq (&chip->lock);if (changed ==0 ) changed =1 ;/* no errors */ }
@@ -1658,9 +1642,8 @@ static int snd_echo_automute_put(struct snd_kcontrol *kcontrol, automute = !!ucontrol->value.integer.value[0 ];if (chip->digital_in_automute != automute) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock); changed =set_input_auto_mute (chip, automute); -spin_unlock_irq (&chip->lock);if (changed ==0 ) changed =1 ;/* no errors */ }
@@ -1688,9 +1671,8 @@ static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol,struct echoaudio *chip; chip =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_meters_on (chip, ucontrol->value.integer.value[0 ]); -spin_unlock_irq (&chip->lock);return 1 ; }
@@ -2135,17 +2117,13 @@ static int snd_echo_suspend(struct device *dev)if (chip->midi_out)snd_echo_midi_output_trigger (chip->midi_out,0 );#endif -spin_lock_irq (&chip->lock); -if (wait_handshake (chip)) { -spin_unlock_irq (&chip->lock); -return -EIO ; + scoped_guard(spinlock_irq, &chip->lock) { +if (wait_handshake (chip)) +return -EIO ; +clear_handshake (chip); +if (send_vector (chip,DSP_VC_GO_COMATOSE ) <0 ) +return -EIO ; } -clear_handshake (chip); -if (send_vector (chip,DSP_VC_GO_COMATOSE ) <0 ) { -spin_unlock_irq (&chip->lock); -return -EIO ; - } -spin_unlock_irq (&chip->lock); chip->dsp_code =NULL ;free_irq (chip->irq, chip);
sound/pci/echoaudio/echoaudio_3g.c +2 -4
@@ -119,7 +119,7 @@ static int set_digital_mode(struct echoaudio *chip, u8 mode)* updated by the DSP comm object. */ if (err >=0 && previous_mode != mode && (previous_mode ==DIGITAL_MODE_ADAT || mode ==DIGITAL_MODE_ADAT )) { -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);for (o =0 ; o <num_busses_out (chip); o++)for (i =0 ; i <num_busses_in (chip); i++) set_monitor_gain(chip, o, i,
@@ -134,7 +134,6 @@ static int set_digital_mode(struct echoaudio *chip, u8 mode)for (o =0 ; o <num_busses_out (chip); o++)set_output_gain (chip, o, chip->output_gain[o]);update_output_line_level (chip); -spin_unlock_irq (&chip->lock); }return err;
@@ -396,7 +395,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)return -EINVAL ; } -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);if (incompatible_clock) { chip->sample_rate =48000 ;
@@ -422,7 +421,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode) } err =write_control_reg (chip, control_reg,get_frq_reg (chip),1 ); -spin_unlock_irq (&chip->lock);if (err <0 )return err; chip->digital_mode = mode;
sound/pci/echoaudio/gina24_dsp.c +1 -2
@@ -305,7 +305,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)return -EINVAL ; } -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);if (incompatible_clock) {/* Switch to 48KHz, internal */ chip->sample_rate =48000 ;
@@ -336,7 +336,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode) } err =write_control_reg (chip, control_reg, true); -spin_unlock_irq (&chip->lock);if (err <0 )return err; chip->digital_mode = mode;
sound/pci/echoaudio/layla24_dsp.c +2 -4
@@ -358,16 +358,15 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)if (incompatible_clock) {/* Switch to 48KHz, internal */ chip->sample_rate =48000 ; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);set_input_clock (chip,ECHO_CLOCK_INTERNAL ); -spin_unlock_irq (&chip->lock); }/* switch_asic() can sleep */ if (switch_asic (chip, asic) <0 )return -EIO ; -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);/* Tweak the control register */ control_reg =le32_to_cpu (chip->comm_page->control_register);
@@ -387,7 +386,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode) } err =write_control_reg (chip, control_reg, true); -spin_unlock_irq (&chip->lock);if (err <0 )return err; chip->digital_mode = mode;
sound/pci/echoaudio/midi.c +21 -20
76 lines not on this page · raw message
sound/pci/echoaudio/mona_dsp.c +1 -2
@@ -381,7 +381,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)return -EINVAL ; } -spin_lock_irq (&chip->lock); +guard (spinlock_irq)(&chip->lock);if (incompatible_clock) {/* Switch to 48KHz, internal */ chip->sample_rate =48000 ;
@@ -413,7 +413,6 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode) } err =write_control_reg (chip, control_reg, false); -spin_unlock_irq (&chip->lock);if (err <0 )return err; chip->digital_mode = mode;
Signature · 1 line
2.50.1
PATCH 26/61 ALSA: emu10k1: 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/pci/emu10k1/emufx.c | 35 +++++++++++++++-------------------- sound/pci/emu10k1/memory.c | 20 +++++--------------- 2 files changed, 20 insertions(+), 35 deletions(-)
sound/pci/emu10k1/emufx.c +15 -20
@@ -1026,12 +1026,12 @@ static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,struct snd_emu10k1_fx8010_code *icode, bool in_kernel) { - int err = 0; + int err; -mutex_lock (&emu->fx8010.lock); +guard (mutex)(&emu->fx8010.lock); err =snd_emu10k1_verify_controls (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err;strscpy (emu->fx8010.name, icode->name,sizeof (emu->fx8010.name));/* stop FX processor - this may be dangerous, but it's better to miss some samples than generate wrong ones - [jk] */
@@ -1042,27 +1042,25 @@ static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,/* ok, do the main job */ err =snd_emu10k1_del_controls (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err; err =snd_emu10k1_gpr_poke (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err; err =snd_emu10k1_tram_poke (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err; err =snd_emu10k1_code_poke (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err; err =snd_emu10k1_add_controls (emu, icode, in_kernel);if (err <0 ) - goto __error; +return err;/* start FX processor when the DSP code is updated */ if (emu->audigy)snd_emu10k1_ptr_write (emu,A_DBG ,0 , emu->fx8010.dbg);else snd_emu10k1_ptr_write (emu,DBG ,0 , emu->fx8010.dbg); - __error: -mutex_unlock (&emu->fx8010.lock); -return err; +return 0 ; } static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu,
@@ -1070,7 +1068,7 @@ static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu, {int err; -mutex_lock (&emu->fx8010.lock); +guard (mutex)(&emu->fx8010.lock);strscpy (icode->name, emu->fx8010.name,sizeof (icode->name));/* ok, do the main job */ err =snd_emu10k1_gpr_peek (emu, icode);
@@ -1080,7 +1078,6 @@ static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu, err =snd_emu10k1_code_peek (emu, icode);if (err >=0 ) err =snd_emu10k1_list_controls (emu, icode); -mutex_unlock (&emu->fx8010.lock);return err; }
@@ -1098,7 +1095,7 @@ static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu,if (ipcm->channels >32 )return -EINVAL ; pcm = &emu->fx8010.pcm[ipcm->substream]; -mutex_lock (&emu->fx8010.lock); +guard (mutex)(&emu->fx8010.lock);spin_lock_irq (&emu->reg_lock);if (pcm->opened) { err = -EBUSY ;
@@ -1128,7 +1125,6 @@ static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu, } __error:spin_unlock_irq (&emu->reg_lock); -mutex_unlock (&emu->fx8010.lock);return err; }
@@ -1144,7 +1140,7 @@ static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu, ipcm->substream =array_index_nospec (ipcm->substream,EMU10K1_FX8010_PCM_COUNT ); pcm = &emu->fx8010.pcm[ipcm->substream]; -mutex_lock (&emu->fx8010.lock); +guard (mutex)(&emu->fx8010.lock);spin_lock_irq (&emu->reg_lock); ipcm->channels = pcm->channels; ipcm->tram_start = pcm->tram_start;
@@ -1160,7 +1156,6 @@ static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu, ipcm->res1 = ipcm->res2 =0 ; ipcm->pad =0 ;spin_unlock_irq (&emu->reg_lock); -mutex_unlock (&emu->fx8010.lock);return err; }
@@ -2547,9 +2542,9 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, unreturn -EPERM ;if (get_user (addr, (unsigned int __user *)argp))return -EFAULT ; -mutex_lock (&emu->fx8010.lock); - res =snd_emu10k1_fx8010_tram_setup (emu, addr); -mutex_unlock (&emu->fx8010.lock); + scoped_guard(mutex, &emu->fx8010.lock) { + res =snd_emu10k1_fx8010_tram_setup (emu, addr); + }return res;case SNDRV_EMU10K1_IOCTL_STOP :if (!capable (CAP_SYS_ADMIN ))
sound/pci/emu10k1/memory.c +5 -15
@@ -315,12 +315,10 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substif (snd_BUG_ON (!hdr))return NULL ; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex); blk =search_empty (emu, runtime->dma_bytes); -if (blk ==NULL ) { -mutex_unlock (&hdr->block_mutex); +if (blk ==NULL )return NULL ; - }/* fill buffer addresses but pointers are not stored so that * snd_free_pci_page() is not called in synth_free() */
@@ -335,7 +333,6 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substif (!is_valid_page (emu, addr)) {dev_err_ratelimited (emu->card->dev,"emu: failure page = %d\n" , idx); -mutex_unlock (&hdr->block_mutex);return NULL ; } emu->page_addr_table[page] = addr;
@@ -347,10 +344,8 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst err =snd_emu10k1_memblk_map (emu, blk);if (err <0 ) {__snd_util_mem_free (hdr, (struct snd_util_memblk *)blk); -mutex_unlock (&hdr->block_mutex);return NULL ; } -mutex_unlock (&hdr->block_mutex);return (struct snd_util_memblk *)blk; }
@@ -407,19 +402,15 @@ snd_emu10k1_synth_alloc(struct snd_emu10k1 *hw, unsigned int size)struct snd_emu10k1_memblk *blk;struct snd_util_memhdr *hdr = hw->memhdr; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex); blk = (struct snd_emu10k1_memblk *)__snd_util_mem_alloc (hdr, size); -if (blk ==NULL ) { -mutex_unlock (&hdr->block_mutex); +if (blk ==NULL )return NULL ; - }if (synth_alloc_pages (hw, blk)) {__snd_util_mem_free (hdr, (struct snd_util_memblk *)blk); -mutex_unlock (&hdr->block_mutex);return NULL ; }snd_emu10k1_memblk_map (hw, blk); -mutex_unlock (&hdr->block_mutex);return (struct snd_util_memblk *)blk; }
@@ -435,14 +426,13 @@ snd_emu10k1_synth_free(struct snd_emu10k1 *emu, struct snd_util_memblk *memblk)struct snd_emu10k1_memblk *blk = (struct snd_emu10k1_memblk *)memblk;unsigned long flags; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex);spin_lock_irqsave (&emu->memblk_lock, flags);if (blk->mapped_page >=0 )unmap_memblk (emu, blk);spin_unlock_irqrestore (&emu->memblk_lock, flags);synth_free_pages (emu, blk);__snd_util_mem_free (hdr, memblk); -mutex_unlock (&hdr->block_mutex);return 0 ; }
Signature · 1 line
2.50.1
PATCH 27/61 ALSA: emu10k1: Use guard() for emu1010 FPGA locking
In reply to Takashi IwaiThe snd_emu1010_fpga_lock() and _unlock() call pairs can be simplified gracefully with the introduction of guard().
Only code refactoring, and no functional changes.
--- include/sound/emu10k1.h | 3 +-- sound/pci/emu10k1/emu10k1_main.c | 15 +++++---------- sound/pci/emu10k1/emumixer.c | 15 ++++++--------- sound/pci/emu10k1/emuproc.c | 8 ++------ sound/pci/emu10k1/io.c | 3 +-- 5 files changed, 15 insertions(+), 29 deletions(-)
include/sound/emu10k1.h +1 -2
@@ -1842,8 +1842,7 @@ unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, unsigned int reg,void snd_emu10k1_ptr20_write (struct snd_emu10k1 *emu,unsigned int reg,unsigned int chn,unsigned int data);int snd_emu10k1_spi_write (struct snd_emu10k1 * emu,unsigned int data);int snd_emu10k1_i2c_write (struct snd_emu10k1 *emu,u32 reg,u32 value); -static inline void snd_emu1010_fpga_lock (struct snd_emu10k1 *emu) {mutex_lock (&emu->emu1010.lock); }; -static inline void snd_emu1010_fpga_unlock (struct snd_emu10k1 *emu) {mutex_unlock (&emu->emu1010.lock); }; +DEFINE_GUARD(snd_emu1010_fpga_lock, struct snd_emu10k1 *, mutex_lock(&(_T)->emu1010.lock), mutex_unlock(&(_T)->emu1010.lock))void snd_emu1010_fpga_write_lock (struct snd_emu10k1 *emu,u32 reg,u32 value);void snd_emu1010_fpga_write (struct snd_emu10k1 *emu,u32 reg,u32 value);void snd_emu1010_fpga_read (struct snd_emu10k1 *emu,u32 reg,u32 *value);
sound/pci/emu10k1/emu10k1_main.c +5 -10
@@ -768,7 +768,7 @@ static void emu1010_work(struct work_struct *work)return ;#endif -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);snd_emu1010_fpga_read (emu,EMU_HANA_IRQ_STATUS , &sts);
@@ -779,8 +779,6 @@ static void emu1010_work(struct work_struct *work)if (sts &EMU_HANA_IRQ_WCLK_CHANGED )emu1010_clock_event (emu); - -snd_emu1010_fpga_unlock (emu); }static void emu1010_interrupt (struct snd_emu10k1 *emu)
@@ -814,13 +812,13 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)* Proper init follows in snd_emu10k1_init(). */ outl (HCFG_LOCKSOUNDCACHE |HCFG_LOCKTANKCACHE_MASK , emu->port +HCFG ); -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);dev_info (emu->card->dev,"emu1010: Loading Hana Firmware\n" ); err =snd_emu1010_load_firmware (emu,0 , &emu->firmware);if (err <0 ) {dev_info (emu->card->dev,"emu1010: Loading Firmware failed\n" ); - goto fail; +return err; }/* ID, should read & 0x7f = 0x55 when FPGA programmed. */
@@ -830,8 +828,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)dev_info (emu->card->dev,"emu1010: Loading Hana Firmware file failed, reg = 0x%x\n" , reg); - err = -ENODEV ; - goto fail; +return -ENODEV ; }dev_info (emu->card->dev,"emu1010: Hana Firmware loaded\n" );
@@ -891,9 +888,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)// so it is safe to simply enable the outputs. snd_emu1010_fpga_write (emu,EMU_HANA_UNMUTE ,EMU_UNMUTE ); -fail: -snd_emu1010_fpga_unlock (emu); -return err; +return 0 ; }/* * Create the EMU10K1 instance
sound/pci/emu10k1/emumixer.c +6 -9
@@ -662,9 +662,8 @@ static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol, change = (emu->emu1010.output_source[channel] != val);if (change) { emu->emu1010.output_source[channel] = val; -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);snd_emu1010_output_source_apply (emu, channel, val); -snd_emu1010_fpga_unlock (emu); }return change; }
@@ -708,9 +707,8 @@ static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol, change = (emu->emu1010.input_source[channel] != val);if (change) { emu->emu1010.input_source[channel] = val; -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);snd_emu1010_input_source_apply (emu, channel, val); -snd_emu1010_fpga_unlock (emu); }return change; }
@@ -985,7 +983,7 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol, val = ucontrol->value.enumerated.item[0 ] ;if (val >= emu_ci->num)return -EINVAL ; -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);spin_lock_irq (&emu->reg_lock); change = (emu->emu1010.clock_source != val);if (change) {
@@ -1002,7 +1000,6 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol, }else {spin_unlock_irq (&emu->reg_lock); } -snd_emu1010_fpga_unlock (emu);return change; }
@@ -2330,9 +2327,9 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,for (i =0 ; i < emu_ri->n_outs; i++) emu->emu1010.output_source[i] =emu1010_map_source (emu_ri, emu_ri->out_dflts[i]); -snd_emu1010_fpga_lock (emu); -snd_emu1010_apply_sources (emu); -snd_emu1010_fpga_unlock (emu); + scoped_guard(snd_emu1010_fpga_lock, emu) { +snd_emu1010_apply_sources (emu); + } kctl = emu->ctl_clock_source =snd_ctl_new1 (&snd_emu1010_clock_source, emu); err =snd_ctl_add (card, kctl);
sound/pci/emu10k1/emuproc.c +2 -6
@@ -166,7 +166,7 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,u32 value2;if (emu->card_capabilities->emu_model) { -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);// This represents the S/PDIF lock status on 0404b, which is // kinda weird and unhelpful, because monitoring it via IRQ is
@@ -200,8 +200,6 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,snd_iprintf (buffer,"\nS/PDIF mode: %s%s\n" , value &EMU_HANA_SPDIF_MODE_RX_PRO ?"professional" :"consumer" , value &EMU_HANA_SPDIF_MODE_RX_NOCOPY ?", no copy" :"" ); - -snd_emu1010_fpga_unlock (emu); }else {snd_emu10k1_proc_spdif_status (emu, buffer,"CD-ROM S/PDIF In" ,CDCS ,CDSRCS );snd_emu10k1_proc_spdif_status (emu, buffer,"Optical or Coax S/PDIF In" ,GPSCS ,GPSRCS );
@@ -464,7 +462,7 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,u32 value;int i; -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);snd_iprintf (buffer,"EMU1010 Registers:\n\n" );
@@ -504,8 +502,6 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,snd_emu_proc_emu1010_link_read (emu, buffer,0x701 ); } } - -snd_emu1010_fpga_unlock (emu); } static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
sound/pci/emu10k1/io.c +1 -2
@@ -297,9 +297,8 @@ void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value)void snd_emu1010_fpga_write_lock (struct snd_emu10k1 *emu,u32 reg,u32 value) { -snd_emu1010_fpga_lock (emu); +guard (snd_emu1010_fpga_lock)(emu);snd_emu1010_fpga_write_locked (emu, reg, value); -snd_emu1010_fpga_unlock (emu); }void snd_emu1010_fpga_read (struct snd_emu10k1 *emu,u32 reg,u32 *value)
Signature · 1 line
2.50.1
PATCH 28/61 ALSA: emu10k1: 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/pci/emu10k1/emu10k1_main.c | 12 +-- sound/pci/emu10k1/emu10k1_synth.c | 11 +- sound/pci/emu10k1/emufx.c | 46 +++----- sound/pci/emu10k1/emumixer.c | 56 ++++------ sound/pci/emu10k1/emumpu401.c | 173 +++++++++++++----------------- sound/pci/emu10k1/emupcm.c | 58 ++++------ sound/pci/emu10k1/emuproc.c | 11 +- sound/pci/emu10k1/io.c | 120 ++++++--------------- sound/pci/emu10k1/memory.c | 14 +-- sound/pci/emu10k1/p16v.c | 8 +- sound/pci/emu10k1/voice.c | 8 +- 11 files changed, 192 insertions(+), 325 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +6 -6
@@ -745,12 +745,12 @@ static void emu1010_clock_event(struct snd_emu10k1 *emu) {struct snd_ctl_elem_id id; -spin_lock_irq (&emu->reg_lock); -// This is the only thing that can actually happen. - emu->emu1010.clock_source = emu->emu1010.clock_fallback; - emu->emu1010.wclock =1 - emu->emu1010.clock_source; -snd_emu1010_update_clock (emu); -spin_unlock_irq (&emu->reg_lock); + scoped_guard(spinlock_irq, &emu->reg_lock) { +// This is the only thing that can actually happen. + emu->emu1010.clock_source = emu->emu1010.clock_fallback; + emu->emu1010.wclock =1 - emu->emu1010.clock_source; +snd_emu1010_update_clock (emu); + }snd_ctl_build_ioff (&id, emu->ctl_clock_source,0 );snd_ctl_notify (emu->card,SNDRV_CTL_EVENT_MASK_VALUE , &id); }
sound/pci/emu10k1/emu10k1_synth.c +5 -6
@@ -55,10 +55,9 @@ static int snd_emu10k1_synth_probe(struct device *_dev)return -ENOMEM ; } -spin_lock_irq (&hw->voice_lock); +guard (spinlock_irq)(&hw->voice_lock); hw->synth = emux; hw->get_synth_voice = snd_emu10k1_synth_get_voice; -spin_unlock_irq (&hw->voice_lock); dev->driver_data = emux;
@@ -77,10 +76,10 @@ static int snd_emu10k1_synth_remove(struct device *_dev) emux = dev->driver_data; hw = emux->hw; -spin_lock_irq (&hw->voice_lock); - hw->synth =NULL ; - hw->get_synth_voice =NULL ; -spin_unlock_irq (&hw->voice_lock); + scoped_guard(spinlock_irq, &hw->voice_lock) { + hw->synth =NULL ; + hw->get_synth_voice =NULL ; + }snd_emux_free (emux);return 0 ;
sound/pci/emu10k1/emufx.c +16 -30
127 lines not on this page · raw message
sound/pci/emu10k1/emumixer.c +22 -34
176 lines not on this page · raw message
sound/pci/emu10k1/emumpu401.c +77 -96
241 lines not on this page · raw message
sound/pci/emu10k1/emupcm.c +20 -38
179 lines not on this page · raw message
sound/pci/emu10k1/emuproc.c +4 -7
@@ -537,15 +537,13 @@ static unsigned int snd_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, unsigned int chn) { -unsigned int regptr, val; +unsigned int regptr; regptr = (reg <<16 ) | chn; -spin_lock_irq (&emu->emu_lock); +guard (spinlock_irq)(&emu->emu_lock);outl (regptr, emu->port + iobase +PTR ); - val =inl (emu->port + iobase +DATA ); -spin_unlock_irq (&emu->emu_lock); -return val; +return inl (emu->port + iobase +DATA ); } static void snd_ptr_write(struct snd_emu10k1 *emu,
@@ -558,10 +556,9 @@ static void snd_ptr_write(struct snd_emu10k1 *emu, regptr = (reg <<16 ) | chn; -spin_lock_irq (&emu->emu_lock); +guard (spinlock_irq)(&emu->emu_lock);outl (regptr, emu->port + iobase +PTR );outl (data, emu->port + iobase +DATA ); -spin_unlock_irq (&emu->emu_lock); }
sound/pci/emu10k1/io.c +33 -87
382 lines not on this page · raw message
sound/pci/emu10k1/memory.c +5 -9
@@ -261,14 +261,12 @@ int snd_emu10k1_memblk_map(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *bint size;struct list_head *p, *nextp;struct snd_emu10k1_memblk *deleted; -unsigned long flags; -spin_lock_irqsave (&emu->memblk_lock, flags); +guard (spinlock_irqsave)(&emu->memblk_lock);if (blk->mapped_page >=0 ) {/* update order link */ list_move_tail (&blk->mapped_order_link, &emu->mapped_order_link_head); -spin_unlock_irqrestore (&emu->memblk_lock, flags);return 0 ; } err =map_memblk (emu, blk);
@@ -289,7 +287,6 @@ int snd_emu10k1_memblk_map(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *b } } } -spin_unlock_irqrestore (&emu->memblk_lock, flags);return err; }
@@ -424,13 +421,12 @@ snd_emu10k1_synth_free(struct snd_emu10k1 *emu, struct snd_util_memblk *memblk) {struct snd_util_memhdr *hdr = emu->memhdr;struct snd_emu10k1_memblk *blk = (struct snd_emu10k1_memblk *)memblk; -unsigned long flags;guard (mutex)(&hdr->block_mutex); -spin_lock_irqsave (&emu->memblk_lock, flags); -if (blk->mapped_page >=0 ) -unmap_memblk (emu, blk); -spin_unlock_irqrestore (&emu->memblk_lock, flags); + scoped_guard(spinlock_irqsave, &emu->memblk_lock) { +if (blk->mapped_page >=0 ) +unmap_memblk (emu, blk); + }synth_free_pages (emu, blk);__snd_util_mem_free (hdr, memblk);return 0 ;
sound/pci/emu10k1/p16v.c +2 -6
@@ -342,24 +342,20 @@ static int snd_p16v_pcm_prepare_capture(struct snd_pcm_substream *substream)static void snd_p16v_intr_enable (struct snd_emu10k1 *emu,unsigned int intrenb) { -unsigned long flags;unsigned int enable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); enable =inl (emu->port +INTE2 ) | intrenb;outl (enable, emu->port +INTE2 ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_p16v_intr_disable (struct snd_emu10k1 *emu,unsigned int intrenb) { -unsigned long flags;unsigned int disable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); disable =inl (emu->port +INTE2 ) & (~intrenb);outl (disable, emu->port +INTE2 ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_p16v_interrupt (struct snd_emu10k1 *emu)
sound/pci/emu10k1/voice.c +2 -6
@@ -77,7 +77,6 @@ static void voice_free(struct snd_emu10k1 *emu,int snd_emu10k1_voice_alloc (struct snd_emu10k1 *emu,int type,int count,int channels,struct snd_emu10k1_pcm *epcm,struct snd_emu10k1_voice **rvoice) { -unsigned long flags;int result;if (snd_BUG_ON (!rvoice))
@@ -87,7 +86,7 @@ int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int count, int chif (snd_BUG_ON (!channels))return -EINVAL ; -spin_lock_irqsave (&emu->voice_lock, flags); +guard (spinlock_irqsave)(&emu->voice_lock);for (int got =0 ; got < channels; ) { result =voice_alloc (emu, type, count, epcm, &rvoice[got]);if (result ==0 ) {
@@ -113,7 +112,6 @@ int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int count, int ch }break ; } -spin_unlock_irqrestore (&emu->voice_lock, flags);return result; }
@@ -123,17 +121,15 @@ EXPORT_SYMBOL(snd_emu10k1_voice_alloc);int snd_emu10k1_voice_free (struct snd_emu10k1 *emu,struct snd_emu10k1_voice *pvoice) { -unsigned long flags;int last;if (snd_BUG_ON (!pvoice))return -EINVAL ; -spin_lock_irqsave (&emu->voice_lock, flags); +guard (spinlock_irqsave)(&emu->voice_lock);do { last = pvoice->last;voice_free (emu, pvoice++); }while (!last); -spin_unlock_irqrestore (&emu->voice_lock, flags);return 0 ; }
Signature · 1 line
2.50.1
PATCH 29/61 ALSA: emu10k1x: 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/pci/emu10k1/emu10k1x.c | 221 ++++++++++++++--------------------- 1 file changed, 88 insertions(+), 133 deletions(-)
sound/pci/emu10k1/emu10k1x.c +88 -133
@@ -281,16 +281,13 @@ static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu, unsigned int reg, unsigned int chn) { -unsigned long flags; -unsigned int regptr, val; +unsigned int regptr; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (regptr, emu->port +PTR ); - val =inl (emu->port +DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); -return val; +return inl (emu->port +DATA ); } static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
@@ -299,45 +296,36 @@ static void snd_emu10k1x_ptr_write(struct emu10k1x *emu, unsigned int data) {unsigned int regptr; -unsigned long flags; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (regptr, emu->port +PTR );outl (data, emu->port +DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_emu10k1x_intr_enable (struct emu10k1x *emu,unsigned int intrenb) { -unsigned long flags;unsigned int intr_enable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); intr_enable =inl (emu->port +INTE ) | intrenb;outl (intr_enable, emu->port +INTE ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_emu10k1x_intr_disable (struct emu10k1x *emu,unsigned int intrenb) { -unsigned long flags;unsigned int intr_enable; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); intr_enable =inl (emu->port +INTE ) & ~intrenb;outl (intr_enable, emu->port +INTE ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_emu10k1x_gpio_write (struct emu10k1x *emu,unsigned int value) { -unsigned long flags; - -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outl (value, emu->port +GPIO ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static void snd_emu10k1x_pcm_free_substream (struct snd_pcm_runtime *runtime)
@@ -694,26 +682,20 @@ static unsigned short snd_emu10k1x_ac97_read(struct snd_ac97 *ac97, unsigned short reg) {struct emu10k1x *emu = ac97->private_data; -unsigned long flags; -unsigned short val; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outb (reg, emu->port +AC97ADDRESS ); - val =inw (emu->port +AC97DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); -return val; +return inw (emu->port +AC97DATA ); }static void snd_emu10k1x_ac97_write (struct snd_ac97 *ac97,unsigned short reg,unsigned short val) {struct emu10k1x *emu = ac97->private_data; -unsigned long flags; -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock);outb (reg, emu->port +AC97ADDRESS );outw (val, emu->port +AC97DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); }static int snd_emu10k1x_ac97 (struct emu10k1x *chip)
@@ -966,14 +948,12 @@ static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry, {struct emu10k1x *emu = entry->private_data;unsigned long value,value1,value2; -unsigned long flags;int i;snd_iprintf (buffer,"Registers:\n\n" );for (i =0 ; i <0x20 ; i+=4 ) { -spin_lock_irqsave (&emu->emu_lock, flags); +guard (spinlock_irqsave)(&emu->emu_lock); value =inl (emu->port + i); -spin_unlock_irqrestore (&emu->emu_lock, flags);snd_iprintf (buffer,"Register %02X: %08lX\n" , i, value); }snd_iprintf (buffer,"\nRegisters\n\n" );
@@ -1206,28 +1186,28 @@ static void do_emu10k1x_midi_interrupt(struct emu10k1x *emu,return ; } -spin_lock (&midi->input_lock); -if ((status & midi->ipr_rx) &&mpu401_input_avail (emu, midi)) { -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT )) { -mpu401_clear_rx (emu, midi); - }else { - byte =mpu401_read_data (emu, midi); -if (midi->substream_input) -snd_rawmidi_receive (midi->substream_input, &byte,1 ); + scoped_guard(spinlock, &midi->input_lock) { +if ((status & midi->ipr_rx) &&mpu401_input_avail (emu, midi)) { +if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT )) { +mpu401_clear_rx (emu, midi); + }else { + byte =mpu401_read_data (emu, midi); +if (midi->substream_input) +snd_rawmidi_receive (midi->substream_input, &byte,1 ); + } } } -spin_unlock (&midi->input_lock); -spin_lock (&midi->output_lock); -if ((status & midi->ipr_tx) &&mpu401_output_ready (emu, midi)) { -if (midi->substream_output && -snd_rawmidi_transmit (midi->substream_output, &byte,1 ) ==1 ) { -mpu401_write_data (emu, midi, byte); - }else { -snd_emu10k1x_intr_disable (emu, midi->tx_enable); + scoped_guard(spinlock, &midi->output_lock) { +if ((status & midi->ipr_tx) &&mpu401_output_ready (emu, midi)) { +if (midi->substream_output && +snd_rawmidi_transmit (midi->substream_output, &byte,1 ) ==1 ) { +mpu401_write_data (emu, midi, byte); + }else { +snd_emu10k1x_intr_disable (emu, midi->tx_enable); + } } } -spin_unlock (&midi->output_lock); }static void snd_emu10k1x_midi_interrupt (struct emu10k1x *emu,unsigned int status)
@@ -1238,29 +1218,28 @@ static void snd_emu10k1x_midi_interrupt(struct emu10k1x *emu, unsigned int statustatic int snd_emu10k1x_midi_cmd (struct emu10k1x * emu,struct emu10k1x_midi *midi,unsigned char cmd,int ack) { -unsigned long flags;int timeout, ok; -spin_lock_irqsave (&midi->input_lock, flags); -mpu401_write_data (emu, midi,0x00 ); -/* mpu401_clear_rx(emu, midi); */ + scoped_guard(spinlock_irqsave, &midi->input_lock) { +mpu401_write_data (emu, midi,0x00 ); +/* mpu401_clear_rx(emu, midi); */ -mpu401_write_cmd (emu, midi, cmd); -if (ack) { - ok =0 ; - timeout =10000 ; -while (!ok && timeout-- >0 ) { -if (mpu401_input_avail (emu, midi)) { -if (mpu401_read_data (emu, midi) ==MPU401_ACK ) - ok =1 ; +mpu401_write_cmd (emu, midi, cmd); +if (ack) { + ok =0 ; + timeout =10000 ; +while (!ok && timeout-- >0 ) { +if (mpu401_input_avail (emu, midi)) { +if (mpu401_read_data (emu, midi) ==MPU401_ACK ) + ok =1 ; + } } - } -if (!ok &&mpu401_read_data (emu, midi) ==MPU401_ACK ) +if (!ok &&mpu401_read_data (emu, midi) ==MPU401_ACK ) + ok =1 ; + }else { ok =1 ; - }else { - ok =1 ; + } } -spin_unlock_irqrestore (&midi->input_lock, flags);if (!ok) { dev_err(emu->card->dev, "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
@@ -1276,100 +1255,78 @@ static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream) {struct emu10k1x *emu;struct emu10k1x_midi *midi = substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); - midi->midi_mode |=EMU10K1X_MIDI_MODE_INPUT ; - midi->substream_input = substream; -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); -if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,1 )) - goto error_out; -if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) - goto error_out; - }else { -spin_unlock_irqrestore (&midi->open_lock, flags); + scoped_guard(spinlock_irqsave, &midi->open_lock) { + midi->midi_mode |=EMU10K1X_MIDI_MODE_INPUT ; + midi->substream_input = substream; +if (midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT ) +return 0 ; } +if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,1 )) +return -EIO ; +if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) +return -EIO ;return 0 ; - -error_out: -return -EIO ; }static int snd_emu10k1x_midi_output_open (struct snd_rawmidi_substream *substream) {struct emu10k1x *emu;struct emu10k1x_midi *midi = substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); - midi->midi_mode |=EMU10K1X_MIDI_MODE_OUTPUT ; - midi->substream_output = substream; -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); -if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,1 )) - goto error_out; -if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) - goto error_out; - }else { -spin_unlock_irqrestore (&midi->open_lock, flags); + scoped_guard(spinlock_irqsave, &midi->open_lock) { + midi->midi_mode |=EMU10K1X_MIDI_MODE_OUTPUT ; + midi->substream_output = substream; +if (midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT ) +return 0 ; } +if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,1 )) +return -EIO ; +if (snd_emu10k1x_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) +return -EIO ;return 0 ; - -error_out: -return -EIO ; }static int snd_emu10k1x_midi_input_close (struct snd_rawmidi_substream *substream) {struct emu10k1x *emu;struct emu10k1x_midi *midi = substream->rmidi->private_data; -unsigned long flags; -int err =0 ; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); -snd_emu10k1x_intr_disable (emu, midi->rx_enable); - midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT ; - midi->substream_input =NULL ; -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); - err =snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,0 ); - }else { -spin_unlock_irqrestore (&midi->open_lock, flags); + scoped_guard(spinlock_irqsave, &midi->open_lock) { +snd_emu10k1x_intr_disable (emu, midi->rx_enable); + midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT ; + midi->substream_input =NULL ; +if (midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT ) +return 0 ; } -return err; +return snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,0 ); }static int snd_emu10k1x_midi_output_close (struct snd_rawmidi_substream *substream) {struct emu10k1x *emu;struct emu10k1x_midi *midi = substream->rmidi->private_data; -unsigned long flags; -int err =0 ; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); -snd_emu10k1x_intr_disable (emu, midi->tx_enable); - midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT ; - midi->substream_output =NULL ; -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); - err =snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,0 ); - }else { -spin_unlock_irqrestore (&midi->open_lock, flags); + scoped_guard(spinlock_irqsave, &midi->open_lock) { +snd_emu10k1x_intr_disable (emu, midi->tx_enable); + midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT ; + midi->substream_output =NULL ; +if (midi->midi_mode &EMU10K1X_MIDI_MODE_INPUT ) +return 0 ; } -return err; +return snd_emu10k1x_midi_cmd (emu, midi,MPU401_RESET ,0 ); }static void snd_emu10k1x_midi_input_trigger (struct snd_rawmidi_substream *substream,int up)
@@ -1390,7 +1347,6 @@ static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *subst {struct emu10k1x *emu;struct emu10k1x_midi *midi = substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))
@@ -1401,22 +1357,21 @@ static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *substunsigned char byte;/* try to send some amount of bytes here before interrupts */ -spin_lock_irqsave (&midi->output_lock, flags); -while (max >0 ) { -if (mpu401_output_ready (emu, midi)) { -if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT ) || -snd_rawmidi_transmit (substream, &byte,1 ) !=1 ) { -/* no more data */ -spin_unlock_irqrestore (&midi->output_lock, flags); -return ; + scoped_guard(spinlock_irqsave, &midi->output_lock) { +while (max >0 ) { +if (mpu401_output_ready (emu, midi)) { +if (!(midi->midi_mode &EMU10K1X_MIDI_MODE_OUTPUT ) || +snd_rawmidi_transmit (substream, &byte,1 ) !=1 ) { +/* no more data */ +return ; + } +mpu401_write_data (emu, midi, byte); + max--; + }else { +break ; } -mpu401_write_data (emu, midi, byte); - max--; - }else { -break ; } } -spin_unlock_irqrestore (&midi->output_lock, flags);snd_emu10k1x_intr_enable (emu, midi->tx_enable); }else {snd_emu10k1x_intr_disable (emu, midi->tx_enable);
Signature · 1 line
2.50.1
PATCH 30/61 ALSA: es1938: 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/pci/es1938.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
sound/pci/es1938.c +10 -18
@@ -237,11 +237,9 @@ MODULE_DEVICE_TABLE(pci, snd_es1938_ids);* -----------------------------------------------------------------*/ static void snd_es1938_mixer_write (struct es1938 *chip,unsigned char reg,unsigned char val) { -unsigned long flags; -spin_lock_irqsave (&chip->mixer_lock, flags); +guard (spinlock_irqsave)(&chip->mixer_lock);outb (reg,SLSB_REG (chip,MIXERADDR ));outb (val,SLSB_REG (chip,MIXERDATA )); -spin_unlock_irqrestore (&chip->mixer_lock, flags);dev_dbg (chip->card->dev,"Mixer reg %02x set to %02x\n" , reg, val); }
@@ -251,11 +249,10 @@ static void snd_es1938_mixer_write(struct es1938 *chip, unsigned char reg, unsigstatic int snd_es1938_mixer_read (struct es1938 *chip,unsigned char reg) {int data; -unsigned long flags; -spin_lock_irqsave (&chip->mixer_lock, flags); + +guard (spinlock_irqsave)(&chip->mixer_lock);outb (reg,SLSB_REG (chip,MIXERADDR )); data =inb (SLSB_REG (chip,MIXERDATA )); -spin_unlock_irqrestore (&chip->mixer_lock, flags);dev_dbg (chip->card->dev,"Mixer reg %02x now is %02x\n" , reg, data);return data; }
@@ -266,9 +263,9 @@ static int snd_es1938_mixer_read(struct es1938 *chip, unsigned char reg)static int snd_es1938_mixer_bits (struct es1938 *chip,unsigned char reg,unsigned char mask,unsigned char val) { -unsigned long flags;unsigned char old, new, oval; -spin_lock_irqsave (&chip->mixer_lock, flags); + +guard (spinlock_irqsave)(&chip->mixer_lock);outb (reg,SLSB_REG (chip,MIXERADDR )); old =inb (SLSB_REG (chip,MIXERDATA )); oval = old & mask;
@@ -279,7 +276,6 @@ static int snd_es1938_mixer_bits(struct es1938 *chip, unsigned char reg,"Mixer reg %02x was %02x, set to %02x\n" , reg, old, new); } -spin_unlock_irqrestore (&chip->mixer_lock, flags);return oval; }
@@ -322,11 +318,9 @@ static int snd_es1938_get_byte(struct es1938 *chip)* -----------------------------------------------------------------*/ static void snd_es1938_write (struct es1938 *chip,unsigned char reg,unsigned char val) { -unsigned long flags; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);snd_es1938_write_cmd (chip, reg);snd_es1938_write_cmd (chip, val); -spin_unlock_irqrestore (&chip->reg_lock, flags);dev_dbg (chip->card->dev,"Reg %02x set to %02x\n" , reg, val); }
@@ -336,12 +330,11 @@ static void snd_es1938_write(struct es1938 *chip, unsigned char reg, unsigned chstatic unsigned char snd_es1938_read (struct es1938 *chip,unsigned char reg) {unsigned char val; -unsigned long flags; -spin_lock_irqsave (&chip->reg_lock, flags); + +guard (spinlock_irqsave)(&chip->reg_lock);snd_es1938_write_cmd (chip,ESS_CMD_READREG );snd_es1938_write_cmd (chip, reg); val =snd_es1938_get_byte (chip); -spin_unlock_irqrestore (&chip->reg_lock, flags);dev_dbg (chip->card->dev,"Reg %02x now is %02x\n" , reg, val);return val; }
@@ -352,9 +345,9 @@ static unsigned char snd_es1938_read(struct es1938 *chip, unsigned char reg)static int snd_es1938_bits (struct es1938 *chip,unsigned char reg,unsigned char mask,unsigned char val) { -unsigned long flags;unsigned char old, new, oval; -spin_lock_irqsave (&chip->reg_lock, flags); + +guard (spinlock_irqsave)(&chip->reg_lock);snd_es1938_write_cmd (chip,ESS_CMD_READREG );snd_es1938_write_cmd (chip, reg); old =snd_es1938_get_byte (chip);
@@ -366,7 +359,6 @@ static int snd_es1938_bits(struct es1938 *chip, unsigned char reg, unsigned chardev_dbg (chip->card->dev,"Reg %02x was %02x, set to %02x\n" , reg, old, new); } -spin_unlock_irqrestore (&chip->reg_lock, flags);return oval; }
Signature · 1 line
2.50.1
PATCH 31/61 ALSA: es1968: 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/pci/es1968.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
sound/pci/es1968.c +4 -10
@@ -1318,12 +1318,11 @@ static int calc_available_memory_size(struct es1968 *chip)int max_size =0 ;struct esm_memory *buf; -mutex_lock (&chip->memory_mutex); +guard (mutex)(&chip->memory_mutex);list_for_each_entry (buf, &chip->buf_list, list) {if (buf->empty && buf->buf.bytes > max_size) max_size = buf->buf.bytes; } -mutex_unlock (&chip->memory_mutex);if (max_size >=128 *1024 ) max_size =127 *1024 ;return max_size;
@@ -1335,21 +1334,18 @@ static struct esm_memory *snd_es1968_new_memory(struct es1968 *chip, int size)struct esm_memory *buf; size =ALIGN (size,ESM_MEM_ALIGN ); -mutex_lock (&chip->memory_mutex); +guard (mutex)(&chip->memory_mutex);list_for_each_entry (buf, &chip->buf_list, list) {if (buf->empty && buf->buf.bytes >= size) goto __found; } -mutex_unlock (&chip->memory_mutex);return NULL ; __found:if (buf->buf.bytes > size) {struct esm_memory *chunk =kmalloc (sizeof (*chunk),GFP_KERNEL ); -if (chunk ==NULL ) { -mutex_unlock (&chip->memory_mutex); +if (chunk ==NULL )return NULL ; - } chunk->buf = buf->buf; chunk->buf.bytes -= size; chunk->buf.area += size;
@@ -1359,7 +1355,6 @@ static struct esm_memory *snd_es1968_new_memory(struct es1968 *chip, int size)list_add (&chunk->list, &buf->list); } buf->empty =0 ; -mutex_unlock (&chip->memory_mutex);return buf; }
@@ -1368,7 +1363,7 @@ static void snd_es1968_free_memory(struct es1968 *chip, struct esm_memory *buf) {struct esm_memory *chunk; -mutex_lock (&chip->memory_mutex); +guard (mutex)(&chip->memory_mutex); buf->empty =1 ;if (buf->list.prev != &chip->buf_list) { chunk = list_entry(buf->list.prev, struct esm_memory, list);
@@ -1387,7 +1382,6 @@ static void snd_es1968_free_memory(struct es1968 *chip, struct esm_memory *buf)kfree (chunk); } } -mutex_unlock (&chip->memory_mutex); }static void snd_es1968_free_dmabuf (struct es1968 *chip)
Signature · 1 line
2.50.1
PATCH 32/61 ALSA: es1968: 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/pci/es1968.c | 146 +++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 92 deletions(-)
sound/pci/es1968.c +54 -92
@@ -574,10 +574,8 @@ static void __maestro_write(struct es1968 *chip, u16 reg, u16 data)static inline void maestro_write (struct es1968 *chip,u16 reg,u16 data) { -unsigned long flags; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);__maestro_write (chip, reg, data); -spin_unlock_irqrestore (&chip->reg_lock, flags); }/* no spinlock */
@@ -592,12 +590,8 @@ static u16 __maestro_read(struct es1968 *chip, u16 reg)static inline u16 maestro_read (struct es1968 *chip,u16 reg) { -unsigned long flags; -u16 result; -spin_lock_irqsave (&chip->reg_lock, flags); - result =__maestro_read (chip, reg); -spin_unlock_irqrestore (&chip->reg_lock, flags); -return result; +guard (spinlock_irqsave)(&chip->reg_lock); +return __maestro_read (chip, reg); }/* Wait for the codec bus to be free */
@@ -693,10 +687,8 @@ static void __apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 datstatic void apu_set_register (struct es1968 *chip,u16 channel,u8 reg,u16 data) { -unsigned long flags; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);__apu_set_register (chip, channel, reg, data); -spin_unlock_irqrestore (&chip->reg_lock, flags); }static u16 __apu_get_register (struct es1968 *chip,u16 channel,u8 reg)
@@ -710,62 +702,40 @@ static u16 __apu_get_register(struct es1968 *chip, u16 channel, u8 reg)static u16 apu_get_register (struct es1968 *chip,u16 channel,u8 reg) { -unsigned long flags; -u16 v; -spin_lock_irqsave (&chip->reg_lock, flags); - v =__apu_get_register (chip, channel, reg); -spin_unlock_irqrestore (&chip->reg_lock, flags); -return v; +guard (spinlock_irqsave)(&chip->reg_lock); +return __apu_get_register (chip, channel, reg); }#if 0 /* ASSP is not supported */ static void assp_set_register (struct es1968 *chip,u32 reg,u32 value) { -unsigned long flags; - -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave),(&chip->reg_lock);outl (reg, chip->io_port +ASSP_INDEX );outl (value, chip->io_port +ASSP_DATA ); -spin_unlock_irqrestore (&chip->reg_lock, flags); }static u32 assp_get_register (struct es1968 *chip,u32 reg) { -unsigned long flags; -u32 value; - -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);outl (reg, chip->io_port +ASSP_INDEX ); - value =inl (chip->io_port +ASSP_DATA ); -spin_unlock_irqrestore (&chip->reg_lock, flags); - -return value; +return inl (chip->io_port +ASSP_DATA ); }#endif static void wave_set_register (struct es1968 *chip,u16 reg,u16 value) { -unsigned long flags; - -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);outw (reg, chip->io_port +WC_INDEX );outw (value, chip->io_port +WC_DATA ); -spin_unlock_irqrestore (&chip->reg_lock, flags); }static u16 wave_get_register (struct es1968 *chip,u16 reg) { -unsigned long flags; -u16 value; - -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);outw (reg, chip->io_port +WC_INDEX ); - value =inw (chip->io_port +WC_DATA ); -spin_unlock_irqrestore (&chip->reg_lock, flags); - -return value; +return inw (chip->io_port +WC_DATA ); }/* *******************
@@ -924,7 +894,7 @@ static inline void snd_es1968_trigger_apu(struct es1968 *esm, int apu, int mode)static void snd_es1968_pcm_start (struct es1968 *chip,struct esschan *es) { -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);__apu_set_register (chip, es->apu[0 ],5 , es->base[0 ]);snd_es1968_trigger_apu (chip, es->apu[0 ], es->apu_mode[0 ]);if (es->mode ==ESM_MODE_CAPTURE ) {
@@ -939,19 +909,17 @@ static void snd_es1968_pcm_start(struct es1968 *chip, struct esschan *es)snd_es1968_trigger_apu (chip, es->apu[3 ], es->apu_mode[3 ]); } } -spin_unlock (&chip->reg_lock); }static void snd_es1968_pcm_stop (struct es1968 *chip,struct esschan *es) { -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);snd_es1968_trigger_apu (chip, es->apu[0 ],0 );snd_es1968_trigger_apu (chip, es->apu[1 ],0 );if (es->mode ==ESM_MODE_CAPTURE ) {snd_es1968_trigger_apu (chip, es->apu[2 ],0 );snd_es1968_trigger_apu (chip, es->apu[3 ],0 ); } -spin_unlock (&chip->reg_lock); }/* set the wavecache control reg */
@@ -981,7 +949,6 @@ static void snd_es1968_playback_setup(struct es1968 *chip, struct esschan *es,int high_apu =0 ;int channel, apu;int i, size; -unsigned long flags;u32 freq; size = es->dma_size >> es->wav_shift;
@@ -1051,12 +1018,12 @@ static void snd_es1968_playback_setup(struct es1968 *chip, struct esschan *es,apu_set_register (chip, apu,10 ,0x8F08 ); } -spin_lock_irqsave (&chip->reg_lock, flags); -/* clear WP interrupts */ -outw (1 , chip->io_port +0x04 ); -/* enable WP ints */ -outw (inw (chip->io_port +ESM_PORT_HOST_IRQ ) |ESM_HIRQ_DSIE , chip->io_port +ESM_PORT_HOST_IRQ ); -spin_unlock_irqrestore (&chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &chip->reg_lock) { +/* clear WP interrupts */ +outw (1 , chip->io_port +0x04 ); +/* enable WP ints */ +outw (inw (chip->io_port +ESM_PORT_HOST_IRQ ) |ESM_HIRQ_DSIE , chip->io_port +ESM_PORT_HOST_IRQ ); + } freq = runtime->rate;/* set frequency */
@@ -1127,7 +1094,6 @@ static void snd_es1968_capture_setup(struct es1968 *chip, struct esschan *es, {int size;u32 freq; -unsigned long flags; size = es->dma_size >> es->wav_shift;
@@ -1179,12 +1145,11 @@ static void snd_es1968_capture_setup(struct es1968 *chip, struct esschan *es,snd_es1968_apu_set_freq (chip, es->apu[2 ], freq);snd_es1968_apu_set_freq (chip, es->apu[3 ], freq); -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);/* clear WP interrupts */ outw (1 , chip->io_port +0x04 );/* enable WP ints */ outw (inw (chip->io_port +ESM_PORT_HOST_IRQ ) |ESM_HIRQ_DSIE , chip->io_port +ESM_PORT_HOST_IRQ ); -spin_unlock_irqrestore (&chip->reg_lock, flags); }/*******************
@@ -1228,7 +1193,7 @@ static int snd_es1968_pcm_trigger(struct snd_pcm_substream *substream, int cmd)struct es1968 *chip =snd_pcm_substream_chip (substream);struct esschan *es = substream->runtime->private_data; -spin_lock (&chip->substream_lock); +guard (spinlock)(&chip->substream_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -1249,7 +1214,6 @@ static int snd_es1968_pcm_trigger(struct snd_pcm_substream *substream, int cmd)snd_es1968_bob_dec (chip);break ; } -spin_unlock (&chip->substream_lock);return 0 ; }
@@ -1543,9 +1507,8 @@ static int snd_es1968_playback_open(struct snd_pcm_substream *substream) runtime->hw.buffer_bytes_max = runtime->hw.period_bytes_max =calc_available_memory_size (chip); -spin_lock_irq (&chip->substream_lock); +guard (spinlock_irq)(&chip->substream_lock);list_add (&es->list, &chip->substream_list); -spin_unlock_irq (&chip->substream_lock);return 0 ; }
@@ -1603,9 +1566,8 @@ static int snd_es1968_capture_open(struct snd_pcm_substream *substream)if (err <0 )return err; -spin_lock_irq (&chip->substream_lock); +guard (spinlock_irq)(&chip->substream_lock);list_add (&es->list, &chip->substream_list); -spin_unlock_irq (&chip->substream_lock);return 0 ; }
@@ -1618,9 +1580,9 @@ static int snd_es1968_playback_close(struct snd_pcm_substream *substream)if (substream->runtime->private_data ==NULL )return 0 ; es = substream->runtime->private_data; -spin_lock_irq (&chip->substream_lock); -list_del (&es->list); -spin_unlock_irq (&chip->substream_lock); + scoped_guard(spinlock_irq, &chip->substream_lock) { +list_del (&es->list); + }snd_es1968_free_apu_pair (chip, es->apu[0 ]);kfree (es);
@@ -1635,9 +1597,9 @@ static int snd_es1968_capture_close(struct snd_pcm_substream *substream)if (substream->runtime->private_data ==NULL )return 0 ; es = substream->runtime->private_data; -spin_lock_irq (&chip->substream_lock); -list_del (&es->list); -spin_unlock_irq (&chip->substream_lock); + scoped_guard(spinlock_irq, &chip->substream_lock) { +list_del (&es->list); + }snd_es1968_free_memory (chip, es->mixbuf);snd_es1968_free_apu_pair (chip, es->apu[0 ]);snd_es1968_free_apu_pair (chip, es->apu[2 ]);
@@ -1718,29 +1680,29 @@ static void es1968_measure_clock(struct es1968 *chip)apu_set_register (chip, apu,9 ,0xD000 );apu_set_register (chip, apu,10 ,0x8F08 );apu_set_register (chip, apu,11 ,0x0000 ); -spin_lock_irq (&chip->reg_lock); -outw (1 , chip->io_port +0x04 );/* clear WP interrupts */ -outw (inw (chip->io_port +ESM_PORT_HOST_IRQ ) |ESM_HIRQ_DSIE , chip->io_port +ESM_PORT_HOST_IRQ );/* enable WP ints */ -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { +outw (1 , chip->io_port +0x04 );/* clear WP interrupts */ +outw (inw (chip->io_port +ESM_PORT_HOST_IRQ ) |ESM_HIRQ_DSIE , chip->io_port +ESM_PORT_HOST_IRQ );/* enable WP ints */ + }snd_es1968_apu_set_freq (chip, apu, ((unsigned int )48000 <<16 ) / chip->clock);/* 48000 Hz */ chip->in_measurement =1 ; chip->measure_apu = apu; -spin_lock_irq (&chip->reg_lock); -snd_es1968_bob_inc (chip,ESM_BOB_FREQ ); -__apu_set_register (chip, apu,5 , pa &0xffff ); -snd_es1968_trigger_apu (chip, apu,ESM_APU_16BITLINEAR ); - start_time =ktime_get (); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { +snd_es1968_bob_inc (chip,ESM_BOB_FREQ ); +__apu_set_register (chip, apu,5 , pa &0xffff ); +snd_es1968_trigger_apu (chip, apu,ESM_APU_16BITLINEAR ); + start_time =ktime_get (); + }msleep (50 ); -spin_lock_irq (&chip->reg_lock); - offset =__apu_get_register (chip, apu,5 ); - stop_time =ktime_get (); -snd_es1968_trigger_apu (chip, apu,0 );/* stop */ -snd_es1968_bob_dec (chip); - chip->in_measurement =0 ; -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + offset =__apu_get_register (chip, apu,5 ); + stop_time =ktime_get (); +snd_es1968_trigger_apu (chip, apu,0 );/* stop */ +snd_es1968_bob_dec (chip); + chip->in_measurement =0 ; + }/* check the current position */ offset -= (pa &0xffff );
@@ -1964,15 +1926,15 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)if (event &ESM_SOUND_IRQ ) {struct esschan *es; -spin_lock (&chip->substream_lock); -list_for_each_entry (es, &chip->substream_list, list) { -if (es->running) { -snd_es1968_update_pcm (chip, es); -if (es->fmt &ESS_FMT_STEREO ) -snd_es1968_suppress_jitter (chip, es); + scoped_guard(spinlock, &chip->substream_lock) { +list_for_each_entry (es, &chip->substream_list, list) { +if (es->running) { +snd_es1968_update_pcm (chip, es); +if (es->fmt &ESS_FMT_STEREO ) +snd_es1968_suppress_jitter (chip, es); + } } } -spin_unlock (&chip->substream_lock);if (chip->in_measurement) {unsigned int curp =__apu_get_register (chip, chip->measure_apu,5 );if (curp < chip->measure_lastpos)
Signature · 1 line
2.50.1
PATCH 33/61 ALSA: fm801: 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/pci/fm801.c | 71 ++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 41 deletions(-)
sound/pci/fm801.c +30 -41
@@ -279,16 +279,14 @@ static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg, unsigned short mask, unsigned short value) { int change; -unsigned long flags;unsigned short old, new; -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock); old =fm801_ioread16 (chip, reg); new = (old & ~mask) | value; change = old != new;if (change)fm801_iowrite16 (chip, reg, new); -spin_unlock_irqrestore (&chip->reg_lock, flags);return change; }
@@ -393,7 +391,7 @@ static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream, {struct fm801 *chip =snd_pcm_substream_chip (substream); -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : chip->ply_ctrl &= ~(FM801_BUF1_LAST |
@@ -414,12 +412,10 @@ static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream, chip->ply_ctrl &= ~FM801_PAUSE ;break ;default : -spin_unlock (&chip->reg_lock);snd_BUG ();return -EINVAL ; }fm801_writew (chip,PLY_CTRL , chip->ply_ctrl); -spin_unlock (&chip->reg_lock);return 0 ; }
@@ -428,7 +424,7 @@ static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream, {struct fm801 *chip =snd_pcm_substream_chip (substream); -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : chip->cap_ctrl &= ~(FM801_BUF1_LAST |
@@ -449,12 +445,10 @@ static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream, chip->cap_ctrl &= ~FM801_PAUSE ;break ;default : -spin_unlock (&chip->reg_lock);snd_BUG ();return -EINVAL ; }fm801_writew (chip,CAP_CTRL , chip->cap_ctrl); -spin_unlock (&chip->reg_lock);return 0 ; }
@@ -465,7 +459,7 @@ static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream) chip->ply_size =snd_pcm_lib_buffer_bytes (substream); chip->ply_count =snd_pcm_lib_period_bytes (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->ply_ctrl &= ~(FM801_START |FM801_16BIT |FM801_STEREO |FM801_RATE_MASK |FM801_CHANNELS_MASK );
@@ -487,7 +481,6 @@ static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)fm801_writel (chip,PLY_BUF1 , chip->ply_buffer);fm801_writel (chip,PLY_BUF2 , chip->ply_buffer + (chip->ply_count % chip->ply_size)); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -498,7 +491,7 @@ static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream) chip->cap_size =snd_pcm_lib_buffer_bytes (substream); chip->cap_count =snd_pcm_lib_period_bytes (substream); -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->cap_ctrl &= ~(FM801_START |FM801_16BIT |FM801_STEREO |FM801_RATE_MASK );if (snd_pcm_format_width (runtime->format) ==16 )
@@ -514,7 +507,6 @@ static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)fm801_writel (chip,CAP_BUF1 , chip->cap_buffer);fm801_writel (chip,CAP_BUF2 , chip->cap_buffer + (chip->cap_count % chip->cap_size)); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -525,13 +517,12 @@ static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *suif (!(chip->ply_ctrl &FM801_START ))return 0 ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); ptr = chip->ply_pos + (chip->ply_count -1 ) -fm801_readw (chip,PLY_COUNT );if (fm801_readw (chip,IRQ_STATUS ) &FM801_IRQ_PLAYBACK ) { ptr += chip->ply_count; ptr %= chip->ply_size; } -spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, ptr); }
@@ -542,13 +533,12 @@ static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *subif (!(chip->cap_ctrl &FM801_START ))return 0 ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); ptr = chip->cap_pos + (chip->cap_count -1 ) -fm801_readw (chip,CAP_COUNT );if (fm801_readw (chip,IRQ_STATUS ) &FM801_IRQ_CAPTURE ) { ptr += chip->cap_count; ptr %= chip->cap_size; } -spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, ptr); }
@@ -565,31 +555,31 @@ static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id)/* ack first */ fm801_writew (chip,IRQ_STATUS , status);if (chip->pcm && (status &FM801_IRQ_PLAYBACK ) && chip->playback_substream) { -spin_lock (&chip->reg_lock); - chip->ply_buf++; - chip->ply_pos += chip->ply_count; - chip->ply_pos %= chip->ply_size; - tmp = chip->ply_pos + chip->ply_count; - tmp %= chip->ply_size; -if (chip->ply_buf &1 ) -fm801_writel (chip,PLY_BUF1 , chip->ply_buffer + tmp); -else -fm801_writel (chip,PLY_BUF2 , chip->ply_buffer + tmp); -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + chip->ply_buf++; + chip->ply_pos += chip->ply_count; + chip->ply_pos %= chip->ply_size; + tmp = chip->ply_pos + chip->ply_count; + tmp %= chip->ply_size; +if (chip->ply_buf &1 ) +fm801_writel (chip,PLY_BUF1 , chip->ply_buffer + tmp); +else +fm801_writel (chip,PLY_BUF2 , chip->ply_buffer + tmp); + }snd_pcm_period_elapsed (chip->playback_substream); }if (chip->pcm && (status &FM801_IRQ_CAPTURE ) && chip->capture_substream) { -spin_lock (&chip->reg_lock); - chip->cap_buf++; - chip->cap_pos += chip->cap_count; - chip->cap_pos %= chip->cap_size; - tmp = chip->cap_pos + chip->cap_count; - tmp %= chip->cap_size; -if (chip->cap_buf &1 ) -fm801_writel (chip,CAP_BUF1 , chip->cap_buffer + tmp); -else -fm801_writel (chip,CAP_BUF2 , chip->cap_buffer + tmp); -spin_unlock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + chip->cap_buf++; + chip->cap_pos += chip->cap_count; + chip->cap_pos %= chip->cap_size; + tmp = chip->cap_pos + chip->cap_count; + tmp %= chip->cap_size; +if (chip->cap_buf &1 ) +fm801_writel (chip,CAP_BUF1 , chip->cap_buffer + tmp); +else +fm801_writel (chip,CAP_BUF2 , chip->cap_buffer + tmp); + }snd_pcm_period_elapsed (chip->capture_substream); }if (chip->rmidi && (status &FM801_IRQ_MPU ))
@@ -924,10 +914,9 @@ static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,int invert = (kcontrol->private_value >>24 ) &0xff ;long *value = ucontrol->value.integer.value; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); value[0 ] = (fm801_ioread16 (chip, reg) >> shift_left) & mask; value[1 ] = (fm801_ioread16 (chip, reg) >> shift_right) & mask; -spin_unlock_irq (&chip->reg_lock);if (invert) { value[0 ] = mask - value[0 ]; value[1 ] = mask - value[1 ];
Signature · 1 line
2.50.1
PATCH 34/61 ALSA: ice1712: 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/pci/ice1712/aureon.c | 27 ++++-------- sound/pci/ice1712/delta.c | 30 ++++++-------- sound/pci/ice1712/hoontech.c | 24 +++++------ sound/pci/ice1712/ice1724.c | 70 +++++++++++++++++--------------- sound/pci/ice1712/maya44.c | 18 +++----- sound/pci/ice1712/phase.c | 6 +-- sound/pci/ice1712/pontis.c | 70 +++++++++++++------------------- sound/pci/ice1712/prodigy192.c | 11 ++--- sound/pci/ice1712/prodigy_hifi.c | 56 +++++++++---------------- sound/pci/ice1712/quartet.c | 3 +- sound/pci/ice1712/wtm.c | 6 +-- 11 files changed, 132 insertions(+), 189 deletions(-)
sound/pci/ice1712/aureon.c +9 -18
@@ -358,14 +358,13 @@ static int aureon_ac97_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elestruct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol);unsigned short vol; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); vol =aureon_ac97_read (ice, kcontrol->private_value &0x7F ); ucontrol->value.integer.value[0 ] =0x1F - (vol &0x1F );if (kcontrol->private_value &AUREON_AC97_STEREO ) ucontrol->value.integer.value[1 ] =0x1F - ((vol >>8 ) &0x1F ); -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -401,12 +400,11 @@ static int aureon_ac97_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_el {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol); -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); ucontrol->value.integer.value[0 ] =aureon_ac97_read (ice, kcontrol->private_value &0x7F ) &0x8000 ?0 :1 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -439,11 +437,10 @@ static int aureon_ac97_micboost_get(struct snd_kcontrol *kcontrol, struct snd_ct {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol); -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); ucontrol->value.integer.value[0 ] =aureon_ac97_read (ice,AC97_MIC ) &0x0020 ?0 :1 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -642,11 +639,10 @@ static int aureon_ac97_mmute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol); -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); ucontrol->value.integer.value[0 ] = (wm_get (ice,WM_OUT_MUX1 ) >>1 ) &0x01 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -704,9 +700,8 @@ static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol); -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); ucontrol->value.integer.value[0 ] = (wm_get (ice,WM_MUTE ) &0x10 ) ?0 :1 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -944,11 +939,10 @@ static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valstruct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol);unsigned short val; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); val =wm_get (ice,WM_DAC_DIG_MASTER_ATTEN ) &0xff ; val = val >PCM_MIN ? (val -PCM_MIN ) :0 ; ucontrol->value.integer.value[0 ] = val; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -984,12 +978,11 @@ static int wm_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_vaunsigned short val;int i; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex);for (i =0 ; i <2 ; i++) { val =wm_get (ice,WM_ADC_GAIN + i); ucontrol->value.integer.value[i] = ~val>>5 &0x1 ; } -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -1031,13 +1024,12 @@ static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valint i, idx;unsigned short vol; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex);for (i =0 ; i <2 ; i++) { idx =WM_ADC_GAIN + i; vol =wm_get (ice, idx) &0x1f ; ucontrol->value.integer.value[i] = vol; } -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -1097,11 +1089,10 @@ static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valstruct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol);unsigned short val; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); val =wm_get (ice,WM_ADC_MUX ); ucontrol->value.enumerated.item[0 ] = val &7 ; ucontrol->value.enumerated.item[1 ] = (val >>4 ) &7 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
sound/pci/ice1712/delta.c +13 -17
@@ -126,13 +126,12 @@ static int ap_cs8427_sendbytes(struct snd_i2c_device *device, unsigned char *bytint res = count;unsigned char tmp; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); tmp =ap_cs8427_codec_select (ice);ap_cs8427_write_byte (ice, (device->addr <<1 ) |0 , tmp);/* address + write mode */ while (count-- >0 )ap_cs8427_write_byte (ice, *bytes++, tmp);ap_cs8427_codec_deassert (ice, tmp); -mutex_unlock (&ice->gpio_mutex);return res; }
@@ -143,13 +142,12 @@ static int ap_cs8427_readbytes(struct snd_i2c_device *device, unsigned char *bytint res = count;unsigned char tmp; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); tmp =ap_cs8427_codec_select (ice);ap_cs8427_write_byte (ice, (device->addr <<1 ) |1 , tmp);/* address + read mode */ while (count-- >0 ) *bytes++ =ap_cs8427_read_byte (ice, tmp);ap_cs8427_codec_deassert (ice, tmp); -mutex_unlock (&ice->gpio_mutex);return res; }
@@ -176,7 +174,7 @@ static void snd_ice1712_delta_cs8403_spdif_write(struct snd_ice1712 *ice, unsign/* send byte to transmitter */ mask1 =ICE1712_DELTA_SPDIF_OUT_STAT_CLOCK ; mask2 =ICE1712_DELTA_SPDIF_OUT_STAT_DATA ; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA );for (idx =7 ; idx >=0 ; idx--) { tmp &= ~(mask1 | mask2);
@@ -190,7 +188,6 @@ static void snd_ice1712_delta_cs8403_spdif_write(struct snd_ice1712 *ice, unsign } tmp &= ~mask1;snd_ice1712_write (ice,ICE1712_IREG_GPIO_DATA , tmp); -mutex_unlock (&ice->gpio_mutex); }
@@ -306,14 +303,13 @@ static void delta_1010_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)if (rate ==0 )/* no hint - S/PDIF input is master, simply return */ return ; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA ); tmp2 = tmp & ~ICE1712_DELTA_DFS ;if (rate >48000 ) tmp2 |=ICE1712_DELTA_DFS ;if (tmp != tmp2)snd_ice1712_write (ice,ICE1712_IREG_GPIO_DATA , tmp2); -mutex_unlock (&ice->gpio_mutex); }/*
@@ -328,9 +324,9 @@ static void delta_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)return ;/* check before reset ak4524 to avoid unnecessary clicks */ -mutex_lock (&ice->gpio_mutex); - tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA ); -mutex_unlock (&ice->gpio_mutex); + scoped_guard(mutex, &ice->gpio_mutex) { + tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA ); + } tmp2 = tmp & ~ICE1712_DELTA_DFS ;if (rate >48000 ) tmp2 |=ICE1712_DELTA_DFS ;
@@ -339,12 +335,12 @@ static void delta_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)/* do it again */ snd_akm4xxx_reset (ak,1 ); -mutex_lock (&ice->gpio_mutex); - tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA ) & ~ICE1712_DELTA_DFS ; -if (rate >48000 ) - tmp |=ICE1712_DELTA_DFS ; -snd_ice1712_write (ice,ICE1712_IREG_GPIO_DATA , tmp); -mutex_unlock (&ice->gpio_mutex); + scoped_guard(mutex, &ice->gpio_mutex) { + tmp =snd_ice1712_read (ice,ICE1712_IREG_GPIO_DATA ) & ~ICE1712_DELTA_DFS ; +if (rate >48000 ) + tmp |=ICE1712_DELTA_DFS ; +snd_ice1712_write (ice,ICE1712_IREG_GPIO_DATA , tmp); + }snd_akm4xxx_reset (ak,0 ); }
sound/pci/ice1712/hoontech.c +10 -14
@@ -41,35 +41,35 @@ static void snd_ice1712_stdsp24_gpio_write(struct snd_ice1712 *ice, unsigned chastatic void snd_ice1712_stdsp24_darear (struct snd_ice1712 *ice,int activate) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); + +guard (mutex)(&ice->gpio_mutex);ICE1712_STDSP24_0_DAREAR (spec->boxbits, activate);snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[0 ]); -mutex_unlock (&ice->gpio_mutex); }static void snd_ice1712_stdsp24_mute (struct snd_ice1712 *ice,int activate) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); + +guard (mutex)(&ice->gpio_mutex);ICE1712_STDSP24_3_MUTE (spec->boxbits, activate);snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[3 ]); -mutex_unlock (&ice->gpio_mutex); }static void snd_ice1712_stdsp24_insel (struct snd_ice1712 *ice,int activate) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); + +guard (mutex)(&ice->gpio_mutex);ICE1712_STDSP24_3_INSEL (spec->boxbits, activate);snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[3 ]); -mutex_unlock (&ice->gpio_mutex); }static void snd_ice1712_stdsp24_box_channel (struct snd_ice1712 *ice,int box,int chn,int activate) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex);/* select box */ ICE1712_STDSP24_0_BOX (spec->boxbits, box);
@@ -111,15 +111,13 @@ static void snd_ice1712_stdsp24_box_channel(struct snd_ice1712 *ice, int box, inICE1712_STDSP24_2_MIDI1 (spec->boxbits,0 );snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[2 ]); - -mutex_unlock (&ice->gpio_mutex); }static void snd_ice1712_stdsp24_box_midi (struct snd_ice1712 *ice,int box,int master) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex);/* select box */ ICE1712_STDSP24_0_BOX (spec->boxbits, box);
@@ -139,17 +137,15 @@ static void snd_ice1712_stdsp24_box_midi(struct snd_ice1712 *ice, int box, int mICE1712_STDSP24_2_MIDIIN (spec->boxbits,1 );snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[2 ]); - -mutex_unlock (&ice->gpio_mutex); }static void snd_ice1712_stdsp24_midi2 (struct snd_ice1712 *ice,int activate) {struct hoontech_spec *spec = ice->spec; -mutex_lock (&ice->gpio_mutex); + +guard (mutex)(&ice->gpio_mutex);ICE1712_STDSP24_3_MIDI2 (spec->boxbits, activate);snd_ice1712_stdsp24_gpio_write (ice, spec->boxbits[3 ]); -mutex_unlock (&ice->gpio_mutex); }static int hoontech_init (struct snd_ice1712 *ice,bool staudio)
sound/pci/ice1712/ice1724.c +37 -33
147 lines not on this page · raw message
sound/pci/ice1712/maya44.c +6 -12
@@ -175,10 +175,9 @@ static int maya_vol_get(struct snd_kcontrol *kcontrol, &chip->wm[snd_ctl_get_ioff (kcontrol, &ucontrol->id)];unsigned int idx = kcontrol->private_value; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); ucontrol->value.integer.value[0 ] = wm->volumes[idx][0 ]; ucontrol->value.integer.value[1 ] = wm->volumes[idx][1 ]; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -193,7 +192,7 @@ static int maya_vol_put(struct snd_kcontrol *kcontrol,unsigned int val, data;int ch, changed =0 ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);for (ch =0 ; ch <2 ; ch++) { val = ucontrol->value.integer.value[ch];if (val > vol->maxval)
@@ -213,7 +212,6 @@ static int maya_vol_put(struct snd_kcontrol *kcontrol, val ? 0 : vol->mux_bits[ch]); wm->volumes[idx][ch] = val; } -mutex_unlock (&chip->mutex);return changed; }
@@ -250,7 +248,7 @@ static int maya_sw_put(struct snd_kcontrol *kcontrol,unsigned int mask, val;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); mask =1 << idx; wm->switch_bits &= ~mask; val = ucontrol->value.integer.value[0 ];
@@ -260,7 +258,6 @@ static int maya_sw_put(struct snd_kcontrol *kcontrol, changed =wm8776_write_bits (chip->ice, wm,GET_SW_VAL_REG (kcontrol->private_value), mask, val ? mask :0 ); -mutex_unlock (&chip->mutex);return changed; }
@@ -315,14 +312,13 @@ static int maya_gpio_sw_put(struct snd_kcontrol *kcontrol,unsigned int val, mask;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); mask =1 << shift; val = ucontrol->value.integer.value[0 ];if (GET_GPIO_VAL_INV (kcontrol->private_value)) val = !val; val = val ? mask :0 ; changed =maya_set_gpio_bits (chip->ice, mask, val); -mutex_unlock (&chip->mutex);return changed; }
@@ -369,11 +365,10 @@ static int maya_rec_src_put(struct snd_kcontrol *kcontrol,int sel = ucontrol->value.enumerated.item[0 ];int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed =maya_set_gpio_bits (chip->ice,1 <<GPIO_MIC_RELAY , sel ? (1 <<GPIO_MIC_RELAY ) :0 );wm8776_select_input (chip,0 , sel ?MAYA_MIC_IN :MAYA_LINE_IN ); -mutex_unlock (&chip->mutex);return changed; }
@@ -635,12 +630,11 @@ static void set_rate(struct snd_ice1712 *ice, unsigned int rate) val |=8 ; val |= ratio <<4 ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);for (i =0 ; i <2 ; i++)wm8776_write_bits (ice, &chip->wm[i],WM8776_REG_MASTER_MODE_CONTROL ,0x180 , val); -mutex_unlock (&chip->mutex); }/*
sound/pci/ice1712/phase.c +2 -4
@@ -287,10 +287,9 @@ static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol); -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); ucontrol->value.integer.value[0 ] = (wm_get (ice,WM_MUTE ) &0x10 ) ?0 :1 ; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
@@ -638,11 +637,10 @@ static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol,struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol);unsigned short val; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex); val =wm_get (ice,WM_DAC_DIG_MASTER_ATTEN ) &0xff ; val = val >PCM_MIN ? (val -PCM_MIN ) :0 ; ucontrol->value.integer.value[0 ] = val; -mutex_unlock (&ice->gpio_mutex);return 0 ; }
sound/pci/ice1712/pontis.c +28 -42
283 lines not on this page · raw message
sound/pci/ice1712/prodigy192.c +4 -7
@@ -110,21 +110,19 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e {struct snd_ice1712 *ice =snd_kcontrol_chip (kcontrol);struct prodigy192_spec *spec = ice->spec; -int idx, change; +int idx;if (kcontrol->private_value) idx =STAC946X_MASTER_VOLUME ;else idx =snd_ctl_get_ioffidx (kcontrol, &ucontrol->id) +STAC946X_LF_VOLUME ;/* due to possible conflicts with stac9460_set_rate_val, mutexing */ -mutex_lock (&spec->mute_mutex); +guard (mutex)(&spec->mute_mutex);/* dev_dbg(ice->card->dev, "Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx, ucontrol->value.integer.value[0]); */ - change =stac9460_dac_mute (ice, idx, ucontrol->value.integer.value[0 ]); -mutex_unlock (&spec->mute_mutex); -return change; +return stac9460_dac_mute (ice, idx, ucontrol->value.integer.value[0 ]); }/*
@@ -316,7 +314,7 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)return ;/* change detected, setting master clock, muting first */ /* due to possible conflicts with mute controls - mutexing */ -mutex_lock (&spec->mute_mutex); +guard (mutex)(&spec->mute_mutex);/* we have to remember current mute status for each DAC */ for (idx =0 ; idx <7 ; ++idx) changed[idx] = stac9460_dac_mute(ice,
@@ -330,7 +328,6 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)if (changed[idx])stac9460_dac_mute (ice,STAC946X_MASTER_VOLUME + idx,1 ); } -mutex_unlock (&spec->mute_mutex); }
sound/pci/ice1712/prodigy_hifi.c +20 -36
249 lines not on this page · raw message
sound/pci/ice1712/quartet.c +1 -2
@@ -396,7 +396,7 @@ static void reg_write(struct snd_ice1712 *ice, unsigned int reg, {unsigned int tmp; -mutex_lock (&ice->gpio_mutex); +guard (mutex)(&ice->gpio_mutex);/* set direction of used GPIOs*/ /* all outputs */ tmp =0x00ffff ;
@@ -429,7 +429,6 @@ static void reg_write(struct snd_ice1712 *ice, unsigned int reg, ice->gpio.set_mask (ice,0xffffff );/* outputs only 8-15 */ ice->gpio.set_dir (ice,0x00ff00 ); -mutex_unlock (&ice->gpio_mutex); }static unsigned int get_scr (struct snd_ice1712 *ice)
sound/pci/ice1712/wtm.c +2 -4
@@ -118,7 +118,7 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,unsigned char val;int idx, id; -mutex_lock (&spec->mute_mutex); +guard (mutex)(&spec->mute_mutex);if (kcontrol->private_value) { idx =STAC946X_MASTER_VOLUME ;
@@ -133,7 +133,6 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, val =stac9460_2_get (ice, idx -6 ); ucontrol->value.integer.value[0 ] = (~val >>7 ) &0x1 ; -mutex_unlock (&spec->mute_mutex);return 0 ; }
@@ -455,7 +454,7 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)return ;/* change detected, setting master clock, muting first */ /* due to possible conflicts with mute controls - mutexing */ -mutex_lock (&spec->mute_mutex); +guard (mutex)(&spec->mute_mutex);/* we have to remember current mute status for each DAC */ changed =0xFFFF ;stac9460_dac_mute_all (ice,0 , &changed);
@@ -466,7 +465,6 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)/* unmuting - only originally unmuted dacs - * i.e. those changed when muting */ stac9460_dac_mute_all (ice,1 , &changed); -mutex_unlock (&spec->mute_mutex); }
Signature · 1 line
2.50.1
PATCH 35/61 ALSA: ice1712: 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/pci/ice1712/delta.c | 53 ++++---- sound/pci/ice1712/ews.c | 53 ++++---- sound/pci/ice1712/ice1712.c | 186 ++++++++++++--------------- sound/pci/ice1712/ice1724.c | 244 +++++++++++++++++------------------- 4 files changed, 241 insertions(+), 295 deletions(-)
sound/pci/ice1712/delta.c +24 -29
@@ -202,15 +202,13 @@ static int delta_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_int change; val =snd_cs8403_encode_spdif_bits (&ucontrol->value.iec958); -spin_lock_irq (&ice->reg_lock); - change = ice->spdif.cs8403_bits != val; - ice->spdif.cs8403_bits = val; -if (change && ice->playback_pro_substream ==NULL ) { -spin_unlock_irq (&ice->reg_lock); -snd_ice1712_delta_cs8403_spdif_write (ice, val); - }else { -spin_unlock_irq (&ice->reg_lock); + scoped_guard(spinlock_irq, &ice->reg_lock) { + change = ice->spdif.cs8403_bits != val; + ice->spdif.cs8403_bits = val; +if (!change || ice->playback_pro_substream) +return change; } +snd_ice1712_delta_cs8403_spdif_write (ice, val);return change; }
@@ -225,15 +223,13 @@ static int delta_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_vint change; val =snd_cs8403_encode_spdif_bits (&ucontrol->value.iec958); -spin_lock_irq (&ice->reg_lock); - change = ice->spdif.cs8403_stream_bits != val; - ice->spdif.cs8403_stream_bits = val; -if (change && ice->playback_pro_substream !=NULL ) { -spin_unlock_irq (&ice->reg_lock); -snd_ice1712_delta_cs8403_spdif_write (ice, val); - }else { -spin_unlock_irq (&ice->reg_lock); + scoped_guard(spinlock_irq, &ice->reg_lock) { + change = ice->spdif.cs8403_stream_bits != val; + ice->spdif.cs8403_stream_bits = val; +if (!change || ice->playback_pro_substream) +return change; } +snd_ice1712_delta_cs8403_spdif_write (ice, val);return change; }
@@ -375,23 +371,22 @@ static void delta_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream */* set up */ static void delta_setup_spdif (struct snd_ice1712 *ice,int rate) { -unsigned long flags;unsigned int tmp;int change; -spin_lock_irqsave (&ice->reg_lock, flags); - tmp = ice->spdif.cs8403_stream_bits; -if (tmp &0x01 )/* consumer */ - tmp &= (tmp &0x01 ) ? ~0x06 : ~0x18 ; -switch (rate) { -case 32000 : tmp |= (tmp &0x01 ) ?0x04 :0x00 ;break ; -case 44100 : tmp |= (tmp &0x01 ) ?0x00 :0x10 ;break ; -case 48000 : tmp |= (tmp &0x01 ) ?0x02 :0x08 ;break ; -default : tmp |= (tmp &0x01 ) ?0x00 :0x18 ;break ; + scoped_guard(spinlock_irqsave, &ice->reg_lock) { + tmp = ice->spdif.cs8403_stream_bits; +if (tmp &0x01 )/* consumer */ + tmp &= (tmp &0x01 ) ? ~0x06 : ~0x18 ; +switch (rate) { +case 32000 : tmp |= (tmp &0x01 ) ?0x04 :0x00 ;break ; +case 44100 : tmp |= (tmp &0x01 ) ?0x00 :0x10 ;break ; +case 48000 : tmp |= (tmp &0x01 ) ?0x02 :0x08 ;break ; +default : tmp |= (tmp &0x01 ) ?0x00 :0x18 ;break ; + } + change = ice->spdif.cs8403_stream_bits != tmp; + ice->spdif.cs8403_stream_bits = tmp; } - change = ice->spdif.cs8403_stream_bits != tmp; - ice->spdif.cs8403_stream_bits = tmp; -spin_unlock_irqrestore (&ice->reg_lock, flags);if (change)snd_ctl_notify (ice->card,SNDRV_CTL_EVENT_MASK_VALUE , &ice->spdif.stream_ctl->id);snd_ice1712_delta_cs8403_spdif_write (ice, tmp);
sound/pci/ice1712/ews.c +24 -29
77 lines not on this page · raw message
sound/pci/ice1712/ice1712.c +80 -106
461 lines not on this page · raw message
sound/pci/ice1712/ice1724.c +113 -131
436 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 36/61 ALSA: intel8x0: 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/pci/intel8x0.c | 178 +++++++++++++++++++++--------------------- sound/pci/intel8x0m.c | 8 +- 2 files changed, 89 insertions(+), 97 deletions(-)
sound/pci/intel8x0.c +87 -91
@@ -690,52 +690,51 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ichstatic inline void snd_intel8x0_update (struct intel8x0 *chip,struct ichdev *ichdev) {unsigned long port = ichdev->reg_offset; -unsigned long flags;int status, civ, i, step;int ack =0 ;if (!(ichdev->prepared || chip->in_measurement) || ichdev->suspended)return ; -spin_lock_irqsave (&chip->reg_lock, flags); - status =igetbyte (chip, port + ichdev->roff_sr); - civ =igetbyte (chip, port +ICH_REG_OFF_CIV ); -if (!(status &ICH_BCIS )) { - step =0 ; - }else if (civ == ichdev->civ) { - step =1 ; - ichdev->civ++; - ichdev->civ &=ICH_REG_LVI_MASK ; - }else { - step = civ - ichdev->civ; -if (step <0 ) - step +=ICH_REG_LVI_MASK +1 ; - ichdev->civ = civ; - } + scoped_guard(spinlock_irqsave, &chip->reg_lock) { + status =igetbyte (chip, port + ichdev->roff_sr); + civ =igetbyte (chip, port +ICH_REG_OFF_CIV ); +if (!(status &ICH_BCIS )) { + step =0 ; + }else if (civ == ichdev->civ) { + step =1 ; + ichdev->civ++; + ichdev->civ &=ICH_REG_LVI_MASK ; + }else { + step = civ - ichdev->civ; +if (step <0 ) + step +=ICH_REG_LVI_MASK +1 ; + ichdev->civ = civ; + } - ichdev->position += step * ichdev->fragsize1; -if (! chip->in_measurement) - ichdev->position %= ichdev->size; - ichdev->lvi += step; - ichdev->lvi &=ICH_REG_LVI_MASK ; -iputbyte (chip, port +ICH_REG_OFF_LVI , ichdev->lvi); -for (i =0 ; i < step; i++) { - ichdev->lvi_frag++; - ichdev->lvi_frag %= ichdev->frags; - ichdev->bdbar[ichdev->lvi *2 ] =cpu_to_le32 (ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1); + ichdev->position += step * ichdev->fragsize1; +if (! chip->in_measurement) + ichdev->position %= ichdev->size; + ichdev->lvi += step; + ichdev->lvi &=ICH_REG_LVI_MASK ; +iputbyte (chip, port +ICH_REG_OFF_LVI , ichdev->lvi); +for (i =0 ; i < step; i++) { + ichdev->lvi_frag++; + ichdev->lvi_frag %= ichdev->frags; + ichdev->bdbar[ichdev->lvi *2 ] =cpu_to_le32 (ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);#if 0 -dev_dbg (chip->card->dev, -"new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n" , - ichdev->lvi *2 , ichdev->bdbar[ichdev->lvi *2 ], - ichdev->bdbar[ichdev->lvi *2 +1 ],inb (ICH_REG_OFF_PIV + port), -inl (port +4 ),inb (port +ICH_REG_OFF_CR )); +dev_dbg (chip->card->dev, +"new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n" , + ichdev->lvi *2 , ichdev->bdbar[ichdev->lvi *2 ], + ichdev->bdbar[ichdev->lvi *2 +1 ],inb (ICH_REG_OFF_PIV + port), +inl (port +4 ),inb (port +ICH_REG_OFF_CR ));#endif -if (--ichdev->ack ==0 ) { - ichdev->ack = ichdev->ack_reload; - ack =1 ; +if (--ichdev->ack ==0 ) { + ichdev->ack = ichdev->ack_reload; + ack =1 ; + } } } -spin_unlock_irqrestore (&chip->reg_lock, flags);if (ack && ichdev->substream) {snd_pcm_period_elapsed (ichdev->substream); }
@@ -917,7 +916,7 @@ static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,unsigned int cnt;int dbl = runtime->rate >48000 ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);switch (chip->device_type) {case DEVICE_ALI : cnt =igetdword (chip,ICHREG (ALI_SCR ));
@@ -963,7 +962,6 @@ static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,iputdword (chip,ICHREG (GLOB_CNT ), cnt);break ; } -spin_unlock_irq (&chip->reg_lock); }static int snd_intel8x0_pcm_prepare (struct snd_pcm_substream *substream)
@@ -993,7 +991,7 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subsint civ, timeout =10 ;unsigned int position; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); do { civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV); ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
@@ -1033,7 +1031,6 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs } } ichdev->last_pos = ptr; -spin_unlock (&chip->reg_lock);if (ptr >= ichdev->size)return 0 ;return bytes_to_frames (substream->runtime, ptr);
@@ -1235,12 +1232,12 @@ static int snd_intel8x0_ali_ac97spdifout_open(struct snd_pcm_substream *substreastruct intel8x0 *chip =snd_pcm_substream_chip (substream);unsigned int val; -spin_lock_irq (&chip->reg_lock); - val =igetdword (chip,ICHREG (ALI_INTERFACECR )); - val |=ICH_ALI_IF_AC97SP ; -iputdword (chip,ICHREG (ALI_INTERFACECR ), val); -/* also needs to set ALI_SC_CODEC_SPDF correctly */ -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + val =igetdword (chip,ICHREG (ALI_INTERFACECR )); + val |=ICH_ALI_IF_AC97SP ; +iputdword (chip,ICHREG (ALI_INTERFACECR ), val); +/* also needs to set ALI_SC_CODEC_SPDF correctly */ + }return snd_intel8x0_pcm_open (substream, &chip->ichd[ALID_AC97SPDIFOUT ]); }
@@ -1251,11 +1248,10 @@ static int snd_intel8x0_ali_ac97spdifout_close(struct snd_pcm_substream *substreunsigned int val; chip->ichd[ALID_AC97SPDIFOUT ].substream =NULL ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); val =igetdword (chip,ICHREG (ALI_INTERFACECR )); val &= ~ICH_ALI_IF_AC97SP ;iputdword (chip,ICHREG (ALI_INTERFACECR ), val); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -2662,53 +2658,53 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip) }snd_intel8x0_setup_periods (chip, ichdev); port = ichdev->reg_offset; -spin_lock_irq (&chip->reg_lock); - chip->in_measurement =1 ; -/* trigger */ -if (chip->device_type !=DEVICE_ALI ) -iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_IOCE |ICH_STARTBM ); -else { -iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_IOCE ); -iputdword (chip,ICHREG (ALI_DMACR ),1 << ichdev->ali_slot); - } - start_time =ktime_get (); -spin_unlock_irq (&chip->reg_lock); -msleep (50 ); -spin_lock_irq (&chip->reg_lock); -/* check the position */ -do { - civ =igetbyte (chip, ichdev->reg_offset +ICH_REG_OFF_CIV ); - pos1 =igetword (chip, ichdev->reg_offset + ichdev->roff_picb); -if (pos1 ==0 ) { -udelay (10 ); -continue ; + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->in_measurement =1 ; +/* trigger */ +if (chip->device_type !=DEVICE_ALI ) +iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_IOCE |ICH_STARTBM ); +else { +iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_IOCE ); +iputdword (chip,ICHREG (ALI_DMACR ),1 << ichdev->ali_slot); } -if (civ ==igetbyte (chip, ichdev->reg_offset +ICH_REG_OFF_CIV ) && - pos1 ==igetword (chip, ichdev->reg_offset + ichdev->roff_picb)) -break ; - }while (timeout--); -if (pos1 ==0 ) {/* oops, this value is not reliable */ - pos =0 ; - }else { - pos = ichdev->fragsize1; - pos -= pos1 << ichdev->pos_shift; - pos += ichdev->position; + start_time =ktime_get (); } - chip->in_measurement =0 ; - stop_time =ktime_get (); -/* stop */ -if (chip->device_type ==DEVICE_ALI ) { -iputdword (chip,ICHREG (ALI_DMACR ),1 << (ichdev->ali_slot +16 )); -iputbyte (chip, port +ICH_REG_OFF_CR ,0 ); -while (igetbyte (chip, port +ICH_REG_OFF_CR )) - ; - }else { -iputbyte (chip, port +ICH_REG_OFF_CR ,0 ); -while (!(igetbyte (chip, port + ichdev->roff_sr) &ICH_DCH )) - ; +msleep (50 ); + scoped_guard(spinlock_irq, &chip->reg_lock) { +/* check the position */ +do { + civ =igetbyte (chip, ichdev->reg_offset +ICH_REG_OFF_CIV ); + pos1 =igetword (chip, ichdev->reg_offset + ichdev->roff_picb); +if (pos1 ==0 ) { +udelay (10 ); +continue ; + } +if (civ ==igetbyte (chip, ichdev->reg_offset +ICH_REG_OFF_CIV ) && + pos1 ==igetword (chip, ichdev->reg_offset + ichdev->roff_picb)) +break ; + }while (timeout--); +if (pos1 ==0 ) {/* oops, this value is not reliable */ + pos =0 ; + }else { + pos = ichdev->fragsize1; + pos -= pos1 << ichdev->pos_shift; + pos += ichdev->position; + } + chip->in_measurement =0 ; + stop_time =ktime_get (); +/* stop */ +if (chip->device_type ==DEVICE_ALI ) { +iputdword (chip,ICHREG (ALI_DMACR ),1 << (ichdev->ali_slot +16 )); +iputbyte (chip, port +ICH_REG_OFF_CR ,0 ); +while (igetbyte (chip, port +ICH_REG_OFF_CR )) + ; + }else { +iputbyte (chip, port +ICH_REG_OFF_CR ,0 ); +while (!(igetbyte (chip, port + ichdev->roff_sr) &ICH_DCH )) + ; + } +iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_RESETREGS ); } -iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_RESETREGS ); -spin_unlock_irq (&chip->reg_lock);if (pos ==0 ) { dev_err(chip->card->dev,
sound/pci/intel8x0m.c +2 -6
@@ -471,16 +471,13 @@ static irqreturn_t snd_intel8x0m_interrupt(int irq, void *dev_id)unsigned int status;unsigned int i; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); status =igetdword (chip, chip->int_sta_reg); -if (status ==0xffffffff ) {/* we are not yet resumed */ -spin_unlock (&chip->reg_lock); +if (status ==0xffffffff )/* we are not yet resumed */ return IRQ_NONE ; - }if ((status & chip->int_sta_mask) ==0 ) {if (status)iputdword (chip, chip->int_sta_reg, status); -spin_unlock (&chip->reg_lock);return IRQ_NONE ; }
@@ -492,7 +489,6 @@ static irqreturn_t snd_intel8x0m_interrupt(int irq, void *dev_id)/* ack them */ iputdword (chip, chip->int_sta_reg, status & chip->int_sta_mask); -spin_unlock (&chip->reg_lock);return IRQ_HANDLED ; }
Signature · 1 line
2.50.1
PATCH 37/61 ALSA: korg1212: 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/pci/korg1212/korg1212.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
sound/pci/korg1212/korg1212.c +4 -10
@@ -606,13 +606,12 @@ static int snd_korg1212_OpenCard(struct snd_korg1212 * korg1212) {K1212_DEBUG_PRINTK ("K1212_DEBUG: OpenCard [%s] %d\n" , stateName[korg1212->cardState], korg1212->opencnt); -mutex_lock (&korg1212->open_mutex); +guard (mutex)(&korg1212->open_mutex);if (korg1212->opencnt++ ==0 ) {snd_korg1212_TurnOffIdleMonitor (korg1212);snd_korg1212_setCardState (korg1212,K1212_STATE_OPEN ); } -mutex_unlock (&korg1212->open_mutex);return 1 ; }
@@ -621,11 +620,9 @@ static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212)K1212_DEBUG_PRINTK ("K1212_DEBUG: CloseCard [%s] %d\n" , stateName[korg1212->cardState], korg1212->opencnt); -mutex_lock (&korg1212->open_mutex); -if (--(korg1212->opencnt)) { -mutex_unlock (&korg1212->open_mutex); +guard (mutex)(&korg1212->open_mutex); +if (--(korg1212->opencnt))return 0 ; - }if (korg1212->cardState ==K1212_STATE_SETUP ) { int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
@@ -633,10 +630,8 @@ static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212)if (rc)K1212_DEBUG_PRINTK ("K1212_DEBUG: CloseCard - RC = %d [%s]\n" , rc, stateName[korg1212->cardState]); -if (rc != K1212_CMDRET_Success) { -mutex_unlock (&korg1212->open_mutex); +if (rc != K1212_CMDRET_Success)return 0 ; - } }else if (korg1212->cardState >K1212_STATE_SETUP ) {snd_korg1212_SendStopAndWait (korg1212); }
@@ -646,7 +641,6 @@ static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212)snd_korg1212_setCardState (korg1212,K1212_STATE_READY ); } -mutex_unlock (&korg1212->open_mutex);return 0 ; }
Signature · 1 line
2.50.1
PATCH 38/61 ALSA: korg1212: 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/pci/korg1212/korg1212.c | 168 ++++++++++++---------------------- 1 file changed, 58 insertions(+), 110 deletions(-)
sound/pci/korg1212/korg1212.c +58 -110
@@ -568,25 +568,19 @@ static void snd_korg1212_SendStop(struct snd_korg1212 *korg1212)static void snd_korg1212_SendStopAndWait (struct snd_korg1212 *korg1212) { -unsigned long flags; -spin_lock_irqsave (&korg1212->lock, flags); -snd_korg1212_SendStop (korg1212); -spin_unlock_irqrestore (&korg1212->lock, flags); + scoped_guard(spinlock_irqsave, &korg1212->lock) { +snd_korg1212_SendStop (korg1212); + }wait_event_timeout (korg1212->wait, !korg1212->dsp_stop_processing,HZ ); }static int snd_korg1212_TurnOnIdleMonitor (struct snd_korg1212 *korg1212) { -unsigned long flags; -int rc; -udelay (INTERCOMMAND_DELAY ); -spin_lock_irqsave (&korg1212->lock, flags); +guard (spinlock_irqsave)(&korg1212->lock); korg1212->idleMonitorOn =1 ; - rc =snd_korg1212_Send1212Command (korg1212, K1212_DB_SelectPlayMode, - K1212_MODE_MonitorOn,0 ,0 ,0 ); -spin_unlock_irqrestore (&korg1212->lock, flags); -return rc; +return snd_korg1212_Send1212Command (korg1212, K1212_DB_SelectPlayMode, + K1212_MODE_MonitorOn,0 ,0 ,0 ); }static void snd_korg1212_TurnOffIdleMonitor (struct snd_korg1212 *korg1212)
@@ -838,7 +832,6 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212)u16 controlValue;// this keeps the current value to be written to // the card's eeprom control register. u16 count; -unsigned long flags;K1212_DEBUG_PRINTK ("K1212_DEBUG: WriteADCSensivity [%s]\n" , stateName[korg1212->cardState]);
@@ -859,7 +852,7 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212) }else monModeSet =0 ; -spin_lock_irqsave (&korg1212->lock, flags); +guard (spinlock_irqsave)(&korg1212->lock);// ---------------------------------------------------------------------------- // we are about to send new values to the card, so clear the new values queued
@@ -968,8 +961,6 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212) rc, stateName[korg1212->cardState]); } -spin_unlock_irqrestore (&korg1212->lock, flags); -return 1 ; }
@@ -1061,7 +1052,7 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id)if (!doorbellValue)return IRQ_NONE ; -spin_lock (&korg1212->lock); +guard (spinlock)(&korg1212->lock);writel (doorbellValue, korg1212->inDoorbellPtr);
@@ -1139,8 +1130,6 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id) korg1212->inIRQ--; -spin_unlock (&korg1212->lock); -return IRQ_HANDLED ; }
@@ -1326,7 +1315,6 @@ static void snd_korg1212_free_pcm(struct snd_pcm *pcm)static int snd_korg1212_playback_open (struct snd_pcm_substream *substream) { -unsigned long flags;struct snd_korg1212 *korg1212 =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime;
@@ -1338,15 +1326,13 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream) runtime->hw = snd_korg1212_playback_info;snd_pcm_set_runtime_buffer (substream, korg1212->dma_play); -spin_lock_irqsave (&korg1212->lock, flags); - - korg1212->playback_substream = substream; - korg1212->playback_pid = current->pid; - korg1212->periodsize =K1212_PERIODS ; - korg1212->channels =K1212_CHANNELS ; - korg1212->errorcnt =0 ; - -spin_unlock_irqrestore (&korg1212->lock, flags); + scoped_guard(spinlock_irqsave, &korg1212->lock) { + korg1212->playback_substream = substream; + korg1212->playback_pid = current->pid; + korg1212->periodsize =K1212_PERIODS ; + korg1212->channels =K1212_CHANNELS ; + korg1212->errorcnt =0 ; + }snd_pcm_hw_constraint_single (runtime,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , kPlayBufferFrames);
@@ -1357,7 +1343,6 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream)static int snd_korg1212_capture_open (struct snd_pcm_substream *substream) { -unsigned long flags;struct snd_korg1212 *korg1212 =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime;
@@ -1369,14 +1354,12 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream) runtime->hw = snd_korg1212_capture_info;snd_pcm_set_runtime_buffer (substream, korg1212->dma_rec); -spin_lock_irqsave (&korg1212->lock, flags); - - korg1212->capture_substream = substream; - korg1212->capture_pid = current->pid; - korg1212->periodsize =K1212_PERIODS ; - korg1212->channels =K1212_CHANNELS ; - -spin_unlock_irqrestore (&korg1212->lock, flags); + scoped_guard(spinlock_irqsave, &korg1212->lock) { + korg1212->capture_substream = substream; + korg1212->capture_pid = current->pid; + korg1212->periodsize =K1212_PERIODS ; + korg1212->channels =K1212_CHANNELS ; + }snd_pcm_hw_constraint_single (runtime,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , kPlayBufferFrames);
@@ -1385,7 +1368,6 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream)static int snd_korg1212_playback_close (struct snd_pcm_substream *substream) { -unsigned long flags;struct snd_korg1212 *korg1212 =snd_pcm_substream_chip (substream); K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n",
@@ -1393,13 +1375,11 @@ static int snd_korg1212_playback_close(struct snd_pcm_substream *substream)snd_korg1212_silence (korg1212,0 ,K1212_MAX_SAMPLES ,0 , korg1212->channels *2 ); -spin_lock_irqsave (&korg1212->lock, flags); - - korg1212->playback_pid =-1 ; - korg1212->playback_substream =NULL ; - korg1212->periodsize =0 ; - -spin_unlock_irqrestore (&korg1212->lock, flags); + scoped_guard(spinlock_irqsave, &korg1212->lock) { + korg1212->playback_pid =-1 ; + korg1212->playback_substream =NULL ; + korg1212->periodsize =0 ; + }snd_korg1212_CloseCard (korg1212);return 0 ;
@@ -1407,19 +1387,16 @@ static int snd_korg1212_playback_close(struct snd_pcm_substream *substream)static int snd_korg1212_capture_close (struct snd_pcm_substream *substream) { -unsigned long flags;struct snd_korg1212 *korg1212 =snd_pcm_substream_chip (substream);K1212_DEBUG_PRINTK ("K1212_DEBUG: snd_korg1212_capture_close [%s]\n" , stateName[korg1212->cardState]); -spin_lock_irqsave (&korg1212->lock, flags); - - korg1212->capture_pid =-1 ; - korg1212->capture_substream =NULL ; - korg1212->periodsize =0 ; - -spin_unlock_irqrestore (&korg1212->lock, flags); + scoped_guard(spinlock_irqsave, &korg1212->lock) { + korg1212->capture_pid =-1 ; + korg1212->capture_substream =NULL ; + korg1212->periodsize =0 ; + }snd_korg1212_CloseCard (korg1212);return 0 ;
@@ -1445,7 +1422,6 @@ static int snd_korg1212_ioctl(struct snd_pcm_substream *substream,static int snd_korg1212_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -unsigned long flags;struct snd_korg1212 *korg1212 =snd_pcm_substream_chip (substream);int err;pid_t this_pid;
@@ -1454,7 +1430,7 @@ static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,K1212_DEBUG_PRINTK ("K1212_DEBUG: snd_korg1212_hw_params [%s]\n" , stateName[korg1212->cardState]); -spin_lock_irqsave (&korg1212->lock, flags); +guard (spinlock_irqsave)(&korg1212->lock);if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { this_pid = korg1212->playback_pid;
@@ -1472,26 +1448,20 @@ static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,*/ if ((int )params_rate (params) != korg1212->clkRate) { -spin_unlock_irqrestore (&korg1212->lock, flags);_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_RATE );return -EBUSY ; } -spin_unlock_irqrestore (&korg1212->lock, flags);return 0 ; } err =snd_korg1212_SetRate (korg1212,params_rate (params)); -if (err <0 ) { -spin_unlock_irqrestore (&korg1212->lock, flags); +if (err <0 )return err; - } korg1212->channels =params_channels (params); korg1212->periodsize =K1212_PERIOD_BYTES ; -spin_unlock_irqrestore (&korg1212->lock, flags); -return 0 ; }
@@ -1511,15 +1481,13 @@ static int snd_korg1212_prepare(struct snd_pcm_substream *substream)K1212_DEBUG_PRINTK ("K1212_DEBUG: snd_korg1212_prepare [%s]\n" , stateName[korg1212->cardState]); -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); korg1212->dsp_stop_processing =0 ; rc =snd_korg1212_SetupForPlay (korg1212); korg1212->currentBuffer =0 ; -spin_unlock_irq (&korg1212->lock); -return rc ? -EINVAL :0 ; }
@@ -1532,7 +1500,7 @@ static int snd_korg1212_trigger(struct snd_pcm_substream *substream,K1212_DEBUG_PRINTK ("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n" , stateName[korg1212->cardState], cmd); -spin_lock (&korg1212->lock); +guard (spinlock)(&korg1212->lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :/*
@@ -1560,7 +1528,6 @@ static int snd_korg1212_trigger(struct snd_pcm_substream *substream, rc =1 ;break ; } -spin_unlock (&korg1212->lock);return rc ? -EINVAL :0 ; }
@@ -1660,15 +1627,13 @@ static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol,struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol);int i = kcontrol->private_value; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); u->value.integer.value[0 ] = korg1212->volumePhase[i];if (i >=8 ) u->value.integer.value[1 ] = korg1212->volumePhase[i+1 ]; -spin_unlock_irq (&korg1212->lock); -return 0 ; }
@@ -1679,7 +1644,7 @@ static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol,int change =0 ;int i, val; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); i = kcontrol->private_value;
@@ -1705,8 +1670,6 @@ static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, } } -spin_unlock_irq (&korg1212->lock); -return change; }
@@ -1726,7 +1689,7 @@ static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol,struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol);int i; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); i = kcontrol->private_value; u->value.integer.value[0 ] =abs (korg1212->sharedBufferPtr->volumeData[i]);
@@ -1734,8 +1697,6 @@ static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol,if (i >=8 ) u->value.integer.value[1 ] =abs (korg1212->sharedBufferPtr->volumeData[i+1 ]); -spin_unlock_irq (&korg1212->lock); -return 0 ; }
@@ -1747,7 +1708,7 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol,int i;int val; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); i = kcontrol->private_value;
@@ -1773,8 +1734,6 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, } } -spin_unlock_irq (&korg1212->lock); -return change; }
@@ -1792,7 +1751,7 @@ static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol,struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol);int i; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); i = kcontrol->private_value; u->value.enumerated.item[0 ] = korg1212->sharedBufferPtr->routeData[i];
@@ -1800,8 +1759,6 @@ static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol,if (i >=8 ) u->value.enumerated.item[1 ] = korg1212->sharedBufferPtr->routeData[i+1 ]; -spin_unlock_irq (&korg1212->lock); -return 0 ; }
@@ -1811,7 +1768,7 @@ static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol,struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol);int change =0 , i; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); i = kcontrol->private_value;
@@ -1831,8 +1788,6 @@ static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol, } } -spin_unlock_irq (&korg1212->lock); -return change; }
@@ -1851,13 +1806,11 @@ static int snd_korg1212_control_get(struct snd_kcontrol *kcontrol, {struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); u->value.integer.value[0 ] = korg1212->leftADCInSens; u->value.integer.value[1 ] = korg1212->rightADCInSens; -spin_unlock_irq (&korg1212->lock); -return 0 ; }
@@ -1867,22 +1820,20 @@ static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol,struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol);int change =0 ; -spin_lock_irq (&korg1212->lock); - -if (u->value.integer.value[0 ] >= k1212MinADCSens && - u->value.integer.value[0 ] <= k1212MaxADCSens && - u->value.integer.value[0 ] != korg1212->leftADCInSens) { - korg1212->leftADCInSens = u->value.integer.value[0 ]; - change =1 ; - } -if (u->value.integer.value[1 ] >= k1212MinADCSens && - u->value.integer.value[1 ] <= k1212MaxADCSens && - u->value.integer.value[1 ] != korg1212->rightADCInSens) { - korg1212->rightADCInSens = u->value.integer.value[1 ]; - change =1 ; - } - -spin_unlock_irq (&korg1212->lock); + scoped_guard(spinlock_irq, &korg1212->lock) { +if (u->value.integer.value[0 ] >= k1212MinADCSens && + u->value.integer.value[0 ] <= k1212MaxADCSens && + u->value.integer.value[0 ] != korg1212->leftADCInSens) { + korg1212->leftADCInSens = u->value.integer.value[0 ]; + change =1 ; + } +if (u->value.integer.value[1 ] >= k1212MinADCSens && + u->value.integer.value[1 ] <= k1212MaxADCSens && + u->value.integer.value[1 ] != korg1212->rightADCInSens) { + korg1212->rightADCInSens = u->value.integer.value[1 ]; + change =1 ; + } + }if (change)snd_korg1212_WriteADCSensitivity (korg1212);
@@ -1901,11 +1852,9 @@ static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol, {struct snd_korg1212 *korg1212 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); ucontrol->value.enumerated.item[0 ] = korg1212->clkSource; - -spin_unlock_irq (&korg1212->lock);return 0 ; }
@@ -1917,10 +1866,9 @@ static int snd_korg1212_control_sync_put(struct snd_kcontrol *kcontrol,int change; val = ucontrol->value.enumerated.item[0 ] %3 ; -spin_lock_irq (&korg1212->lock); +guard (spinlock_irq)(&korg1212->lock); change = val != korg1212->clkSource;snd_korg1212_SetClockSource (korg1212, val); -spin_unlock_irq (&korg1212->lock);return change; }
Signature · 1 line
2.50.1
PATCH 39/61 ALSA: lola: 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/pci/lola/lola_pcm.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
sound/pci/lola/lola_pcm.c +13 -20
@@ -214,11 +214,9 @@ static int lola_pcm_open(struct snd_pcm_substream *substream)struct lola_stream *str =lola_get_stream (substream);struct snd_pcm_runtime *runtime = substream->runtime; -mutex_lock (&chip->open_mutex); -if (str->opened) { -mutex_unlock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex); +if (str->opened)return -EBUSY ; - } str->substream = substream; str->master =NULL ; str->opened =1 ;
@@ -239,7 +237,6 @@ static int lola_pcm_open(struct snd_pcm_substream *substream) chip->granularity);snd_pcm_hw_constraint_step (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , chip->granularity); -mutex_unlock (&chip->open_mutex);return 0 ; }
@@ -261,7 +258,7 @@ static int lola_pcm_close(struct snd_pcm_substream *substream)struct lola *chip =snd_pcm_substream_chip (substream);struct lola_stream *str =lola_get_stream (substream); -mutex_lock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex);if (str->substream == substream) { str->substream =NULL ; str->opened =0 ;
@@ -270,7 +267,6 @@ static int lola_pcm_close(struct snd_pcm_substream *substream)/* release sample rate */ chip->sample_rate =0 ; } -mutex_unlock (&chip->open_mutex);return 0 ; }
@@ -291,10 +287,9 @@ static int lola_pcm_hw_free(struct snd_pcm_substream *substream)struct lola_pcm *pcm =lola_get_pcm (substream);struct lola_stream *str =lola_get_stream (substream); -mutex_lock (&chip->open_mutex); +guard (mutex)(&chip->open_mutex);lola_stream_reset (chip, str);lola_cleanup_slave_streams (pcm, str); -mutex_unlock (&chip->open_mutex);return 0 ; }
@@ -457,18 +452,16 @@ static int lola_pcm_prepare(struct snd_pcm_substream *substream)unsigned int bufsize, period_bytes, format_verb;int i, err; -mutex_lock (&chip->open_mutex); -lola_stream_reset (chip, str); -lola_cleanup_slave_streams (pcm, str); -if (str->index + runtime->channels > pcm->num_streams) { -mutex_unlock (&chip->open_mutex); -return -EINVAL ; + scoped_guard(mutex, &chip->open_mutex) { +lola_stream_reset (chip, str); +lola_cleanup_slave_streams (pcm, str); +if (str->index + runtime->channels > pcm->num_streams) +return -EINVAL ; +for (i =1 ; i < runtime->channels; i++) { + str[i].master = str; + str[i].opened =1 ; + } } -for (i =1 ; i < runtime->channels; i++) { - str[i].master = str; - str[i].opened =1 ; - } -mutex_unlock (&chip->open_mutex); bufsize =snd_pcm_lib_buffer_bytes (substream); period_bytes =snd_pcm_lib_period_bytes (substream);
Signature · 1 line
2.50.1
PATCH 40/61 ALSA: lola: 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/pci/lola/lola.c | 4 +--- sound/pci/lola/lola_pcm.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-)
sound/pci/lola/lola.c +1 -3
@@ -74,7 +74,6 @@ static int corb_send_verb(struct lola *chip, unsigned int nid, unsigned int verb, unsigned int data, unsigned int extdata) { - unsigned long flags; int ret = -EIO; chip->last_cmd_nid = nid;
@@ -83,7 +82,7 @@ static int corb_send_verb(struct lola *chip, unsigned int nid, chip->last_extdata = extdata; data |= (nid <<20 ) | (verb <<8 ); -spin_lock_irqsave (&chip->reg_lock, flags); +guard (spinlock_irqsave)(&chip->reg_lock);if (chip->rirb.cmds <LOLA_CORB_ENTRIES -1 ) {unsigned int wp = chip->corb.wp +1 ; wp %=LOLA_CORB_ENTRIES ;
@@ -95,7 +94,6 @@ static int corb_send_verb(struct lola *chip, unsigned int nid,smp_wmb (); ret =0 ; } -spin_unlock_irqrestore (&chip->reg_lock, flags);return ret; }
sound/pci/lola/lola_pcm.c +1 -2
@@ -523,7 +523,7 @@ static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd)*/ sync_streams = (start &&snd_pcm_stream_linked (substream)); tstamp =lola_get_tstamp (chip, !sync_streams); -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);snd_pcm_group_for_each_entry (s, substream) {if (s->pcm->card != substream->pcm->card)continue ;
@@ -536,7 +536,6 @@ static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd) str->paused = !start;snd_pcm_trigger_done (s, substream); } -spin_unlock (&chip->reg_lock);return 0 ; }
Signature · 1 line
2.50.1
PATCH 41/61 ALSA: lx6464es: 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/pci/lx6464es/lx6464es.c | 49 ++++++---------- sound/pci/lx6464es/lx_core.c | 107 ++++++++++------------------------ 2 files changed, 48 insertions(+), 108 deletions(-)
sound/pci/lx6464es/lx6464es.c +18 -31
@@ -207,7 +207,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)int board_rate;dev_dbg (chip->card->dev,"->lx_pcm_open\n" ); -mutex_lock (&chip->setup_mutex); +guard (mutex)(&chip->setup_mutex);/* copy the struct snd_pcm_hardware struct */ runtime->hw = lx_caps;
@@ -218,7 +218,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream) SNDRV_PCM_HW_PARAM_PERIODS);if (err <0 ) {dev_warn (chip->card->dev,"could not constrain periods\n" ); - goto exit; +return err; }#endif
@@ -229,7 +229,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)if (err <0 ) {dev_warn (chip->card->dev,"could not constrain periods\n" ); - goto exit; +return err; }/* constrain period size */
@@ -240,7 +240,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)if (err <0 ) {dev_warn (chip->card->dev,"could not constrain period size\n" ); - goto exit; +return err; } snd_pcm_hw_constraint_step(runtime, 0,
@@ -249,10 +249,8 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)snd_pcm_set_sync (substream); err =0 ; -exit: runtime->private_data = chip; -mutex_unlock (&chip->setup_mutex);dev_dbg (chip->card->dev,"<-lx_pcm_open, %d\n" , err);return err; }
@@ -275,9 +273,8 @@ static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substreamdev_dbg (chip->card->dev,"->lx_pcm_stream_pointer\n" ); -mutex_lock (&chip->lock); +guard (mutex)(&chip->lock); pos = lx_stream->frame_pos * substream->runtime->period_size; -mutex_unlock (&chip->lock);dev_dbg (chip->card->dev,"stream_pointer at %ld\n" , pos);return pos;
@@ -291,21 +288,21 @@ static int lx_pcm_prepare(struct snd_pcm_substream *substream)dev_dbg (chip->card->dev,"->lx_pcm_prepare\n" ); -mutex_lock (&chip->setup_mutex); +guard (mutex)(&chip->setup_mutex);if (chip->hardware_running[is_capture]) { err =lx_hardware_stop (chip, substream);if (err <0 ) {dev_err (chip->card->dev,"failed to stop hardware. " "Error code %d\n" , err); - goto exit; +return err; } err =lx_hardware_close (chip, substream);if (err <0 ) {dev_err (chip->card->dev,"failed to close hardware. " "Error code %d\n" , err); - goto exit; +return err; } }
@@ -314,14 +311,14 @@ static int lx_pcm_prepare(struct snd_pcm_substream *substream)if (err <0 ) {dev_err (chip->card->dev,"failed to open hardware. " "Error code %d\n" , err); - goto exit; +return err; } err =lx_hardware_start (chip, substream);if (err <0 ) {dev_err (chip->card->dev,"failed to start hardware. " "Error code %d\n" , err); - goto exit; +return err; } chip->hardware_running[is_capture] =1 ;
@@ -331,8 +328,6 @@ static int lx_pcm_prepare(struct snd_pcm_substream *substream) chip->board_sample_rate = substream->runtime->rate; } -exit: -mutex_unlock (&chip->setup_mutex);return err; }
@@ -343,14 +338,13 @@ static int lx_pcm_hw_params(struct snd_pcm_substream *substream,dev_dbg (chip->card->dev,"->lx_pcm_hw_params\n" ); -mutex_lock (&chip->setup_mutex); +guard (mutex)(&chip->setup_mutex);if (is_capture) chip->capture_stream.stream = substream;else chip->playback_stream.stream = substream; -mutex_unlock (&chip->setup_mutex);return 0 ; }
@@ -373,21 +367,21 @@ static int lx_pcm_hw_free(struct snd_pcm_substream *substream)int is_capture = (substream->stream ==SNDRV_PCM_STREAM_CAPTURE );dev_dbg (chip->card->dev,"->lx_pcm_hw_free\n" ); -mutex_lock (&chip->setup_mutex); +guard (mutex)(&chip->setup_mutex);if (chip->hardware_running[is_capture]) { err =lx_hardware_stop (chip, substream);if (err <0 ) {dev_err (chip->card->dev,"failed to stop hardware. " "Error code %d\n" , err); - goto exit; +return err; } err =lx_hardware_close (chip, substream);if (err <0 ) {dev_err (chip->card->dev,"failed to close hardware. " "Error code %d\n" , err); - goto exit; +return err; } chip->hardware_running[is_capture] =0 ;
@@ -398,9 +392,7 @@ static int lx_pcm_hw_free(struct snd_pcm_substream *substream)else chip->playback_stream.stream =NULL ; -exit: -mutex_unlock (&chip->setup_mutex); -return err; +return 0 ; }static void lx_trigger_start (struct lx6464es *chip,struct lx_stream *lx_stream)
@@ -486,9 +478,7 @@ static void lx_trigger_dispatch_stream(struct lx6464es *chip,static int lx_pcm_trigger_dispatch (struct lx6464es *chip,struct lx_stream *lx_stream,int cmd) { -int err =0 ; - -mutex_lock (&chip->lock); +guard (mutex)(&chip->lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START : lx_stream->status =LX_STREAM_STATUS_SCHEDULE_RUN ;
@@ -499,16 +489,13 @@ static int lx_pcm_trigger_dispatch(struct lx6464es *chip,break ;default : - err = -EINVAL ; - goto exit; +return -EINVAL ; }lx_trigger_dispatch_stream (chip, &chip->capture_stream);lx_trigger_dispatch_stream (chip, &chip->playback_stream); -exit: -mutex_unlock (&chip->lock); -return err; +return 0 ; }
sound/pci/lx6464es/lx_core.c +30 -77
367 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 42/61 ALSA: maestro3: 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/pci/maestro3.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
sound/pci/maestro3.c +7 -16
@@ -1096,7 +1096,7 @@ snd_m3_pcm_trigger(struct snd_pcm_substream *subs, int cmd)if (snd_BUG_ON (!s))return -ENXIO ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -1117,7 +1117,6 @@ snd_m3_pcm_trigger(struct snd_pcm_substream *subs, int cmd) }break ; } -spin_unlock (&chip->reg_lock);return err; }
@@ -1412,7 +1411,7 @@ snd_m3_pcm_prepare(struct snd_pcm_substream *subs) runtime->rate < 8000)return -EINVAL ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);snd_m3_pcm_setup1 (chip, s, subs);
@@ -1423,8 +1422,6 @@ snd_m3_pcm_prepare(struct snd_pcm_substream *subs)snd_m3_pcm_setup2 (chip, s, runtime); -spin_unlock_irq (&chip->reg_lock); -return 0 ; }
@@ -1466,9 +1463,8 @@ snd_m3_pcm_pointer(struct snd_pcm_substream *subs)if (snd_BUG_ON (!s))return 0 ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); ptr =snd_m3_get_pointer (chip, s, subs); -spin_unlock (&chip->reg_lock);return bytes_to_frames (subs->runtime, ptr); }
@@ -1629,13 +1625,12 @@ static irqreturn_t snd_m3_interrupt(int irq, void *dev_id)if (ctl &DSP2HOST_REQ_TIMER ) {outb (DSP2HOST_REQ_TIMER , chip->iobase +ASSP_HOST_INT_STATUS );/* update adc/dac info if it was a timer int */ -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);for (i =0 ; i < chip->num_substreams; i++) {struct m3_dma *s = &chip->substreams[i];if (s->running)snd_m3_update_ptr (chip, s); } -spin_unlock (&chip->reg_lock); } } }
@@ -1707,18 +1702,16 @@ snd_m3_substream_open(struct snd_m3 *chip, struct snd_pcm_substream *subs)int i;struct m3_dma *s; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i < chip->num_substreams; i++) { s = &chip->substreams[i];if (! s->opened) goto __found; } -spin_unlock_irq (&chip->reg_lock);return -ENOMEM ; __found: s->opened =1 ; s->running =0 ; -spin_unlock_irq (&chip->reg_lock); subs->runtime->private_data = s; s->substream = subs;
@@ -1742,7 +1735,7 @@ snd_m3_substream_close(struct snd_m3 *chip, struct snd_pcm_substream *subs)if (s ==NULL )return ;/* not opened properly */ -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);if (s->substream && s->running)snd_m3_pcm_stop (chip, s, s->substream);/* does this happen? */ if (s->in_lists) {
@@ -1753,7 +1746,6 @@ snd_m3_substream_close(struct snd_m3 *chip, struct snd_pcm_substream *subs) } s->running =0 ; s->opened =0 ; -spin_unlock_irq (&chip->reg_lock); } static int
@@ -2339,14 +2331,13 @@ static void snd_m3_free(struct snd_card *card)cancel_work_sync (&chip->hwvol_work);if (chip->substreams) { -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);for (i =0 ; i < chip->num_substreams; i++) { s = &chip->substreams[i];/* check surviving pcms; this should not happen though.. */ if (s->substream && s->running)snd_m3_pcm_stop (chip, s, s->substream); } -spin_unlock_irq (&chip->reg_lock); }if (chip->iobase) {outw (0 , chip->iobase +HOST_INT_CTRL );/* disable ints */
Signature · 1 line
2.50.1
PATCH 43/61 ALSA: mixart: 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/pci/mixart/mixart.c | 48 +++++++--------------- sound/pci/mixart/mixart_core.c | 71 +++++++++++++++------------------ sound/pci/mixart/mixart_mixer.c | 46 ++++++++++----------- 3 files changed, 70 insertions(+), 95 deletions(-)
sound/pci/mixart/mixart.c +15 -33
@@ -603,7 +603,7 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,/* set up format for the stream */ format =params_format (hw); -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);/* update the stream levels */ if ( stream->pcm_number <=MIXART_PCM_DIGITAL ) {
@@ -618,10 +618,8 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,/* set the format to the board */ err =mixart_set_format (stream, format); -if (err <0 ) { -mutex_unlock (&mgr->setup_mutex); +if (err <0 )return err; - }if (subs->runtime->buffer_changed) {struct mixart_bufferinfo *bufferinfo;
@@ -641,7 +639,6 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs, bufferinfo[i].available_length, subs->number); } -mutex_unlock (&mgr->setup_mutex);return 0 ; }
@@ -712,7 +709,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)int err =0 ;int pcm_number; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);if ( pcm == chip->pcm ) { pcm_number =MIXART_PCM_ANALOG ;
@@ -734,25 +731,21 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)dev_err (chip->card->dev,"snd_mixart_playback_open C%d/P%d/Sub%d in use\n" , chip->chip_idx, pcm_number, subs->number); - err = -EBUSY ; - goto _exit_open; +return -EBUSY ; }/* get pipe pointer (out pipe) */ pipe =snd_mixart_add_ref_pipe (chip, pcm_number,0 ,0 ); -if (pipe ==NULL ) { - err = -EINVAL ; - goto _exit_open; - } +if (pipe ==NULL ) +return -EINVAL ;/* start the pipe if necessary */ err =mixart_set_pipe_state (chip->mgr, pipe,1 );if ( err <0 ) {dev_err (chip->card->dev,"error starting pipe!\n" );snd_mixart_kill_ref_pipe (chip->mgr, pipe,0 ); - err = -EINVAL ; - goto _exit_open; +return -EINVAL ; } stream->pipe = pipe;
@@ -773,10 +766,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs) } } - _exit_open: -mutex_unlock (&mgr->setup_mutex); - -return err; +return 0 ; }
@@ -791,7 +781,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)int err =0 ;int pcm_number; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);if ( pcm == chip->pcm ) { pcm_number =MIXART_PCM_ANALOG ;
@@ -815,25 +805,21 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)dev_err (chip->card->dev,"snd_mixart_capture_open C%d/P%d/Sub%d in use\n" , chip->chip_idx, pcm_number, subs->number); - err = -EBUSY ; - goto _exit_open; +return -EBUSY ; }/* get pipe pointer (in pipe) */ pipe =snd_mixart_add_ref_pipe (chip, pcm_number,1 ,0 ); -if (pipe ==NULL ) { - err = -EINVAL ; - goto _exit_open; - } +if (pipe ==NULL ) +return -EINVAL ;/* start the pipe if necessary */ err =mixart_set_pipe_state (chip->mgr, pipe,1 );if ( err <0 ) {dev_err (chip->card->dev,"error starting pipe!\n" );snd_mixart_kill_ref_pipe (chip->mgr, pipe,0 ); - err = -EINVAL ; - goto _exit_open; +return -EINVAL ; } stream->pipe = pipe;
@@ -854,10 +840,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs) } } - _exit_open: -mutex_unlock (&mgr->setup_mutex); - -return err; +return 0 ; }
@@ -868,7 +851,7 @@ static int snd_mixart_close(struct snd_pcm_substream *subs)struct mixart_mgr *mgr = chip->mgr;struct mixart_stream *stream = subs->runtime->private_data; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);dev_dbg (chip->card->dev,"snd_mixart_close C%d/P%d/Sub%d\n" , chip->chip_idx, stream->pcm_number, subs->number);
@@ -890,7 +873,6 @@ static int snd_mixart_close(struct snd_pcm_substream *subs) stream->status =MIXART_STREAM_STATUS_FREE ; stream->substream =NULL ; -mutex_unlock (&mgr->setup_mutex);return 0 ; }
sound/pci/mixart/mixart_core.c +33 -38
119 lines not on this page · raw message
sound/pci/mixart/mixart_mixer.c +22 -24
176 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 44/61 ALSA: nm256: 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/pci/nm256/nm256.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
sound/pci/nm256/nm256.c +2 -5
@@ -446,27 +446,25 @@ snd_nm256_set_format(struct nm256 *chip, struct nm256_stream *s,/* acquire interrupt */ static int snd_nm256_acquire_irq (struct nm256 *chip) { -mutex_lock (&chip->irq_mutex); +guard (mutex)(&chip->irq_mutex);if (chip->irq <0 ) {if (request_irq (chip->pci->irq, chip->interrupt,IRQF_SHARED ,KBUILD_MODNAME , chip)) {dev_err (chip->card->dev,"unable to grab IRQ %d\n" , chip->pci->irq); -mutex_unlock (&chip->irq_mutex);return -EBUSY ; } chip->irq = chip->pci->irq; chip->card->sync_irq = chip->irq; } chip->irq_acks++; -mutex_unlock (&chip->irq_mutex);return 0 ; }/* release interrupt */ static void snd_nm256_release_irq (struct nm256 *chip) { -mutex_lock (&chip->irq_mutex); +guard (mutex)(&chip->irq_mutex);if (chip->irq_acks >0 ) chip->irq_acks--;if (chip->irq_acks ==0 && chip->irq >=0 ) {
@@ -474,7 +472,6 @@ static void snd_nm256_release_irq(struct nm256 *chip) chip->irq =-1 ; chip->card->sync_irq =-1 ; } -mutex_unlock (&chip->irq_mutex); }/*
Signature · 1 line
2.50.1
PATCH 45/61 ALSA: nm256: 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/pci/nm256/nm256.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
sound/pci/nm256/nm256.c +10 -20
@@ -544,12 +544,11 @@ snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd) {struct nm256 *chip =snd_pcm_substream_chip (substream);struct nm256_stream *s = substream->runtime->private_data; -int err =0 ;if (snd_BUG_ON (!s))return -ENXIO ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_RESUME : s->suspended =0 ;
@@ -570,11 +569,9 @@ snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd) }break ;default : - err = -EINVAL ; -break ; +return -EINVAL ; } -spin_unlock (&chip->reg_lock); -return err; +return 0 ; } static int
@@ -582,12 +579,11 @@ snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd) {struct nm256 *chip =snd_pcm_substream_chip (substream);struct nm256_stream *s = substream->runtime->private_data; -int err =0 ;if (snd_BUG_ON (!s))return -ENXIO ; -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -604,11 +600,9 @@ snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd) }break ;default : - err = -EINVAL ; -break ; +return -EINVAL ; } -spin_unlock (&chip->reg_lock); -return err; +return 0 ; }
@@ -628,10 +622,9 @@ static int snd_nm256_pcm_prepare(struct snd_pcm_substream *substream) s->periods = substream->runtime->periods; s->cur_period =0 ; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); s->running =0 ;snd_nm256_set_format (chip, s, substream); -spin_unlock_irq (&chip->reg_lock);return 0 ; }
@@ -996,7 +989,7 @@ snd_nm256_interrupt(int irq, void *dev_id)/* Rather boring; check for individual interrupts and process them. */ -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);if (status &NM_PLAYBACK_INT ) { status &= ~NM_PLAYBACK_INT ;NM_ACK_INT (chip,NM_PLAYBACK_INT );
@@ -1035,7 +1028,6 @@ snd_nm256_interrupt(int irq, void *dev_id)NM_ACK_INT (chip, status); } -spin_unlock (&chip->reg_lock);return IRQ_HANDLED ; }
@@ -1062,7 +1054,7 @@ snd_nm256_interrupt_zx(int irq, void *dev_id)/* Rather boring; check for individual interrupts and process them. */ -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock);if (status &NM2_PLAYBACK_INT ) { status &= ~NM2_PLAYBACK_INT ;NM2_ACK_INT (chip,NM2_PLAYBACK_INT );
@@ -1100,7 +1092,6 @@ snd_nm256_interrupt_zx(int irq, void *dev_id)NM2_ACK_INT (chip, status); } -spin_unlock (&chip->reg_lock);return IRQ_HANDLED ; }
@@ -1389,9 +1380,8 @@ static int nm256_resume(struct device *dev)for (i =0 ; i <2 ; i++) {struct nm256_stream *s = &chip->streams[i];if (s->substream && s->suspended) { -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);snd_nm256_set_format (chip, s, s->substream); -spin_unlock_irq (&chip->reg_lock); } }
Signature · 1 line
2.50.1
PATCH 46/61 ALSA: oxygen: 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/pci/oxygen/oxygen.c | 12 +++---- sound/pci/oxygen/oxygen_mixer.c | 60 +++++++++++-------------------- sound/pci/oxygen/oxygen_pcm.c | 21 ++++------- sound/pci/oxygen/xonar_cs43xx.c | 3 +- sound/pci/oxygen/xonar_dg_mixer.c | 33 ++++++----------- sound/pci/oxygen/xonar_pcm179x.c | 18 ++++------ sound/pci/oxygen/xonar_wm87x6.c | 31 ++++++---------- 7 files changed, 59 insertions(+), 119 deletions(-)
sound/pci/oxygen/oxygen.c +4 -8
@@ -450,7 +450,7 @@ static int rolloff_put(struct snd_kcontrol *ctl,int changed;u8 reg; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->ak4396_regs[0 ][AK4396_CONTROL_2 ];if (value->value.enumerated.item[0 ]) reg |=AK4396_SLOW ;
@@ -461,7 +461,6 @@ static int rolloff_put(struct snd_kcontrol *ctl,for (i =0 ; i < data->dacs; ++i)ak4396_write (chip, i,AK4396_CONTROL_2 , reg); } -mutex_unlock (&chip->mutex);return changed; }
@@ -499,14 +498,13 @@ static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)unsigned int reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->wm8785_regs[WM8785_R2 ] & ~(WM8785_HPFR |WM8785_HPFL );if (value->value.enumerated.item[0 ]) reg |=WM8785_HPFR |WM8785_HPFL ; changed = reg != data->wm8785_regs[WM8785_R2 ];if (changed)wm8785_write (chip,WM8785_R2 , reg); -mutex_unlock (&chip->mutex);return changed; }
@@ -563,7 +561,7 @@ static int meridian_dig_source_put(struct snd_kcontrol *ctl,u16 old_reg, new_reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); old_reg =oxygen_read16 (chip,OXYGEN_GPIO_DATA ); new_reg = old_reg & ~GPIO_MERIDIAN_DIG_MASK ;if (value->value.enumerated.item[0 ] ==0 )
@@ -573,7 +571,6 @@ static int meridian_dig_source_put(struct snd_kcontrol *ctl, changed = new_reg != old_reg;if (changed)oxygen_write16 (chip,OXYGEN_GPIO_DATA , new_reg); -mutex_unlock (&chip->mutex);return changed; }
@@ -584,7 +581,7 @@ static int claro_dig_source_put(struct snd_kcontrol *ctl,u16 old_reg, new_reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); old_reg =oxygen_read16 (chip,OXYGEN_GPIO_DATA ); new_reg = old_reg & ~GPIO_CLARO_DIG_COAX ;if (value->value.enumerated.item[0 ])
@@ -592,7 +589,6 @@ static int claro_dig_source_put(struct snd_kcontrol *ctl, changed = new_reg != old_reg;if (changed)oxygen_write16 (chip,OXYGEN_GPIO_DATA , new_reg); -mutex_unlock (&chip->mutex);return changed; }
sound/pci/oxygen/oxygen_mixer.c +20 -40
250 lines not on this page · raw message
sound/pci/oxygen/oxygen_pcm.c +7 -14
@@ -171,7 +171,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,snd_pcm_set_sync (substream); chip->streams[channel] = substream; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); chip->pcm_active |=1 << channel;if (channel ==PCM_SPDIF ) { chip->spdif_pcm_bits = chip->spdif_bits;
@@ -181,7 +181,6 @@ static int oxygen_open(struct snd_pcm_substream *substream,SNDRV_CTL_EVENT_MASK_INFO , &chip->controls[CONTROL_SPDIF_PCM]->id); } -mutex_unlock (&chip->mutex);return 0 ; }
@@ -221,7 +220,7 @@ static int oxygen_close(struct snd_pcm_substream *substream)struct oxygen *chip =snd_pcm_substream_chip (substream);unsigned int channel =oxygen_substream_channel (substream); -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); chip->pcm_active &= ~(1 << channel);if (channel ==PCM_SPDIF ) { chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |=
@@ -232,7 +231,6 @@ static int oxygen_close(struct snd_pcm_substream *substream) }if (channel ==PCM_SPDIF || channel ==PCM_MULTICH )oxygen_update_spdif_source (chip); -mutex_unlock (&chip->mutex); chip->streams[channel] =NULL ;return 0 ;
@@ -366,9 +364,8 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream, OXYGEN_I2S_BITS_MASK);spin_unlock_irq (&chip->reg_lock); -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); chip->model.set_adc_params (chip, hw_params); -mutex_unlock (&chip->mutex);return 0 ; }
@@ -403,9 +400,8 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,spin_unlock_irq (&chip->reg_lock);if (!is_ac97) { -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); chip->model.set_adc_params (chip, hw_params); -mutex_unlock (&chip->mutex); }return 0 ; }
@@ -440,9 +436,8 @@ static int oxygen_rec_c_hw_params(struct snd_pcm_substream *substream,spin_unlock_irq (&chip->reg_lock);if (!is_spdif) { -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); chip->model.set_adc_params (chip, hw_params); -mutex_unlock (&chip->mutex); }return 0 ; }
@@ -457,7 +452,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,if (err <0 )return err; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);spin_lock_irq (&chip->reg_lock);oxygen_clear_bits32 (chip,OXYGEN_SPDIF_CONTROL ,OXYGEN_SPDIF_OUT_ENABLE );
@@ -469,7 +464,6 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream, OXYGEN_SPDIF_OUT_RATE_MASK);oxygen_update_spdif_source (chip);spin_unlock_irq (&chip->reg_lock); -mutex_unlock (&chip->mutex);return 0 ; }
@@ -483,7 +477,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,if (err <0 )return err; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);spin_lock_irq (&chip->reg_lock); oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, oxygen_play_channels(hw_params),
@@ -505,7 +499,6 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream, chip->model.set_dac_params (chip, hw_params);oxygen_update_dac_routing (chip); -mutex_unlock (&chip->mutex);return 0 ; }
sound/pci/oxygen/xonar_cs43xx.c +1 -2
@@ -309,7 +309,7 @@ static int rolloff_put(struct snd_kcontrol *ctl,int changed;u8 reg; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->cs4398_regs[7 ];if (value->value.enumerated.item[0 ]) reg |=CS4398_FILT_SEL ;
@@ -324,7 +324,6 @@ static int rolloff_put(struct snd_kcontrol *ctl, reg = data->cs4362a_regs[0x04 ] & ~CS4362A_FILT_SEL ;cs4362a_write (chip,0x04 , reg); } -mutex_unlock (&chip->mutex);return changed; }
sound/pci/oxygen/xonar_dg_mixer.c +11 -22
@@ -62,9 +62,8 @@ static int output_select_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct dg *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); value->value.enumerated.item[0 ] = data->output_sel; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -77,14 +76,13 @@ static int output_select_put(struct snd_kcontrol *ctl,int changed =0 ;int ret; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);if (data->output_sel != new) { data->output_sel = new; ret =output_select_apply (chip); changed = ret >=0 ?1 : ret;oxygen_update_dac_routing (chip); } -mutex_unlock (&chip->mutex);return changed; }
@@ -108,12 +106,11 @@ static int hp_stereo_volume_get(struct snd_kcontrol *ctl,struct dg *data = chip->model_data;unsigned int tmp; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); tmp = (~data->cs4245_shadow[CS4245_DAC_A_CTRL ]) &255 ; val->value.integer.value[0 ] = tmp; tmp = (~data->cs4245_shadow[CS4245_DAC_B_CTRL ]) &255 ; val->value.integer.value[1 ] = tmp; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -130,7 +127,7 @@ static int hp_stereo_volume_put(struct snd_kcontrol *ctl,if ((new1 >255 ) || (new1 <0 ) || (new2 >255 ) || (new2 <0 ))return -EINVAL ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);if ((data->cs4245_shadow[CS4245_DAC_A_CTRL ] != ~new1) || (data->cs4245_shadow[CS4245_DAC_B_CTRL ] != ~new2)) { data->cs4245_shadow[CS4245_DAC_A_CTRL ] = ~new1;
@@ -140,7 +137,6 @@ static int hp_stereo_volume_put(struct snd_kcontrol *ctl, ret =cs4245_write_spi (chip,CS4245_DAC_B_CTRL ); changed = ret >=0 ?1 : ret; } -mutex_unlock (&chip->mutex);return changed; }
@@ -153,10 +149,9 @@ static int hp_mute_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct dg *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); val->value.integer.value[0 ] = !(data->cs4245_shadow[CS4245_DAC_CTRL_1 ] &CS4245_MUTE_DAC ); -mutex_unlock (&chip->mutex);return 0 ; }
@@ -170,13 +165,12 @@ static int hp_mute_put(struct snd_kcontrol *ctl,if (val->value.integer.value[0 ] >1 )return -EINVAL ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); data->cs4245_shadow[CS4245_DAC_CTRL_1 ] &= ~CS4245_MUTE_DAC ; data->cs4245_shadow[CS4245_DAC_CTRL_1 ] |= (~val->value.integer.value[0 ] <<2 ) &CS4245_MUTE_DAC ; ret =cs4245_write_spi (chip,CS4245_DAC_CTRL_1 ); changed = ret >=0 ?1 : ret; -mutex_unlock (&chip->mutex);return changed; }
@@ -212,10 +206,9 @@ static int input_vol_get(struct snd_kcontrol *ctl,struct dg *data = chip->model_data;unsigned int idx = ctl->private_value; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); value->value.integer.value[0 ] = data->input_vol[idx][0 ]; value->value.integer.value[1 ] = data->input_vol[idx][1 ]; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -233,7 +226,7 @@ static int input_vol_put(struct snd_kcontrol *ctl, value->value.integer.value[1 ] <2 *-12 || value->value.integer.value[1] > 2 * 12) return -EINVAL; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = data->input_vol[idx][0 ] != value->value.integer.value[0 ] || data->input_vol[idx][1 ] != value->value.integer.value[1 ];if (changed) {
@@ -246,7 +239,6 @@ static int input_vol_put(struct snd_kcontrol *ctl, } changed = ret >=0 ?1 : ret; } -mutex_unlock (&chip->mutex);return changed; }
@@ -282,9 +274,8 @@ static int input_sel_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct dg *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); value->value.enumerated.item[0 ] = data->input_sel; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -299,7 +290,7 @@ static int input_sel_put(struct snd_kcontrol *ctl,if (value->value.enumerated.item[0 ] >3 )return -EINVAL ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = value->value.enumerated.item[0 ] != data->input_sel;if (changed) { data->input_sel = value->value.enumerated.item[0 ];
@@ -311,7 +302,6 @@ static int input_sel_put(struct snd_kcontrol *ctl, data->input_vol[data->input_sel][1]); changed = ret >=0 ?1 : ret; } -mutex_unlock (&chip->mutex);return changed; }
@@ -341,7 +331,7 @@ static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)u8 reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->cs4245_shadow[CS4245_ADC_CTRL ] & ~CS4245_HPF_FREEZE ;if (value->value.enumerated.item[0 ]) reg |=CS4245_HPF_FREEZE ;
@@ -350,7 +340,6 @@ static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) data->cs4245_shadow[CS4245_ADC_CTRL ] = reg;cs4245_write_spi (chip,CS4245_ADC_CTRL ); } -mutex_unlock (&chip->mutex);return changed; }
sound/pci/oxygen/xonar_pcm179x.c +6 -12
@@ -762,7 +762,7 @@ static int rolloff_put(struct snd_kcontrol *ctl,int changed;u8 reg; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->pcm1796_regs[0 ][19 -PCM1796_REG_BASE ]; reg &= ~PCM1796_FLT_MASK ;if (!value->value.enumerated.item[0 ])
@@ -774,7 +774,6 @@ static int rolloff_put(struct snd_kcontrol *ctl,for (i =0 ; i < data->dacs; ++i)pcm1796_write (chip, i,19 , reg); } -mutex_unlock (&chip->mutex);return changed; }
@@ -806,7 +805,7 @@ static int deemph_put(struct snd_kcontrol *ctl,int changed;u8 reg; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->pcm1796_regs[0 ][18 -PCM1796_REG_BASE ];if (!value->value.integer.value[0 ]) reg &= ~PCM1796_DME ;
@@ -817,7 +816,6 @@ static int deemph_put(struct snd_kcontrol *ctl,for (i =0 ; i < data->dacs; ++i)pcm1796_write (chip, i,18 , reg); } -mutex_unlock (&chip->mutex);return changed; }
@@ -872,7 +870,7 @@ static int st_output_switch_put(struct snd_kcontrol *ctl,struct xonar_pcm179x *data = chip->model_data;u16 gpio_old, gpio; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); gpio_old =oxygen_read16 (chip,OXYGEN_GPIO_DATA ); gpio = gpio_old;switch (value->value.enumerated.item[0 ]) {
@@ -889,7 +887,6 @@ static int st_output_switch_put(struct snd_kcontrol *ctl,oxygen_write16 (chip,OXYGEN_GPIO_DATA , gpio); data->hp_active = gpio &GPIO_ST_HP ;update_pcm1796_volume (chip); -mutex_unlock (&chip->mutex);return gpio != gpio_old; }
@@ -909,7 +906,7 @@ static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct xonar_pcm179x *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex);if (data->hp_gain_offset <2 *-12 ) value->value.enumerated.item[0 ] =0 ;else if (data->hp_gain_offset <2 *-6 )
@@ -918,7 +915,6 @@ static int st_hp_volume_offset_get(struct snd_kcontrol *ctl, value->value.enumerated.item[0 ] =2 ; else value->value.enumerated.item[0] = 3; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -935,13 +931,12 @@ static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,if (value->value.enumerated.item[0 ] >3 )return -EINVAL ; offset = offsets[value->value.enumerated.item[0 ]]; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = offset != data->hp_gain_offset;if (changed) { data->hp_gain_offset = offset;update_pcm1796_volume (chip); } -mutex_unlock (&chip->mutex);return changed; }
@@ -985,7 +980,7 @@ static int xense_output_switch_put(struct snd_kcontrol *ctl,struct xonar_pcm179x *data = chip->model_data;u16 gpio_old, gpio; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); gpio_old =oxygen_read16 (chip,OXYGEN_GPIO_DATA ); gpio = gpio_old;switch (value->value.enumerated.item[0 ]) {
@@ -1002,7 +997,6 @@ static int xense_output_switch_put(struct snd_kcontrol *ctl,oxygen_write16 (chip,OXYGEN_GPIO_DATA , gpio); data->hp_active = !(gpio &GPIO_XENSE_SPEAKERS );update_pcm1796_volume (chip); -mutex_unlock (&chip->mutex);return gpio != gpio_old; }
sound/pci/oxygen/xonar_wm87x6.c +10 -21
@@ -237,7 +237,7 @@ static void xonar_ds_handle_hp_jack(struct oxygen *chip)bool hp_plugged;unsigned int reg; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); hp_plugged = !(oxygen_read16 (chip,OXYGEN_GPIO_DATA ) &GPIO_DS_HP_DETECT );
@@ -252,8 +252,6 @@ static void xonar_ds_handle_hp_jack(struct oxygen *chip)wm8766_write_cached (chip,WM8766_DAC_CTRL , reg);snd_jack_report (data->hp_jack, hp_plugged ?SND_JACK_HEADPHONE :0 ); - -mutex_unlock (&chip->mutex); }static void xonar_ds_init (struct oxygen *chip)
@@ -521,14 +519,13 @@ static int wm8776_bit_switch_put(struct snd_kcontrol *ctl,bool invert = (ctl->private_value >>24 ) &1 ;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg_value = data->wm8776_regs[reg_index] & ~bit;if (value->value.integer.value[0 ] ^ invert) reg_value |= bit; changed = reg_value != data->wm8776_regs[reg_index];if (changed)wm8776_write (chip, reg_index, reg_value); -mutex_unlock (&chip->mutex);return changed; }
@@ -648,13 +645,12 @@ static int wm8776_field_set(struct snd_kcontrol *ctl, unsigned int value) max = (ctl->private_value >>12 ) &0xf ;if (value < min || value > max)return -EINVAL ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = value != (ctl->private_value &0xf );if (changed) { ctl->private_value = (ctl->private_value & ~0xf ) | value;wm8776_field_set_from_ctl (ctl); } -mutex_unlock (&chip->mutex);return changed; }
@@ -700,12 +696,11 @@ static int wm8776_hp_vol_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct xonar_wm87x6 *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); value->value.integer.value[0 ] = data->wm8776_regs[WM8776_HPLVOL ] &WM8776_HPATT_MASK ; value->value.integer.value[1 ] = data->wm8776_regs[WM8776_HPRVOL ] &WM8776_HPATT_MASK ; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -716,7 +711,7 @@ static int wm8776_hp_vol_put(struct snd_kcontrol *ctl,struct xonar_wm87x6 *data = chip->model_data;u8 to_update; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); to_update = (value->value.integer.value[0 ] != (data->wm8776_regs[WM8776_HPLVOL ] &WM8776_HPATT_MASK )) <<0 ;
@@ -744,7 +739,6 @@ static int wm8776_hp_vol_put(struct snd_kcontrol *ctl, value->value.integer.value[1 ] | WM8776_HPZCEN | WM8776_UPDATE); } -mutex_unlock (&chip->mutex);return to_update !=0 ; }
@@ -770,7 +764,7 @@ static int wm8776_input_mux_put(struct snd_kcontrol *ctl,u16 reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->wm8776_regs[WM8776_ADCMUX ];if (value->value.integer.value[0 ]) { reg |= mux_bit;
@@ -794,7 +788,6 @@ static int wm8776_input_mux_put(struct snd_kcontrol *ctl, GPIO_DS_INPUT_ROUTE);wm8776_write (chip,WM8776_ADCMUX , reg); } -mutex_unlock (&chip->mutex);return changed; }
@@ -814,12 +807,11 @@ static int wm8776_input_vol_get(struct snd_kcontrol *ctl,struct oxygen *chip = ctl->private_data;struct xonar_wm87x6 *data = chip->model_data; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); value->value.integer.value[0 ] = data->wm8776_regs[WM8776_ADCLVOL ] &WM8776_AGMASK ; value->value.integer.value[1 ] = data->wm8776_regs[WM8776_ADCRVOL ] &WM8776_AGMASK ; -mutex_unlock (&chip->mutex);return 0 ; }
@@ -830,7 +822,7 @@ static int wm8776_input_vol_put(struct snd_kcontrol *ctl,struct xonar_wm87x6 *data = chip->model_data;int changed =0 ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = (value->value.integer.value[0 ] != (data->wm8776_regs[WM8776_ADCLVOL] & WM8776_AGMASK)) || (value->value.integer.value[1] !=
@@ -839,7 +831,6 @@ static int wm8776_input_vol_put(struct snd_kcontrol *ctl, value->value.integer.value[0] | WM8776_ZCA);wm8776_write_cached (chip,WM8776_ADCRVOL , value->value.integer.value[1 ] |WM8776_ZCA ); -mutex_unlock (&chip->mutex);return changed; }
@@ -895,7 +886,7 @@ static int wm8776_level_control_put(struct snd_kcontrol *ctl,if (value->value.enumerated.item[0 ] >=3 )return -EINVAL ; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); changed = value->value.enumerated.item[0 ] != ctl->private_value;if (changed) { ctl->private_value = value->value.enumerated.item[0 ];
@@ -926,7 +917,6 @@ static int wm8776_level_control_put(struct snd_kcontrol *ctl,for (i =0 ; i <ARRAY_SIZE (data->lc_controls); ++i)activate_control (chip, data->lc_controls[i], mode); } -mutex_unlock (&chip->mutex);return changed; }
@@ -956,14 +946,13 @@ static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)unsigned int reg;int changed; -mutex_lock (&chip->mutex); +guard (mutex)(&chip->mutex); reg = data->wm8776_regs[WM8776_ADCIFCTRL ] & ~WM8776_ADCHPD ;if (!value->value.enumerated.item[0 ]) reg |=WM8776_ADCHPD ; changed = reg != data->wm8776_regs[WM8776_ADCIFCTRL ];if (changed)wm8776_write (chip,WM8776_ADCIFCTRL , reg); -mutex_unlock (&chip->mutex);return changed; }
Signature · 1 line
2.50.1
PATCH 47/61 ALSA: oxygen: 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/pci/oxygen/oxygen_lib.c | 132 ++++++++++++++-------------- sound/pci/oxygen/oxygen_mixer.c | 6 +- sound/pci/oxygen/oxygen_pcm.c | 144 +++++++++++++++---------------- sound/pci/oxygen/xonar_cs43xx.c | 3 +- sound/pci/oxygen/xonar_lib.c | 3 +- sound/pci/oxygen/xonar_pcm179x.c | 3 +- 6 files changed, 139 insertions(+), 152 deletions(-)
sound/pci/oxygen/oxygen_lib.c +64 -68
@@ -59,36 +59,34 @@ static irqreturn_t oxygen_interrupt(int dummy, void *dev_id)if (!status)return IRQ_NONE ; -spin_lock (&chip->reg_lock); + scoped_guard(spinlock, &chip->reg_lock) { + clear = status & (OXYGEN_CHANNEL_A | +OXYGEN_CHANNEL_B | +OXYGEN_CHANNEL_C | +OXYGEN_CHANNEL_SPDIF | +OXYGEN_CHANNEL_MULTICH | +OXYGEN_CHANNEL_AC97 | +OXYGEN_INT_SPDIF_IN_DETECT | +OXYGEN_INT_GPIO | +OXYGEN_INT_AC97 ); +if (clear) { +if (clear &OXYGEN_INT_SPDIF_IN_DETECT ) + chip->interrupt_mask &= ~OXYGEN_INT_SPDIF_IN_DETECT ; +oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , + chip->interrupt_mask & ~clear); +oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , + chip->interrupt_mask); + } - clear = status & (OXYGEN_CHANNEL_A | -OXYGEN_CHANNEL_B | -OXYGEN_CHANNEL_C | -OXYGEN_CHANNEL_SPDIF | -OXYGEN_CHANNEL_MULTICH | -OXYGEN_CHANNEL_AC97 | -OXYGEN_INT_SPDIF_IN_DETECT | -OXYGEN_INT_GPIO | -OXYGEN_INT_AC97 ); -if (clear) { -if (clear &OXYGEN_INT_SPDIF_IN_DETECT ) - chip->interrupt_mask &= ~OXYGEN_INT_SPDIF_IN_DETECT ; -oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , - chip->interrupt_mask & ~clear); -oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , - chip->interrupt_mask); + elapsed_streams = status & chip->pcm_running; } - elapsed_streams = status & chip->pcm_running; - -spin_unlock (&chip->reg_lock); -for (i =0 ; i <PCM_COUNT ; ++i)if ((elapsed_streams & (1 << i)) && chip->streams[i])snd_pcm_period_elapsed (chip->streams[i]);if (status &OXYGEN_INT_SPDIF_IN_DETECT ) { -spin_lock (&chip->reg_lock); +guard (spinlock)(&chip->reg_lock); i =oxygen_read32 (chip,OXYGEN_SPDIF_CONTROL );if (i & (OXYGEN_SPDIF_SENSE_INT |OXYGEN_SPDIF_LOCK_INT |OXYGEN_SPDIF_RATE_INT )) {
@@ -96,7 +94,6 @@ static irqreturn_t oxygen_interrupt(int dummy, void *dev_id)oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , i);schedule_work (&chip->spdif_input_bits_work); } -spin_unlock (&chip->reg_lock); }if (status &OXYGEN_INT_GPIO )
@@ -127,45 +124,45 @@ static void oxygen_spdif_input_bits_changed(struct work_struct *work)* changes. */ msleep (1 ); -spin_lock_irq (&chip->reg_lock); - reg =oxygen_read32 (chip,OXYGEN_SPDIF_CONTROL ); -if ((reg & (OXYGEN_SPDIF_SENSE_STATUS | -OXYGEN_SPDIF_LOCK_STATUS )) - ==OXYGEN_SPDIF_SENSE_STATUS ) { -/* -* If we detect activity on the SPDIF input but cannot lock to -* a signal, the clock bit is likely to be wrong. -*/ - reg ^=OXYGEN_SPDIF_IN_CLOCK_MASK ; -oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , reg); -spin_unlock_irq (&chip->reg_lock); -msleep (1 ); -spin_lock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { reg =oxygen_read32 (chip,OXYGEN_SPDIF_CONTROL );if ((reg & (OXYGEN_SPDIF_SENSE_STATUS |OXYGEN_SPDIF_LOCK_STATUS )) ==OXYGEN_SPDIF_SENSE_STATUS ) { -/* nothing detected with either clock; give up */ -if ((reg &OXYGEN_SPDIF_IN_CLOCK_MASK ) - ==OXYGEN_SPDIF_IN_CLOCK_192 ) { -/* -* Reset clock to <= 96 kHz because this is -* more likely to be received next time. -*/ - reg &= ~OXYGEN_SPDIF_IN_CLOCK_MASK ; - reg |=OXYGEN_SPDIF_IN_CLOCK_96 ; -oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , reg); +/* +* If we detect activity on the SPDIF input but cannot lock to +* a signal, the clock bit is likely to be wrong. +*/ + reg ^=OXYGEN_SPDIF_IN_CLOCK_MASK ; +oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , reg); +spin_unlock_irq (&chip->reg_lock); +msleep (1 ); +spin_lock_irq (&chip->reg_lock); + reg =oxygen_read32 (chip,OXYGEN_SPDIF_CONTROL ); +if ((reg & (OXYGEN_SPDIF_SENSE_STATUS | +OXYGEN_SPDIF_LOCK_STATUS )) + ==OXYGEN_SPDIF_SENSE_STATUS ) { +/* nothing detected with either clock; give up */ +if ((reg &OXYGEN_SPDIF_IN_CLOCK_MASK ) + ==OXYGEN_SPDIF_IN_CLOCK_192 ) { +/* +* Reset clock to <= 96 kHz because this is +* more likely to be received next time. +*/ + reg &= ~OXYGEN_SPDIF_IN_CLOCK_MASK ; + reg |=OXYGEN_SPDIF_IN_CLOCK_96 ; +oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , reg); + } } } } -spin_unlock_irq (&chip->reg_lock);if (chip->controls[CONTROL_SPDIF_INPUT_BITS ]) { -spin_lock_irq (&chip->reg_lock); - chip->interrupt_mask |=OXYGEN_INT_SPDIF_IN_DETECT ; -oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , - chip->interrupt_mask); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + chip->interrupt_mask |=OXYGEN_INT_SPDIF_IN_DETECT ; +oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , + chip->interrupt_mask); + }/* * We don't actually know that any channel status bits have
@@ -557,12 +554,11 @@ static void oxygen_init(struct oxygen *chip)static void oxygen_shutdown (struct oxygen *chip) { -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); chip->interrupt_mask =0 ; chip->pcm_running =0 ;oxygen_write16 (chip,OXYGEN_DMA_STATUS ,0 );oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK ,0 ); -spin_unlock_irq (&chip->reg_lock); }static void oxygen_card_free (struct snd_card *card)
@@ -686,13 +682,13 @@ static int __oxygen_pci_probe(struct pci_dev *pci, int index, char *id,oxygen_proc_init (chip); -spin_lock_irq (&chip->reg_lock); -if (chip->model.device_config &CAPTURE_1_FROM_SPDIF ) - chip->interrupt_mask |=OXYGEN_INT_SPDIF_IN_DETECT ; -if (chip->has_ac97_0 | chip->has_ac97_1) - chip->interrupt_mask |=OXYGEN_INT_AC97 ; -oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , chip->interrupt_mask); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { +if (chip->model.device_config &CAPTURE_1_FROM_SPDIF ) + chip->interrupt_mask |=OXYGEN_INT_SPDIF_IN_DETECT ; +if (chip->has_ac97_0 | chip->has_ac97_1) + chip->interrupt_mask |=OXYGEN_INT_AC97 ; +oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK , chip->interrupt_mask); + } err =snd_card_register (card);if (err <0 )
@@ -724,12 +720,12 @@ static int oxygen_pci_suspend(struct device *dev)if (chip->model.suspend) chip->model.suspend (chip); -spin_lock_irq (&chip->reg_lock); - saved_interrupt_mask = chip->interrupt_mask; - chip->interrupt_mask =0 ; -oxygen_write16 (chip,OXYGEN_DMA_STATUS ,0 ); -oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK ,0 ); -spin_unlock_irq (&chip->reg_lock); + scoped_guard(spinlock_irq, &chip->reg_lock) { + saved_interrupt_mask = chip->interrupt_mask; + chip->interrupt_mask =0 ; +oxygen_write16 (chip,OXYGEN_DMA_STATUS ,0 ); +oxygen_write16 (chip,OXYGEN_INTERRUPT_MASK ,0 ); + }flush_work (&chip->spdif_input_bits_work);flush_work (&chip->gpio_work);
sound/pci/oxygen/oxygen_mixer.c +2 -4
@@ -432,7 +432,7 @@ static int spdif_bit_switch_put(struct snd_kcontrol *ctl,u32 oldreg, newreg;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); oldreg =oxygen_read32 (chip,OXYGEN_SPDIF_CONTROL );if (value->value.integer.value[0 ]) newreg = oldreg | bit;
@@ -441,7 +441,6 @@ static int spdif_bit_switch_put(struct snd_kcontrol *ctl, changed = newreg != oldreg;if (changed)oxygen_write32 (chip,OXYGEN_SPDIF_CONTROL , newreg); -spin_unlock_irq (&chip->reg_lock);return changed; }
@@ -476,7 +475,7 @@ static int monitor_put(struct snd_kcontrol *ctl,u8 oldreg, newreg;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); oldreg =oxygen_read8 (chip,OXYGEN_ADC_MONITOR );if ((!!value->value.integer.value[0 ] ^ !!invert) !=0 ) newreg = oldreg | bit;
@@ -485,7 +484,6 @@ static int monitor_put(struct snd_kcontrol *ctl, changed = newreg != oldreg;if (changed)oxygen_write8 (chip,OXYGEN_ADC_MONITOR , newreg); -spin_unlock_irq (&chip->reg_lock);return changed; }
sound/pci/oxygen/oxygen_pcm.c +70 -74
221 lines not on this page · raw message
sound/pci/oxygen/xonar_cs43xx.c +1 -2
@@ -339,11 +339,10 @@ static void xonar_d1_line_mic_ac97_switch(struct oxygen *chip, unsigned int reg, unsigned int mute) {if (reg ==AC97_LINE ) { -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);oxygen_write16_masked (chip,OXYGEN_GPIO_DATA , mute ?GPIO_D1_INPUT_ROUTE :0 ,GPIO_D1_INPUT_ROUTE ); -spin_unlock_irq (&chip->reg_lock); } }
sound/pci/oxygen/xonar_lib.c +1 -2
@@ -109,7 +109,7 @@ int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,u16 old_bits, new_bits;int changed; -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock); old_bits =oxygen_read16 (chip,OXYGEN_GPIO_DATA );if (!!value->value.integer.value[0 ] ^ invert) new_bits = old_bits | bit;
@@ -118,6 +118,5 @@ int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl, changed = new_bits != old_bits;if (changed)oxygen_write16 (chip,OXYGEN_GPIO_DATA , new_bits); -spin_unlock_irq (&chip->reg_lock);return changed; }
sound/pci/oxygen/xonar_pcm179x.c +1 -2
@@ -1021,11 +1021,10 @@ static void xonar_line_mic_ac97_switch(struct oxygen *chip, unsigned int reg, unsigned int mute) {if (reg ==AC97_LINE ) { -spin_lock_irq (&chip->reg_lock); +guard (spinlock_irq)(&chip->reg_lock);oxygen_write16_masked (chip,OXYGEN_GPIO_DATA , mute ?GPIO_INPUT_ROUTE :0 ,GPIO_INPUT_ROUTE ); -spin_unlock_irq (&chip->reg_lock); } }
Signature · 1 line
2.50.1
PATCH 48/61 ALSA: pcxhr: 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/pci/pcxhr/pcxhr.c | 35 +++++---------------- sound/pci/pcxhr/pcxhr_core.c | 15 +++------ sound/pci/pcxhr/pcxhr_mix22.c | 23 +++++++------- sound/pci/pcxhr/pcxhr_mixer.c | 58 +++++++++++++---------------------- 4 files changed, 45 insertions(+), 86 deletions(-)
sound/pci/pcxhr/pcxhr.c +8 -27
@@ -701,7 +701,7 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr) start_time =ktime_get ();#endif -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);/* check the pipes concerned and build pipe_array */ for (i =0 ; i < mgr->num_cards; i++) {
@@ -720,7 +720,6 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr) } }if (capture_mask ==0 && playback_mask ==0 ) { -mutex_unlock (&mgr->setup_mutex);dev_err (&mgr->pci->dev,"%s : no pipes\n" , __func__);return ; }
@@ -731,7 +730,6 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)/* synchronous stop of all the pipes concerned */ err =pcxhr_set_pipe_state (mgr, playback_mask, capture_mask,0 );if (err) { -mutex_unlock (&mgr->setup_mutex);dev_err (&mgr->pci->dev,"%s : " "error stop pipes (P%x C%x)\n" , __func__, playback_mask, capture_mask);
@@ -776,7 +774,6 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)/* synchronous start of all the pipes concerned */ err =pcxhr_set_pipe_state (mgr, playback_mask, capture_mask,1 );if (err) { -mutex_unlock (&mgr->setup_mutex);dev_err (&mgr->pci->dev,"%s : " "error start pipes (P%x C%x)\n" , __func__, playback_mask, capture_mask);
@@ -786,7 +783,7 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr)/* put the streams into the running state now * (increment pointer by interrupt) */ -mutex_lock (&mgr->lock); +guard (mutex)(&mgr->lock);for ( i =0 ; i < mgr->num_cards; i++) {struct pcxhr_stream *stream; chip = mgr->chip[i];
@@ -804,9 +801,6 @@ static void pcxhr_start_linked_stream(struct pcxhr_mgr *mgr) } } } -mutex_unlock (&mgr->lock); - -mutex_unlock (&mgr->setup_mutex);#ifdef CONFIG_SND_DEBUG_VERBOSE stop_time =ktime_get ();
@@ -907,7 +901,7 @@ static int pcxhr_prepare(struct snd_pcm_substream *subs) subs->runtime->period_size, subs->runtime->periods, subs->runtime->buffer_size); -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex); do { /* only the first stream can choose the sample rate */
@@ -923,8 +917,6 @@ static int pcxhr_prepare(struct snd_pcm_substream *subs) } }while (0 );/* do only once (so we can use break instead of goto) */ -mutex_unlock (&mgr->setup_mutex); -return err; }
@@ -939,15 +931,13 @@ static int pcxhr_hw_params(struct snd_pcm_substream *subs,struct pcxhr_mgr *mgr = chip->mgr;struct pcxhr_stream *stream = subs->runtime->private_data; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);/* set up channels */ stream->channels =params_channels (hw);/* set up format for the stream */ stream->format =params_format (hw); -mutex_unlock (&mgr->setup_mutex); -return 0 ; }
@@ -990,7 +980,7 @@ static int pcxhr_open(struct snd_pcm_substream *subs)struct pcxhr_stream *stream;int err; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);/* copy the struct snd_pcm_hardware struct */ runtime->hw = pcxhr_caps;
@@ -1012,7 +1002,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs)/* streams in use */ dev_err (chip->card->dev,"%s chip%d subs%d in use\n" , __func__, chip->chip_idx, subs->number); -mutex_unlock (&mgr->setup_mutex);return -EBUSY ; }
@@ -1023,10 +1012,8 @@ static int pcxhr_open(struct snd_pcm_substream *subs)/* buffer-size should better be multiple of period-size */ err =snd_pcm_hw_constraint_integer (runtime,SNDRV_PCM_HW_PARAM_PERIODS ); -if (err <0 ) { -mutex_unlock (&mgr->setup_mutex); +if (err <0 )return err; - }/* if a sample rate is already used or fixed by external clock, * the stream cannot change
@@ -1040,7 +1027,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs) &external_rate) || external_rate == 0) {/* cannot detect the external clock rate */ -mutex_unlock (&mgr->setup_mutex);return -EBUSY ; } runtime->hw.rate_min = external_rate;
@@ -1063,7 +1049,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs) mgr->ref_count_rate++; -mutex_unlock (&mgr->setup_mutex);return 0 ; }
@@ -1074,7 +1059,7 @@ static int pcxhr_close(struct snd_pcm_substream *subs)struct pcxhr_mgr *mgr = chip->mgr;struct pcxhr_stream *stream = subs->runtime->private_data; -mutex_lock (&mgr->setup_mutex); +guard (mutex)(&mgr->setup_mutex);dev_dbg (chip->card->dev,"%s chip%d subs%d\n" , __func__, chip->chip_idx, subs->number);
@@ -1088,8 +1073,6 @@ static int pcxhr_close(struct snd_pcm_substream *subs) stream->status =PCXHR_STREAM_STATUS_FREE ; stream->substream =NULL ; -mutex_unlock (&mgr->setup_mutex); -return 0 ; }
@@ -1102,14 +1085,12 @@ static snd_pcm_uframes_t pcxhr_stream_pointer(struct snd_pcm_substream *subs)struct snd_pcm_runtime *runtime = subs->runtime;struct pcxhr_stream *stream = runtime->private_data; -mutex_lock (&chip->mgr->lock); +guard (mutex)(&chip->mgr->lock);/* get the period fragment and the nb of periods in the buffer */ timer_period_frag = stream->timer_period_frag; timer_buf_periods = stream->timer_buf_periods; -mutex_unlock (&chip->mgr->lock); -return (snd_pcm_uframes_t)((timer_buf_periods * runtime->period_size) + timer_period_frag); }
sound/pci/pcxhr/pcxhr_core.c +4 -11
@@ -754,12 +754,8 @@ void pcxhr_set_pipe_cmd_params(struct pcxhr_rmh *rmh, int capture,*/ int pcxhr_send_msg (struct pcxhr_mgr *mgr,struct pcxhr_rmh *rmh) { -int err; - -mutex_lock (&mgr->msg_lock); - err =pcxhr_send_msg_nolock (mgr, rmh); -mutex_unlock (&mgr->msg_lock); -return err; +guard (mutex)(&mgr->msg_lock); +return pcxhr_send_msg_nolock (mgr, rmh); }static inline int pcxhr_pipes_running (struct pcxhr_mgr *mgr)
@@ -962,14 +958,13 @@ int pcxhr_write_io_num_reg_cont(struct pcxhr_mgr *mgr, unsigned int mask,struct pcxhr_rmh rmh;int err; -mutex_lock (&mgr->msg_lock); +guard (mutex)(&mgr->msg_lock);if ((mgr->io_num_reg_cont & mask) == value) {dev_dbg (&mgr->pci->dev,"IO_NUM_REG_CONT mask %x already is set to %x\n" , mask, value);if (changed) *changed =0 ; -mutex_unlock (&mgr->msg_lock);return 0 ;/* already programmed */ }pcxhr_init_rmh (&rmh,CMD_ACCESS_IO_WRITE );
@@ -984,7 +979,6 @@ int pcxhr_write_io_num_reg_cont(struct pcxhr_mgr *mgr, unsigned int mask,if (changed) *changed =1 ; } -mutex_unlock (&mgr->msg_lock);return err; }
@@ -1269,7 +1263,7 @@ irqreturn_t pcxhr_threaded_irq(int irq, void *dev_id)int i, j;struct snd_pcxhr *chip; -mutex_lock (&mgr->lock); +guard (mutex)(&mgr->lock);if (mgr->src_it_dsp &PCXHR_IRQ_TIMER ) {/* is a 24 bit counter */ int dsp_time_new =
@@ -1328,6 +1322,5 @@ irqreturn_t pcxhr_threaded_irq(int irq, void *dev_id) }pcxhr_msg_thread (mgr); -mutex_unlock (&mgr->lock);return IRQ_HANDLED ; }
sound/pci/pcxhr/pcxhr_mix22.c +11 -12
@@ -710,9 +710,9 @@ static int hr222_mic_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol); -mutex_lock (&chip->mgr->mixer_mutex); + +guard (mutex)(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0 ] = chip->mic_volume; -mutex_unlock (&chip->mgr->mixer_mutex);return 0 ; }
@@ -721,13 +721,13 @@ static int hr222_mic_vol_put(struct snd_kcontrol *kcontrol, {struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol);int changed =0 ; -mutex_lock (&chip->mgr->mixer_mutex); + +guard (mutex)(&chip->mgr->mixer_mutex);if (chip->mic_volume != ucontrol->value.integer.value[0 ]) { changed =1 ; chip->mic_volume = ucontrol->value.integer.value[0 ];hr222_update_analog_audio_level (chip,1 ,0 ); } -mutex_unlock (&chip->mgr->mixer_mutex);return changed; }
@@ -760,9 +760,9 @@ static int hr222_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol); -mutex_lock (&chip->mgr->mixer_mutex); + +guard (mutex)(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0 ] = chip->mic_boost; -mutex_unlock (&chip->mgr->mixer_mutex);return 0 ; }
@@ -771,13 +771,13 @@ static int hr222_mic_boost_put(struct snd_kcontrol *kcontrol, {struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol);int changed =0 ; -mutex_lock (&chip->mgr->mixer_mutex); + +guard (mutex)(&chip->mgr->mixer_mutex);if (chip->mic_boost != ucontrol->value.integer.value[0 ]) { changed =1 ; chip->mic_boost = ucontrol->value.integer.value[0 ];hr222_micro_boost (chip->mgr, chip->mic_boost); } -mutex_unlock (&chip->mgr->mixer_mutex);return changed; }
@@ -800,9 +800,9 @@ static int hr222_phantom_power_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol); -mutex_lock (&chip->mgr->mixer_mutex); + +guard (mutex)(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0 ] = chip->phantom_power; -mutex_unlock (&chip->mgr->mixer_mutex);return 0 ; }
@@ -812,14 +812,13 @@ static int hr222_phantom_power_put(struct snd_kcontrol *kcontrol,struct snd_pcxhr *chip =snd_kcontrol_chip (kcontrol);int power, changed =0 ; -mutex_lock (&chip->mgr->mixer_mutex); +guard (mutex)(&chip->mgr->mixer_mutex); power = !!ucontrol->value.integer.value[0 ];if (chip->phantom_power != power) {hr222_phantom_power (chip->mgr, power); chip->phantom_power = power; changed =1 ; } -mutex_unlock (&chip->mgr->mixer_mutex);return changed; }
sound/pci/pcxhr/pcxhr_mixer.c +22 -36
249 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 49/61 ALSA: rme32: 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/pci/rme32.c | 152 +++++++++++++++++----------------------------- 1 file changed, 56 insertions(+), 96 deletions(-)
sound/pci/rme32.c +56 -96
@@ -646,35 +646,27 @@ snd_rme32_playback_hw_params(struct snd_pcm_substream *substream, runtime->dma_bytes =RME32_BUFFER_SIZE ; } -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); rate =0 ;if (rme32->rcreg &RME32_RCR_KMODE ) rate =snd_rme32_capture_getrate (rme32, &dummy);if (rate >0 ) {/* AutoSync */ -if ((int )params_rate (params) != rate) { -spin_unlock_irq (&rme32->lock); +if ((int )params_rate (params) != rate)return -EIO ; - } }else { err =snd_rme32_playback_setrate (rme32,params_rate (params)); -if (err <0 ) { -spin_unlock_irq (&rme32->lock); +if (err <0 )return err; - } } err =snd_rme32_setformat (rme32,params_format (params)); -if (err <0 ) { -spin_unlock_irq (&rme32->lock); +if (err <0 )return err; - }snd_rme32_setframelog (rme32,params_channels (params),1 );if (rme32->capture_periodsize !=0 ) { -if (params_period_size (params) << rme32->playback_frlog != rme32->capture_periodsize) { -spin_unlock_irq (&rme32->lock); +if (params_period_size (params) << rme32->playback_frlog != rme32->capture_periodsize)return -EBUSY ; - } } rme32->playback_periodsize =params_period_size (params) << rme32->playback_frlog;/* S/PDIF setup */
@@ -683,7 +675,6 @@ snd_rme32_playback_hw_params(struct snd_pcm_substream *substream, rme32->wcreg |= rme32->wcreg_spdif_stream;writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); } -spin_unlock_irq (&rme32->lock);return 0 ; }
@@ -703,32 +694,24 @@ snd_rme32_capture_hw_params(struct snd_pcm_substream *substream, runtime->dma_bytes =RME32_BUFFER_SIZE ; } -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock);/* enable AutoSync for record-preparing */ rme32->wcreg |=RME32_WCR_AUTOSYNC ;writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); err =snd_rme32_setformat (rme32,params_format (params)); -if (err <0 ) { -spin_unlock_irq (&rme32->lock); +if (err <0 )return err; - } err =snd_rme32_playback_setrate (rme32,params_rate (params)); -if (err <0 ) { -spin_unlock_irq (&rme32->lock); +if (err <0 )return err; - } rate =snd_rme32_capture_getrate (rme32, &isadat);if (rate >0 ) { -if ((int )params_rate (params) != rate) { -spin_unlock_irq (&rme32->lock); +if ((int )params_rate (params) != rate)return -EIO ; - }if ((isadat && runtime->hw.channels_min ==2 ) || - (!isadat && runtime->hw.channels_min ==8 )) { -spin_unlock_irq (&rme32->lock); + (!isadat && runtime->hw.channels_min ==8 ))return -EIO ; - } }/* AutoSync off for recording */ rme32->wcreg &= ~RME32_WCR_AUTOSYNC ;
@@ -737,14 +720,11 @@ snd_rme32_capture_hw_params(struct snd_pcm_substream *substream,snd_rme32_setframelog (rme32,params_channels (params),0 );if (rme32->playback_periodsize !=0 ) {if (params_period_size (params) << rme32->capture_frlog != - rme32->playback_periodsize) { -spin_unlock_irq (&rme32->lock); + rme32->playback_periodsize)return -EBUSY ; - } } rme32->capture_periodsize =params_period_size (params) << rme32->capture_frlog; -spin_unlock_irq (&rme32->lock);return 0 ; }
@@ -824,15 +804,13 @@ static int snd_rme32_playback_spdif_open(struct snd_pcm_substream *substream)snd_pcm_set_sync (substream); -spin_lock_irq (&rme32->lock); -if (rme32->playback_substream !=NULL ) { -spin_unlock_irq (&rme32->lock); -return -EBUSY ; + scoped_guard(spinlock_irq, &rme32->lock) { +if (rme32->playback_substream !=NULL ) +return -EBUSY ; + rme32->wcreg &= ~RME32_WCR_ADAT ; +writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); + rme32->playback_substream = substream; } - rme32->wcreg &= ~RME32_WCR_ADAT ; -writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); - rme32->playback_substream = substream; -spin_unlock_irq (&rme32->lock);if (rme32->fullduplex_mode) runtime->hw = snd_rme32_spdif_fd_info;
@@ -869,13 +847,11 @@ static int snd_rme32_capture_spdif_open(struct snd_pcm_substream *substream)snd_pcm_set_sync (substream); -spin_lock_irq (&rme32->lock); -if (rme32->capture_substream !=NULL ) { -spin_unlock_irq (&rme32->lock); -return -EBUSY ; - } - rme32->capture_substream = substream; -spin_unlock_irq (&rme32->lock); + scoped_guard(spinlock_irq, &rme32->lock) { +if (rme32->capture_substream !=NULL ) +return -EBUSY ; + rme32->capture_substream = substream; + }if (rme32->fullduplex_mode) runtime->hw = snd_rme32_spdif_fd_info;
@@ -909,15 +885,13 @@ snd_rme32_playback_adat_open(struct snd_pcm_substream *substream)snd_pcm_set_sync (substream); -spin_lock_irq (&rme32->lock); -if (rme32->playback_substream !=NULL ) { -spin_unlock_irq (&rme32->lock); -return -EBUSY ; - } - rme32->wcreg |=RME32_WCR_ADAT ; -writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); - rme32->playback_substream = substream; -spin_unlock_irq (&rme32->lock); + scoped_guard(spinlock_irq, &rme32->lock) { +if (rme32->playback_substream !=NULL ) +return -EBUSY ; + rme32->wcreg |=RME32_WCR_ADAT ; +writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); + rme32->playback_substream = substream; + }if (rme32->fullduplex_mode) runtime->hw = snd_rme32_adat_fd_info;
@@ -960,13 +934,11 @@ snd_rme32_capture_adat_open(struct snd_pcm_substream *substream)snd_pcm_set_sync (substream); -spin_lock_irq (&rme32->lock); -if (rme32->capture_substream !=NULL ) { -spin_unlock_irq (&rme32->lock); -return -EBUSY ; - } - rme32->capture_substream = substream; -spin_unlock_irq (&rme32->lock); + scoped_guard(spinlock_irq, &rme32->lock) { +if (rme32->capture_substream !=NULL ) +spin_unlock_irq (&rme32->lock); + rme32->capture_substream = substream; + }snd_rme32_set_buffer_constraint (rme32, runtime);return 0 ;
@@ -977,11 +949,11 @@ static int snd_rme32_playback_close(struct snd_pcm_substream *substream)struct rme32 *rme32 =snd_pcm_substream_chip (substream);int spdif =0 ; -spin_lock_irq (&rme32->lock); - rme32->playback_substream =NULL ; - rme32->playback_periodsize =0 ; - spdif = (rme32->wcreg &RME32_WCR_ADAT ) ==0 ; -spin_unlock_irq (&rme32->lock); + scoped_guard(spinlock_irq, &rme32->lock) { + rme32->playback_substream =NULL ; + rme32->playback_periodsize =0 ; + spdif = (rme32->wcreg &RME32_WCR_ADAT ) ==0 ; + }if (spdif) { rme32->spdif_ctl->vd[0 ].access |=SNDRV_CTL_ELEM_ACCESS_INACTIVE ; snd_ctl_notify(rme32->card, SNDRV_CTL_EVENT_MASK_VALUE |
@@ -995,10 +967,9 @@ static int snd_rme32_capture_close(struct snd_pcm_substream *substream) {struct rme32 *rme32 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); rme32->capture_substream =NULL ; rme32->capture_periodsize =0 ; -spin_unlock_irq (&rme32->lock);return 0 ; }
@@ -1006,7 +977,7 @@ static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream) {struct rme32 *rme32 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock);if (rme32->fullduplex_mode) {memset (&rme32->playback_pcm,0 ,sizeof (rme32->playback_pcm)); rme32->playback_pcm.hw_buffer_size =RME32_BUFFER_SIZE ;
@@ -1017,7 +988,6 @@ static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream)if (rme32->wcreg &RME32_WCR_SEL ) rme32->wcreg &= ~RME32_WCR_MUTE ;writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); -spin_unlock_irq (&rme32->lock);return 0 ; }
@@ -1025,7 +995,7 @@ static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream) {struct rme32 *rme32 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock);if (rme32->fullduplex_mode) {memset (&rme32->capture_pcm,0 ,sizeof (rme32->capture_pcm)); rme32->capture_pcm.hw_buffer_size =RME32_BUFFER_SIZE ;
@@ -1034,7 +1004,6 @@ static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream) }else {writel (0 , rme32->iobase +RME32_IO_RESET_POS ); } -spin_unlock_irq (&rme32->lock);return 0 ; }
@@ -1044,7 +1013,7 @@ snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd)struct rme32 *rme32 =snd_pcm_substream_chip (substream);struct snd_pcm_substream *s; -spin_lock (&rme32->lock); +guard (spinlock)(&rme32->lock);snd_pcm_group_for_each_entry (s, substream) {if (s != rme32->playback_substream && s != rme32->capture_substream)
@@ -1088,7 +1057,6 @@ snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd)snd_rme32_pcm_start (rme32,1 );break ; } -spin_unlock (&rme32->lock);return 0 ; }
@@ -1124,11 +1092,11 @@ static int snd_rme32_playback_fd_ack(struct snd_pcm_substream *substream) rec = &rme32->playback_pcm; cprec = &rme32->capture_pcm; -spin_lock (&rme32->lock); - rec->hw_queue_size =RME32_BUFFER_SIZE ; -if (rme32->running & (1 <<SNDRV_PCM_STREAM_CAPTURE )) - rec->hw_queue_size -= cprec->hw_ready; -spin_unlock (&rme32->lock); + scoped_guard(spinlock, &rme32->lock) { + rec->hw_queue_size =RME32_BUFFER_SIZE ; +if (rme32->running & (1 <<SNDRV_PCM_STREAM_CAPTURE )) + rec->hw_queue_size -= cprec->hw_ready; + }return snd_pcm_indirect_playback_transfer (substream, rec, snd_rme32_pb_trans_copy); }
@@ -1513,10 +1481,9 @@ snd_rme32_get_loopback_control(struct snd_kcontrol *kcontrol, {struct rme32 *rme32 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); ucontrol->value.integer.value[0 ] = rme32->wcreg &RME32_WCR_SEL ?0 :1 ; -spin_unlock_irq (&rme32->lock);return 0 ; } static int
@@ -1528,7 +1495,7 @@ snd_rme32_put_loopback_control(struct snd_kcontrol *kcontrol,int change; val = ucontrol->value.integer.value[0 ] ?0 :RME32_WCR_SEL ; -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); val = (rme32->wcreg & ~RME32_WCR_SEL ) | val; change = val != rme32->wcreg;if (ucontrol->value.integer.value[0 ])
@@ -1537,7 +1504,6 @@ snd_rme32_put_loopback_control(struct snd_kcontrol *kcontrol, val |=RME32_WCR_MUTE ; rme32->wcreg = val;writel (val, rme32->iobase +RME32_IO_CONTROL_REGISTER ); -spin_unlock_irq (&rme32->lock);return change; }
@@ -1572,7 +1538,7 @@ snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol,struct rme32 *rme32 =snd_kcontrol_chip (kcontrol);unsigned int items =3 ; -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); ucontrol->value.enumerated.item[0 ] =snd_rme32_getinputtype (rme32);switch (rme32->pci->device) {
@@ -1591,7 +1557,6 @@ snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol, ucontrol->value.enumerated.item[0 ] = items -1 ; } -spin_unlock_irq (&rme32->lock);return 0 ; } static int
@@ -1616,10 +1581,9 @@ snd_rme32_put_inputtype_control(struct snd_kcontrol *kcontrol, } val = ucontrol->value.enumerated.item[0 ] % items; -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); change = val != (unsigned int )snd_rme32_getinputtype (rme32);snd_rme32_setinputtype (rme32, val); -spin_unlock_irq (&rme32->lock);return change; }
@@ -1640,9 +1604,8 @@ snd_rme32_get_clockmode_control(struct snd_kcontrol *kcontrol, {struct rme32 *rme32 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); ucontrol->value.enumerated.item[0 ] =snd_rme32_getclockmode (rme32); -spin_unlock_irq (&rme32->lock);return 0 ; } static int
@@ -1654,10 +1617,9 @@ snd_rme32_put_clockmode_control(struct snd_kcontrol *kcontrol,int change; val = ucontrol->value.enumerated.item[0 ] %3 ; -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); change = val != (unsigned int )snd_rme32_getclockmode (rme32);snd_rme32_setclockmode (rme32, val); -spin_unlock_irq (&rme32->lock);return change; }
@@ -1707,10 +1669,9 @@ static int snd_rme32_control_spdif_put(struct snd_kcontrol *kcontrol,u32 val; val =snd_rme32_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); change = val != rme32->wcreg_spdif; rme32->wcreg_spdif = val; -spin_unlock_irq (&rme32->lock);return change; }
@@ -1742,13 +1703,12 @@ static int snd_rme32_control_spdif_stream_put(struct snd_kcontrol *kcontrol,u32 val; val =snd_rme32_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme32->lock); +guard (spinlock_irq)(&rme32->lock); change = val != rme32->wcreg_spdif_stream; rme32->wcreg_spdif_stream = val; rme32->wcreg &= ~(RME32_WCR_PRO |RME32_WCR_EMP ); rme32->wcreg |= val;writel (rme32->wcreg, rme32->iobase +RME32_IO_CONTROL_REGISTER ); -spin_unlock_irq (&rme32->lock);return change; }
Signature · 1 line
2.50.1
PATCH 50/61 ALSA: rme96: 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/pci/rme96.c | 211 +++++++++++++++++++--------------------------- 1 file changed, 85 insertions(+), 126 deletions(-)
sound/pci/rme96.c +85 -126
@@ -964,48 +964,45 @@ snd_rme96_playback_hw_params(struct snd_pcm_substream *substream, runtime->dma_addr = rme96->port +RME96_IO_PLAY_BUFFER ; runtime->dma_bytes =RME96_BUFFER_SIZE ; -spin_lock_irq (&rme96->lock); - rate =0 ; -if (!(rme96->wcreg &RME96_WCR_MASTER ) && -snd_rme96_getinputtype (rme96) !=RME96_INPUT_ANALOG ) - rate =snd_rme96_capture_getrate (rme96, &dummy); -if (rate >0 ) { -/* slave clock */ -if ((int )params_rate (params) != rate) { - err = -EIO ; - goto error; + scoped_guard(spinlock_irq, &rme96->lock) { + rate =0 ; +if (!(rme96->wcreg &RME96_WCR_MASTER ) && +snd_rme96_getinputtype (rme96) !=RME96_INPUT_ANALOG ) + rate =snd_rme96_capture_getrate (rme96, &dummy); +if (rate >0 ) { +/* slave clock */ +if ((int )params_rate (params) != rate) +return -EIO ; + }else { + err =snd_rme96_playback_setrate (rme96,params_rate (params)); +if (err <0 ) +return err; + apply_dac_volume = err >0 ;/* need to restore volume later? */ } - }else { - err =snd_rme96_playback_setrate (rme96,params_rate (params)); + + err =snd_rme96_playback_setformat (rme96,params_format (params));if (err <0 ) goto error; - apply_dac_volume = err >0 ;/* need to restore volume later? */ - } - - err =snd_rme96_playback_setformat (rme96,params_format (params)); -if (err <0 ) - goto error; -snd_rme96_setframelog (rme96,params_channels (params),1 ); -if (rme96->capture_periodsize !=0 ) { -if (params_period_size (params) << rme96->playback_frlog != - rme96->capture_periodsize) - { - err = -EBUSY ; - goto error; +snd_rme96_setframelog (rme96,params_channels (params),1 ); +if (rme96->capture_periodsize !=0 ) { +if (params_period_size (params) << rme96->playback_frlog != + rme96->capture_periodsize) { + err = -EBUSY ; + goto error; + } + } + rme96->playback_periodsize = +params_period_size (params) << rme96->playback_frlog; +snd_rme96_set_period_properties (rme96, rme96->playback_periodsize); +/* S/PDIF setup */ +if ((rme96->wcreg &RME96_WCR_ADAT ) ==0 ) { + rme96->wcreg &= ~(RME96_WCR_PRO |RME96_WCR_DOLBY |RME96_WCR_EMP ); +writel (rme96->wcreg |= rme96->wcreg_spdif_stream, rme96->iobase +RME96_IO_CONTROL_REGISTER ); } - } - rme96->playback_periodsize = -params_period_size (params) << rme96->playback_frlog; -snd_rme96_set_period_properties (rme96, rme96->playback_periodsize); -/* S/PDIF setup */ -if ((rme96->wcreg &RME96_WCR_ADAT ) ==0 ) { - rme96->wcreg &= ~(RME96_WCR_PRO |RME96_WCR_DOLBY |RME96_WCR_EMP ); -writel (rme96->wcreg |= rme96->wcreg_spdif_stream, rme96->iobase +RME96_IO_CONTROL_REGISTER ); - } - err =0 ; + err =0 ; + } error: -spin_unlock_irq (&rme96->lock);if (apply_dac_volume) {usleep_range (3000 ,10000 );snd_rme96_apply_dac_volume (rme96);
@@ -1027,45 +1024,33 @@ snd_rme96_capture_hw_params(struct snd_pcm_substream *substream, runtime->dma_addr = rme96->port +RME96_IO_REC_BUFFER ; runtime->dma_bytes =RME96_BUFFER_SIZE ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); err =snd_rme96_capture_setformat (rme96,params_format (params)); -if (err <0 ) { -spin_unlock_irq (&rme96->lock); +if (err <0 )return err; - }if (snd_rme96_getinputtype (rme96) ==RME96_INPUT_ANALOG ) { err =snd_rme96_capture_analog_setrate (rme96,params_rate (params)); -if (err <0 ) { -spin_unlock_irq (&rme96->lock); +if (err <0 )return err; - } }else { rate =snd_rme96_capture_getrate (rme96, &isadat);if (rate >0 ) { -if ((int )params_rate (params) != rate) { -spin_unlock_irq (&rme96->lock); +if ((int )params_rate (params) != rate)return -EIO ; - }if ((isadat && runtime->hw.channels_min ==2 ) || - (!isadat && runtime->hw.channels_min ==8 )) { -spin_unlock_irq (&rme96->lock); + (!isadat && runtime->hw.channels_min ==8 ))return -EIO ; - } } }snd_rme96_setframelog (rme96,params_channels (params),0 );if (rme96->playback_periodsize !=0 ) {if (params_period_size (params) << rme96->capture_frlog != rme96->playback_periodsize) - { -spin_unlock_irq (&rme96->lock);return -EBUSY ; - } } rme96->capture_periodsize =params_period_size (params) << rme96->capture_frlog;snd_rme96_set_period_properties (rme96, rme96->capture_periodsize); -spin_unlock_irq (&rme96->lock);return 0 ; }
@@ -1165,15 +1150,13 @@ snd_rme96_playback_spdif_open(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;snd_pcm_set_sync (substream); -spin_lock_irq (&rme96->lock); -if (rme96->playback_substream) { -spin_unlock_irq (&rme96->lock); -return -EBUSY ; - } - rme96->wcreg &= ~RME96_WCR_ADAT ; -writel (rme96->wcreg, rme96->iobase +RME96_IO_CONTROL_REGISTER ); - rme96->playback_substream = substream; -spin_unlock_irq (&rme96->lock); + scoped_guard(spinlock_irq, &rme96->lock) { +if (rme96->playback_substream) +return -EBUSY ; + rme96->wcreg &= ~RME96_WCR_ADAT ; +writel (rme96->wcreg, rme96->iobase +RME96_IO_CONTROL_REGISTER ); + rme96->playback_substream = substream; + } runtime->hw = snd_rme96_playback_spdif_info; if (!(rme96->wcreg & RME96_WCR_MASTER) &&
@@ -1215,13 +1198,11 @@ snd_rme96_capture_spdif_open(struct snd_pcm_substream *substream) } } -spin_lock_irq (&rme96->lock); -if (rme96->capture_substream) { -spin_unlock_irq (&rme96->lock); -return -EBUSY ; - } - rme96->capture_substream = substream; -spin_unlock_irq (&rme96->lock); + scoped_guard(spinlock_irq, &rme96->lock) { +if (rme96->capture_substream) +return -EBUSY ; + rme96->capture_substream = substream; + }rme96_set_buffer_size_constraint (rme96, runtime);return 0 ;
@@ -1235,15 +1216,13 @@ snd_rme96_playback_adat_open(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;snd_pcm_set_sync (substream); -spin_lock_irq (&rme96->lock); -if (rme96->playback_substream) { -spin_unlock_irq (&rme96->lock); -return -EBUSY ; - } - rme96->wcreg |=RME96_WCR_ADAT ; -writel (rme96->wcreg, rme96->iobase +RME96_IO_CONTROL_REGISTER ); - rme96->playback_substream = substream; -spin_unlock_irq (&rme96->lock); + scoped_guard(spinlock_irq, &rme96->lock) { +if (rme96->playback_substream) +return -EBUSY ; + rme96->wcreg |=RME96_WCR_ADAT ; +writel (rme96->wcreg, rme96->iobase +RME96_IO_CONTROL_REGISTER ); + rme96->playback_substream = substream; + } runtime->hw = snd_rme96_playback_adat_info; if (!(rme96->wcreg & RME96_WCR_MASTER) &&
@@ -1285,13 +1264,11 @@ snd_rme96_capture_adat_open(struct snd_pcm_substream *substream) runtime->hw.rate_max = rate; } -spin_lock_irq (&rme96->lock); -if (rme96->capture_substream) { -spin_unlock_irq (&rme96->lock); -return -EBUSY ; - } - rme96->capture_substream = substream; -spin_unlock_irq (&rme96->lock); + scoped_guard(spinlock_irq, &rme96->lock) { +if (rme96->capture_substream) +return -EBUSY ; + rme96->capture_substream = substream; + }rme96_set_buffer_size_constraint (rme96, runtime);return 0 ;
@@ -1303,14 +1280,13 @@ snd_rme96_playback_close(struct snd_pcm_substream *substream)struct rme96 *rme96 =snd_pcm_substream_chip (substream);int spdif =0 ; -spin_lock_irq (&rme96->lock); -if (RME96_ISPLAYING (rme96)) { -snd_rme96_trigger (rme96,RME96_STOP_PLAYBACK ); + scoped_guard(spinlock_irq, &rme96->lock) { +if (RME96_ISPLAYING (rme96)) +snd_rme96_trigger (rme96,RME96_STOP_PLAYBACK ); + rme96->playback_substream =NULL ; + rme96->playback_periodsize =0 ; + spdif = (rme96->wcreg &RME96_WCR_ADAT ) ==0 ; } - rme96->playback_substream =NULL ; - rme96->playback_periodsize =0 ; - spdif = (rme96->wcreg &RME96_WCR_ADAT ) ==0 ; -spin_unlock_irq (&rme96->lock);if (spdif) { rme96->spdif_ctl->vd[0 ].access |=SNDRV_CTL_ELEM_ACCESS_INACTIVE ; snd_ctl_notify(rme96->card, SNDRV_CTL_EVENT_MASK_VALUE |
@@ -1324,13 +1300,12 @@ snd_rme96_capture_close(struct snd_pcm_substream *substream) {struct rme96 *rme96 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock);if (RME96_ISRECORDING (rme96)) {snd_rme96_trigger (rme96,RME96_STOP_CAPTURE ); } rme96->capture_substream =NULL ; rme96->capture_periodsize =0 ; -spin_unlock_irq (&rme96->lock);return 0 ; }
@@ -1339,12 +1314,11 @@ snd_rme96_playback_prepare(struct snd_pcm_substream *substream) {struct rme96 *rme96 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock);if (RME96_ISPLAYING (rme96)) {snd_rme96_trigger (rme96,RME96_STOP_PLAYBACK ); }writel (0 , rme96->iobase +RME96_IO_RESET_PLAY_POS ); -spin_unlock_irq (&rme96->lock);return 0 ; }
@@ -1353,12 +1327,11 @@ snd_rme96_capture_prepare(struct snd_pcm_substream *substream) {struct rme96 *rme96 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock);if (RME96_ISRECORDING (rme96)) {snd_rme96_trigger (rme96,RME96_STOP_CAPTURE ); }writel (0 , rme96->iobase +RME96_IO_RESET_REC_POS ); -spin_unlock_irq (&rme96->lock);return 0 ; }
@@ -1829,9 +1802,8 @@ snd_rme96_get_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_ele {struct rme96 *rme96 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); ucontrol->value.integer.value[0 ] = rme96->wcreg &RME96_WCR_SEL ?0 :1 ; -spin_unlock_irq (&rme96->lock);return 0 ; } static int
@@ -1842,12 +1814,11 @@ snd_rme96_put_loopback_control(struct snd_kcontrol *kcontrol, struct snd_ctl_eleint change; val = ucontrol->value.integer.value[0 ] ?0 :RME96_WCR_SEL ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); val = (rme96->wcreg & ~RME96_WCR_SEL ) | val; change = val != rme96->wcreg; rme96->wcreg = val;writel (val, rme96->iobase +RME96_IO_CONTROL_REGISTER ); -spin_unlock_irq (&rme96->lock);return change; }
@@ -1893,7 +1864,7 @@ snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elstruct rme96 *rme96 =snd_kcontrol_chip (kcontrol);unsigned int items =3 ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); ucontrol->value.enumerated.item[0 ] =snd_rme96_getinputtype (rme96);switch (rme96->pci->device) {
@@ -1923,7 +1894,6 @@ snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el ucontrol->value.enumerated.item[0 ] = items -1 ; } -spin_unlock_irq (&rme96->lock);return 0 ; } static int
@@ -1961,10 +1931,9 @@ snd_rme96_put_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el } } -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = (int )val !=snd_rme96_getinputtype (rme96);snd_rme96_setinputtype (rme96, val); -spin_unlock_irq (&rme96->lock);return change; }
@@ -1980,9 +1949,8 @@ snd_rme96_get_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el {struct rme96 *rme96 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); ucontrol->value.enumerated.item[0 ] =snd_rme96_getclockmode (rme96); -spin_unlock_irq (&rme96->lock);return 0 ; } static int
@@ -1993,10 +1961,9 @@ snd_rme96_put_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elint change; val = ucontrol->value.enumerated.item[0 ] %3 ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = (int )val !=snd_rme96_getclockmode (rme96);snd_rme96_setclockmode (rme96, val); -spin_unlock_irq (&rme96->lock);return change; }
@@ -2014,9 +1981,8 @@ snd_rme96_get_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_ {struct rme96 *rme96 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); ucontrol->value.enumerated.item[0 ] =snd_rme96_getattenuation (rme96); -spin_unlock_irq (&rme96->lock);return 0 ; } static int
@@ -2027,11 +1993,10 @@ snd_rme96_put_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_int change; val = ucontrol->value.enumerated.item[0 ] %4 ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = (int )val !=snd_rme96_getattenuation (rme96);snd_rme96_setattenuation (rme96, val); -spin_unlock_irq (&rme96->lock);return change; }
@@ -2047,9 +2012,8 @@ snd_rme96_get_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_el {struct rme96 *rme96 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); ucontrol->value.enumerated.item[0 ] =snd_rme96_getmontracks (rme96); -spin_unlock_irq (&rme96->lock);return 0 ; } static int
@@ -2060,10 +2024,9 @@ snd_rme96_put_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elint change; val = ucontrol->value.enumerated.item[0 ] %4 ; -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = (int )val !=snd_rme96_getmontracks (rme96);snd_rme96_setmontracks (rme96, val); -spin_unlock_irq (&rme96->lock);return change; }
@@ -2111,10 +2074,9 @@ static int snd_rme96_control_spdif_put(struct snd_kcontrol *kcontrol, struct sndu32 val; val =snd_rme96_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = val != rme96->wcreg_spdif; rme96->wcreg_spdif = val; -spin_unlock_irq (&rme96->lock);return change; }
@@ -2140,13 +2102,12 @@ static int snd_rme96_control_spdif_stream_put(struct snd_kcontrol *kcontrol, stru32 val; val =snd_rme96_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); change = val != rme96->wcreg_spdif_stream; rme96->wcreg_spdif_stream = val; rme96->wcreg &= ~(RME96_WCR_PRO |RME96_WCR_DOLBY |RME96_WCR_EMP ); rme96->wcreg |= val;writel (rme96->wcreg, rme96->iobase +RME96_IO_CONTROL_REGISTER ); -spin_unlock_irq (&rme96->lock);return change; }
@@ -2180,10 +2141,9 @@ snd_rme96_dac_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu {struct rme96 *rme96 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); u->value.integer.value[0 ] = rme96->vol[0 ]; u->value.integer.value[1 ] = rme96->vol[1 ]; -spin_unlock_irq (&rme96->lock);return 0 ; }
@@ -2199,7 +2159,7 @@ snd_rme96_dac_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valuif (!RME96_HAS_ANALOG_OUT (rme96))return -EINVAL ; maxvol =RME96_185X_MAX_OUT (rme96); -spin_lock_irq (&rme96->lock); +guard (spinlock_irq)(&rme96->lock); vol = u->value.integer.value[0 ];if (vol != rme96->vol[0 ] && vol <= maxvol) { rme96->vol[0 ] = vol;
@@ -2212,7 +2172,6 @@ snd_rme96_dac_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu }if (change)snd_rme96_apply_dac_volume (rme96); -spin_unlock_irq (&rme96->lock);return change; }
Signature · 1 line
2.50.1
PATCH 51/61 ALSA: hdsp: 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/pci/rme9652/hdsp.c | 309 ++++++++++++++++----------------------- 1 file changed, 124 insertions(+), 185 deletions(-)
sound/pci/rme9652/hdsp.c +124 -185
@@ -691,7 +691,6 @@ static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,static int snd_hdsp_load_firmware_from_cache (struct hdsp *hdsp) {int i; -unsigned long flags;const u32 *cache;if (hdsp->fw_uploaded)
@@ -746,9 +745,8 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {if (hdsp->state & HDSP_InitializationComplete) {dev_info (hdsp->card->dev,"firmware loaded from cache, restoring defaults\n" ); -spin_lock_irqsave (&hdsp->lock, flags); +guard (spinlock_irqsave)(&hdsp->lock);snd_hdsp_set_defaults (hdsp); -spin_unlock_irqrestore (&hdsp->lock, flags); } hdsp->state |= HDSP_FirmwareLoaded;
@@ -939,14 +937,12 @@ static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned shortstatic int snd_hdsp_use_is_exclusive (struct hdsp *hdsp) { -unsigned long flags;int ret =1 ; -spin_lock_irqsave (&hdsp->lock, flags); +guard (spinlock_irqsave)(&hdsp->lock);if ((hdsp->playback_pid != hdsp->capture_pid) && (hdsp->playback_pid >=0 ) && (hdsp->capture_pid >=0 )) ret =0 ; -spin_unlock_irqrestore (&hdsp->lock, flags);return ret; }
@@ -1063,8 +1059,6 @@ static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames) {int n; -spin_lock_irq (&s->lock); - frames >>=7 ; n =0 ;while (frames) {
@@ -1079,8 +1073,6 @@ static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)hdsp_compute_period_size (s); -spin_unlock_irq (&s->lock); -return 0 ; }
@@ -1306,7 +1298,6 @@ static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi) { -unsigned long flags;int n_pending;int to_write;int i;
@@ -1314,7 +1305,7 @@ static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)/* Output is not interrupt driven */ -spin_lock_irqsave (&hmidi->lock, flags); +guard (spinlock_irqsave)(&hmidi->lock);if (hmidi->output) {if (!snd_rawmidi_transmit_empty (hmidi->output)) { n_pending =snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id);
@@ -1330,40 +1321,38 @@ static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi) } } } -spin_unlock_irqrestore (&hmidi->lock, flags);return 0 ; }static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi) {unsigned char buf[128 ];/* this buffer is designed to match the MIDI input FIFO size */ -unsigned long flags;int n_pending;int i; -spin_lock_irqsave (&hmidi->lock, flags); - n_pending =snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id); -if (n_pending >0 ) { -if (hmidi->input) { -if (n_pending > (int )sizeof (buf)) - n_pending =sizeof (buf); -for (i =0 ; i < n_pending; ++i) - buf[i] =snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); -if (n_pending) -snd_rawmidi_receive (hmidi->input, buf, n_pending); - }else { -/* flush the MIDI input FIFO */ -while (--n_pending) -snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); + scoped_guard(spinlock_irqsave, &hmidi->lock) { + n_pending =snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id); +if (n_pending >0 ) { +if (hmidi->input) { +if (n_pending > (int )sizeof (buf)) + n_pending =sizeof (buf); +for (i =0 ; i < n_pending; ++i) + buf[i] =snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); +if (n_pending) +snd_rawmidi_receive (hmidi->input, buf, n_pending); + }else { +/* flush the MIDI input FIFO */ +while (--n_pending) +snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); + } } + hmidi->pending =0 ; +if (hmidi->id) + hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; +else + hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; +hdsp_write (hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); } - hmidi->pending =0 ; -if (hmidi->id) - hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; -else - hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; -hdsp_write (hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); -spin_unlock_irqrestore (&hmidi->lock, flags);return snd_hdsp_midi_output_write (hmidi); }
@@ -1371,13 +1360,12 @@ static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, {struct hdsp *hdsp;struct hdsp_midi *hmidi; -unsigned long flags;u32 ie; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; hdsp = hmidi->hdsp; ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable; -spin_lock_irqsave (&hdsp->lock, flags); +guard (spinlock_irqsave)(&hdsp->lock);if (up) {if (!(hdsp->control_register & ie)) {snd_hdsp_flush_midi_input (hdsp, hmidi->id);
@@ -1388,16 +1376,14 @@ static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, }hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register); -spin_unlock_irqrestore (&hdsp->lock, flags); }static void snd_hdsp_midi_output_timer (struct timer_list *t) {struct hdsp_midi *hmidi =timer_container_of (hmidi, t, timer); -unsigned long flags;snd_hdsp_midi_output_write (hmidi); -spin_lock_irqsave (&hmidi->lock, flags); +guard (spinlock_irqsave)(&hmidi->lock);/* this does not bump hmidi->istimer, because the kernel automatically removed the timer when it
@@ -1407,29 +1393,26 @@ static void snd_hdsp_midi_output_timer(struct timer_list *t)if (hmidi->istimer)mod_timer (&hmidi->timer,1 + jiffies); - -spin_unlock_irqrestore (&hmidi->lock, flags); }static void snd_hdsp_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) {struct hdsp_midi *hmidi; -unsigned long flags; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; -spin_lock_irqsave (&hmidi->lock, flags); -if (up) { -if (!hmidi->istimer) { -timer_setup (&hmidi->timer, snd_hdsp_midi_output_timer, -0 ); -mod_timer (&hmidi->timer,1 + jiffies); - hmidi->istimer++; + scoped_guard(spinlock_irqsave, &hmidi->lock) { +if (up) { +if (!hmidi->istimer) { +timer_setup (&hmidi->timer, snd_hdsp_midi_output_timer, +0 ); +mod_timer (&hmidi->timer,1 + jiffies); + hmidi->istimer++; + } + }else { +if (hmidi->istimer && --hmidi->istimer <=0 ) +timer_delete (&hmidi->timer); } - }else { -if (hmidi->istimer && --hmidi->istimer <=0 ) -timer_delete (&hmidi->timer); } -spin_unlock_irqrestore (&hmidi->lock, flags);if (up)snd_hdsp_midi_output_write (hmidi); }
@@ -1439,10 +1422,9 @@ static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)struct hdsp_midi *hmidi; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock);snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id); hmidi->input = substream; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -1452,9 +1434,8 @@ static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)struct hdsp_midi *hmidi; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->output = substream; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -1466,9 +1447,8 @@ static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)snd_hdsp_midi_input_trigger (substream,0 ); hmidi = (struct hdsp_midi *) substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->input =NULL ; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -1480,9 +1460,8 @@ static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)snd_hdsp_midi_output_trigger (substream,0 ); hmidi = (struct hdsp_midi *) substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->output =NULL ; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -1579,10 +1558,9 @@ static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_u32 val; val =snd_hdsp_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = val != hdsp->creg_spdif; hdsp->creg_spdif = val; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -1608,12 +1586,11 @@ static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struu32 val; val =snd_hdsp_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = val != hdsp->creg_spdif_stream; hdsp->creg_spdif_stream = val; hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register |= val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -1679,11 +1656,10 @@ static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_eif (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.enumerated.item[0 ] % ((hdsp->io_type ==H9632 ) ?4 :3 ); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = val !=hdsp_spdif_in (hdsp);if (change)hdsp_set_spdif_input (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -1720,9 +1696,8 @@ static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol,struct hdsp *hdsp =snd_kcontrol_chip (kcontrol);u32 regmask = kcontrol->private_value; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); ucontrol->value.integer.value[0 ] =hdsp_toggle_setting (hdsp, regmask); -spin_unlock_irq (&hdsp->lock);return 0 ; }
@@ -1737,11 +1712,10 @@ static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,if (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int ) val !=hdsp_toggle_setting (hdsp, regmask);if (change)hdsp_set_toggle_setting (hdsp, regmask, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2047,12 +2021,11 @@ static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_cif (val >6 ) val =6 ; } -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_clock_source (hdsp)) change = (hdsp_set_clock_source (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2147,12 +2120,11 @@ static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_el val = ucontrol->value.enumerated.item[0 ];if (val <0 ) val =0 ;if (val >2 ) val =2 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_da_gain (hdsp)) change = (hdsp_set_da_gain (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2226,12 +2198,11 @@ static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_el val = ucontrol->value.enumerated.item[0 ];if (val <0 ) val =0 ;if (val >2 ) val =2 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_ad_gain (hdsp)) change = (hdsp_set_ad_gain (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2305,12 +2276,11 @@ static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl val = ucontrol->value.enumerated.item[0 ];if (val <0 ) val =0 ;if (val >2 ) val =2 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_phone_gain (hdsp)) change = (hdsp_set_phone_gain (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2436,10 +2406,9 @@ static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ } val = ucontrol->value.enumerated.item[0 ] % max; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int )val !=hdsp_pref_sync_ref (hdsp);hdsp_set_pref_sync_ref (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2519,9 +2488,8 @@ static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct sn {struct hdsp *hdsp =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); ucontrol->value.integer.value[0 ] = hdsp->precise_ptr; -spin_unlock_irq (&hdsp->lock);return 0 ; }
@@ -2534,10 +2502,9 @@ static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snif (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int )val != hdsp->precise_ptr;hdsp_set_precise_pointer (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2565,9 +2532,8 @@ static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ {struct hdsp *hdsp =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); ucontrol->value.integer.value[0 ] = hdsp->use_midi_work; -spin_unlock_irq (&hdsp->lock);return 0 ; }
@@ -2580,10 +2546,9 @@ static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_if (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int )val != hdsp->use_midi_work;hdsp_set_use_midi_work (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2624,9 +2589,8 @@ static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elemelse addr =hdsp_input_to_output_key (hdsp,source, destination); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); ucontrol->value.integer.value[2 ] =hdsp_read_gain (hdsp, addr); -spin_unlock_irq (&hdsp->lock);return 0 ; }
@@ -2652,11 +2616,10 @@ static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem gain = ucontrol->value.integer.value[2 ]; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = gain !=hdsp_read_gain (hdsp, addr);if (change)hdsp_write_gain (hdsp, addr, gain); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -2869,12 +2832,11 @@ static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctlif (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ]; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_dds_offset (hdsp)) change = (hdsp_set_dds_offset (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -3018,12 +2980,11 @@ static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ct val =0 ;if (val >4 ) val =4 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_rpm_input12 (hdsp)) change = (hdsp_set_rpm_input12 (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -3103,12 +3064,11 @@ static int snd_hdsp_put_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ct val =0 ;if (val >4 ) val =4 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (val !=hdsp_rpm_input34 (hdsp)) change = (hdsp_set_rpm_input34 (hdsp, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdsp->lock);return change; }
@@ -3149,10 +3109,9 @@ static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctlif (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int )val !=hdsp_rpm_bypass (hdsp);hdsp_set_rpm_bypass (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -3201,10 +3160,9 @@ static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct sndif (!snd_hdsp_use_is_exclusive (hdsp))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); change = (int )val !=hdsp_rpm_disconnect (hdsp);hdsp_set_rpm_disconnect (hdsp, val); -spin_unlock_irq (&hdsp->lock);return change; }
@@ -4051,7 +4009,7 @@ static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,if (hdsp_check_for_firmware (hdsp,1 ))return -EIO ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
@@ -4071,39 +4029,31 @@ static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,*/ if (params_rate (params) != hdsp->system_sample_rate) { -spin_unlock_irq (&hdsp->lock);_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_RATE );return -EBUSY ; }if (params_period_size (params) != hdsp->period_bytes /4 ) { -spin_unlock_irq (&hdsp->lock);_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_PERIOD_SIZE );return -EBUSY ; }/* We're fine. */ -spin_unlock_irq (&hdsp->lock);return 0 ; - }else { -spin_unlock_irq (&hdsp->lock); }/* how to make sure that the rate matches an externally-set one ? */ -spin_lock_irq (&hdsp->lock);if (! hdsp->clock_source_locked) { err =hdsp_set_rate (hdsp,params_rate (params),0 );if (err <0 ) { -spin_unlock_irq (&hdsp->lock);_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_RATE );return err; } } -spin_unlock_irq (&hdsp->lock); err =hdsp_set_interrupt_interval (hdsp,params_period_size (params));if (err <0 ) {
@@ -4160,7 +4110,7 @@ static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)if (hdsp_check_for_firmware (hdsp,0 ))/* no auto-loading in trigger */ return -EIO ; -spin_lock (&hdsp->lock); +guard (spinlock)(&hdsp->lock); running = hdsp->running;switch (cmd) {case SNDRV_PCM_TRIGGER_START :
@@ -4171,7 +4121,6 @@ static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)break ;default :snd_BUG (); -spin_unlock (&hdsp->lock);return -EINVAL ; }if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK )
@@ -4211,7 +4160,6 @@ static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)else if (hdsp->running && !running)hdsp_stop_audio (hdsp); hdsp->running = running; -spin_unlock (&hdsp->lock);return 0 ; }
@@ -4227,10 +4175,9 @@ static int snd_hdsp_prepare(struct snd_pcm_substream *substream)if (hdsp_check_for_firmware (hdsp,1 ))return -EIO ; -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock);if (!hdsp->running)hdsp_reset_hw_pointer (hdsp); -spin_unlock_irq (&hdsp->lock);return result; }
@@ -4473,17 +4420,15 @@ static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)if (hdsp_check_for_firmware (hdsp,1 ))return -EIO ; -spin_lock_irq (&hdsp->lock); + scoped_guard(spinlock_irq, &hdsp->lock) { +snd_pcm_set_sync (substream); -snd_pcm_set_sync (substream); + runtime->hw = snd_hdsp_playback_subinfo; +snd_pcm_set_runtime_buffer (substream, &hdsp->playback_dma_buf); - runtime->hw = snd_hdsp_playback_subinfo; -snd_pcm_set_runtime_buffer (substream, &hdsp->playback_dma_buf); - - hdsp->playback_pid = current->pid; - hdsp->playback_substream = substream; - -spin_unlock_irq (&hdsp->lock); + hdsp->playback_pid = current->pid; + hdsp->playback_substream = substream; + }snd_pcm_hw_constraint_msbits (runtime,0 ,32 ,24 );snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , &hdsp_hw_constraints_period_sizes);
@@ -4523,12 +4468,10 @@ static int snd_hdsp_playback_release(struct snd_pcm_substream *substream) {struct hdsp *hdsp =snd_pcm_substream_chip (substream); -spin_lock_irq (&hdsp->lock); - - hdsp->playback_pid =-1 ; - hdsp->playback_substream =NULL ; - -spin_unlock_irq (&hdsp->lock); + scoped_guard(spinlock_irq, &hdsp->lock) { + hdsp->playback_pid =-1 ; + hdsp->playback_substream =NULL ; + }if (RPM != hdsp->io_type) { hdsp->spdif_ctl->vd[0 ].access |=SNDRV_CTL_ELEM_ACCESS_INACTIVE ;
@@ -4550,17 +4493,15 @@ static int snd_hdsp_capture_open(struct snd_pcm_substream *substream)if (hdsp_check_for_firmware (hdsp,1 ))return -EIO ; -spin_lock_irq (&hdsp->lock); + scoped_guard(spinlock_irq, &hdsp->lock) { +snd_pcm_set_sync (substream); -snd_pcm_set_sync (substream); + runtime->hw = snd_hdsp_capture_subinfo; +snd_pcm_set_runtime_buffer (substream, &hdsp->capture_dma_buf); - runtime->hw = snd_hdsp_capture_subinfo; -snd_pcm_set_runtime_buffer (substream, &hdsp->capture_dma_buf); - - hdsp->capture_pid = current->pid; - hdsp->capture_substream = substream; - -spin_unlock_irq (&hdsp->lock); + hdsp->capture_pid = current->pid; + hdsp->capture_substream = substream; + }snd_pcm_hw_constraint_msbits (runtime,0 ,32 ,24 );snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , &hdsp_hw_constraints_period_sizes);
@@ -4588,12 +4529,11 @@ static int snd_hdsp_capture_release(struct snd_pcm_substream *substream) {struct hdsp *hdsp =snd_pcm_substream_chip (substream); -spin_lock_irq (&hdsp->lock); +guard (spinlock_irq)(&hdsp->lock); hdsp->capture_pid =-1 ; hdsp->capture_substream =NULL ; -spin_unlock_irq (&hdsp->lock);return 0 ; }
@@ -4756,7 +4696,6 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne }case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO : {struct hdsp_config_info info; -unsigned long flags;int i; err =hdsp_check_for_iobox (hdsp);
@@ -4768,48 +4707,48 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsignereturn err;memset (&info,0 ,sizeof (info)); -spin_lock_irqsave (&hdsp->lock, flags); - info.pref_sync_ref = (unsigned char )hdsp_pref_sync_ref (hdsp); - info.wordclock_sync_check = (unsigned char )hdsp_wc_sync_check (hdsp); -if (hdsp->io_type !=H9632 ) - info.adatsync_sync_check = (unsigned char )hdsp_adatsync_sync_check (hdsp); - info.spdif_sync_check = (unsigned char )hdsp_spdif_sync_check (hdsp); -for (i =0 ; i < ((hdsp->io_type != Multiface && hdsp->io_type !=RPM && hdsp->io_type !=H9632 ) ?3 :1 ); ++i) - info.adat_sync_check[i] = (unsigned char )hdsp_adat_sync_check (hdsp, i); - info.spdif_in = (unsigned char )hdsp_spdif_in (hdsp); - info.spdif_out = (unsigned char )hdsp_toggle_setting (hdsp, - HDSP_SPDIFOpticalOut); - info.spdif_professional = (unsigned char ) -hdsp_toggle_setting (hdsp, HDSP_SPDIFProfessional); - info.spdif_emphasis = (unsigned char ) -hdsp_toggle_setting (hdsp, HDSP_SPDIFEmphasis); - info.spdif_nonaudio = (unsigned char ) -hdsp_toggle_setting (hdsp, HDSP_SPDIFNonAudio); - info.spdif_sample_rate =hdsp_spdif_sample_rate (hdsp); - info.system_sample_rate = hdsp->system_sample_rate; - info.autosync_sample_rate =hdsp_external_sample_rate (hdsp); - info.system_clock_mode = (unsigned char )hdsp_system_clock_mode (hdsp); - info.clock_source = (unsigned char )hdsp_clock_source (hdsp); - info.autosync_ref = (unsigned char )hdsp_autosync_ref (hdsp); - info.line_out = (unsigned char ) -hdsp_toggle_setting (hdsp, HDSP_LineOut); -if (hdsp->io_type ==H9632 ) { - info.da_gain = (unsigned char )hdsp_da_gain (hdsp); - info.ad_gain = (unsigned char )hdsp_ad_gain (hdsp); - info.phone_gain = (unsigned char )hdsp_phone_gain (hdsp); - info.xlr_breakout_cable = - (unsigned char )hdsp_toggle_setting (hdsp, - HDSP_XLRBreakoutCable); + scoped_guard(spinlock_irqsave, &hdsp->lock) { + info.pref_sync_ref = (unsigned char )hdsp_pref_sync_ref (hdsp); + info.wordclock_sync_check = (unsigned char )hdsp_wc_sync_check (hdsp); +if (hdsp->io_type !=H9632 ) + info.adatsync_sync_check = (unsigned char )hdsp_adatsync_sync_check (hdsp); + info.spdif_sync_check = (unsigned char )hdsp_spdif_sync_check (hdsp); +for (i =0 ; i < ((hdsp->io_type != Multiface && hdsp->io_type !=RPM && hdsp->io_type !=H9632 ) ?3 :1 ); ++i) + info.adat_sync_check[i] = (unsigned char )hdsp_adat_sync_check (hdsp, i); + info.spdif_in = (unsigned char )hdsp_spdif_in (hdsp); + info.spdif_out = (unsigned char )hdsp_toggle_setting (hdsp, + HDSP_SPDIFOpticalOut); + info.spdif_professional = (unsigned char ) +hdsp_toggle_setting (hdsp, HDSP_SPDIFProfessional); + info.spdif_emphasis = (unsigned char ) +hdsp_toggle_setting (hdsp, HDSP_SPDIFEmphasis); + info.spdif_nonaudio = (unsigned char ) +hdsp_toggle_setting (hdsp, HDSP_SPDIFNonAudio); + info.spdif_sample_rate =hdsp_spdif_sample_rate (hdsp); + info.system_sample_rate = hdsp->system_sample_rate; + info.autosync_sample_rate =hdsp_external_sample_rate (hdsp); + info.system_clock_mode = (unsigned char )hdsp_system_clock_mode (hdsp); + info.clock_source = (unsigned char )hdsp_clock_source (hdsp); + info.autosync_ref = (unsigned char )hdsp_autosync_ref (hdsp); + info.line_out = (unsigned char ) +hdsp_toggle_setting (hdsp, HDSP_LineOut); +if (hdsp->io_type ==H9632 ) { + info.da_gain = (unsigned char )hdsp_da_gain (hdsp); + info.ad_gain = (unsigned char )hdsp_ad_gain (hdsp); + info.phone_gain = (unsigned char )hdsp_phone_gain (hdsp); + info.xlr_breakout_cable = + (unsigned char )hdsp_toggle_setting (hdsp, + HDSP_XLRBreakoutCable); - }else if (hdsp->io_type ==RPM ) { - info.da_gain = (unsigned char )hdsp_rpm_input12 (hdsp); - info.ad_gain = (unsigned char )hdsp_rpm_input34 (hdsp); + }else if (hdsp->io_type ==RPM ) { + info.da_gain = (unsigned char )hdsp_rpm_input12 (hdsp); + info.ad_gain = (unsigned char )hdsp_rpm_input34 (hdsp); + } +if (hdsp->io_type ==H9632 || hdsp->io_type ==H9652 ) + info.analog_extension_board = + (unsigned char )hdsp_toggle_setting (hdsp, + HDSP_AnalogExtensionBoard); } -if (hdsp->io_type ==H9632 || hdsp->io_type ==H9652 ) - info.analog_extension_board = - (unsigned char )hdsp_toggle_setting (hdsp, - HDSP_AnalogExtensionBoard); -spin_unlock_irqrestore (&hdsp->lock, flags);if (copy_to_user (argp, &info,sizeof (info)))return -EFAULT ;break ;
Signature · 1 line
2.50.1
PATCH 52/61 ALSA: hdspm: 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/pci/rme9652/hdspm.c | 303 ++++++++++++++++---------------------- 1 file changed, 128 insertions(+), 175 deletions(-)
sound/pci/rme9652/hdspm.c +128 -175
@@ -1204,16 +1204,11 @@ static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)/* check if same process is writing and reading */ static int snd_hdspm_use_is_exclusive (struct hdspm *hdspm) { -unsigned long flags; -int ret =1 ; - -spin_lock_irqsave (&hdspm->lock, flags); +guard (spinlock_irqsave)(&hdspm->lock);if ((hdspm->playback_pid != hdspm->capture_pid) && - (hdspm->playback_pid >=0 ) && (hdspm->capture_pid >=0 )) { - ret =0 ; - } -spin_unlock_irqrestore (&hdspm->lock, flags); -return ret; + (hdspm->playback_pid >=0 ) && (hdspm->capture_pid >=0 )) +return 0 ; +return 1 ; }/* round arbitrary sample rates to commonly known rates */
@@ -1527,7 +1522,7 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) {int n; -spin_lock_irq (&s->lock); +guard (spinlock_irq)(&s->lock);if (32 == frames) {/* Special case for new RME cards like RayDAT/AIO which
@@ -1557,8 +1552,6 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)hdspm_compute_period_size (s); -spin_unlock_irq (&s->lock); -return 0 ; }
@@ -1846,7 +1839,6 @@ static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) { -unsigned long flags;int n_pending;int to_write;int i;
@@ -1854,7 +1846,7 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)/* Output is not interrupt driven */ -spin_lock_irqsave (&hmidi->lock, flags); +guard (spinlock_irqsave)(&hmidi->lock);if (hmidi->output && !snd_rawmidi_transmit_empty (hmidi->output)) { n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
@@ -1873,7 +1865,6 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) } } } -spin_unlock_irqrestore (&hmidi->lock, flags);return 0 ; }
@@ -1882,37 +1873,36 @@ static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)unsigned char buf[128 ];/* this buffer is designed to match the MIDI * input FIFO size */ -unsigned long flags;int n_pending;int i; -spin_lock_irqsave (&hmidi->lock, flags); - n_pending =snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); -if (n_pending >0 ) { -if (hmidi->input) { -if (n_pending > (int )sizeof (buf)) - n_pending =sizeof (buf); -for (i =0 ; i < n_pending; ++i) - buf[i] =snd_hdspm_midi_read_byte (hmidi->hdspm, - hmidi->id); -if (n_pending) -snd_rawmidi_receive (hmidi->input, buf, - n_pending); - }else { -/* flush the MIDI input FIFO */ -while (n_pending--) -snd_hdspm_midi_read_byte (hmidi->hdspm, - hmidi->id); + scoped_guard(spinlock_irqsave, &hmidi->lock) { + n_pending =snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); +if (n_pending >0 ) { +if (hmidi->input) { +if (n_pending > (int )sizeof (buf)) + n_pending =sizeof (buf); +for (i =0 ; i < n_pending; ++i) + buf[i] =snd_hdspm_midi_read_byte (hmidi->hdspm, + hmidi->id); +if (n_pending) +snd_rawmidi_receive (hmidi->input, buf, + n_pending); + }else { +/* flush the MIDI input FIFO */ +while (n_pending--) +snd_hdspm_midi_read_byte (hmidi->hdspm, + hmidi->id); + } } + hmidi->pending =0 ; } - hmidi->pending =0 ; -spin_unlock_irqrestore (&hmidi->lock, flags); -spin_lock_irqsave (&hmidi->hdspm->lock, flags); - hmidi->hdspm->control_register |= hmidi->ie; -hdspm_write (hmidi->hdspm, HDSPM_controlRegister, - hmidi->hdspm->control_register); -spin_unlock_irqrestore (&hmidi->hdspm->lock, flags); + scoped_guard(spinlock_irqsave, &hmidi->hdspm->lock) { + hmidi->hdspm->control_register |= hmidi->ie; +hdspm_write (hmidi->hdspm, HDSPM_controlRegister, + hmidi->hdspm->control_register); + }return snd_hdspm_midi_output_write (hmidi); }
@@ -1922,12 +1912,11 @@ snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) {struct hdspm *hdspm;struct hdspm_midi *hmidi; -unsigned long flags; hmidi = substream->rmidi->private_data; hdspm = hmidi->hdspm; -spin_lock_irqsave (&hdspm->lock, flags); +guard (spinlock_irqsave)(&hdspm->lock);if (up) {if (!(hdspm->control_register & hmidi->ie)) {snd_hdspm_flush_midi_input (hdspm, hmidi->id);
@@ -1938,16 +1927,14 @@ snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) }hdspm_write (hdspm, HDSPM_controlRegister, hdspm->control_register); -spin_unlock_irqrestore (&hdspm->lock, flags); }static void snd_hdspm_midi_output_timer (struct timer_list *t) {struct hdspm_midi *hmidi =timer_container_of (hmidi, t, timer); -unsigned long flags;snd_hdspm_midi_output_write (hmidi); -spin_lock_irqsave (&hmidi->lock, flags); +guard (spinlock_irqsave)(&hmidi->lock);/* this does not bump hmidi->istimer, because the kernel automatically removed the timer when it
@@ -1957,30 +1944,27 @@ static void snd_hdspm_midi_output_timer(struct timer_list *t)if (hmidi->istimer)mod_timer (&hmidi->timer,1 + jiffies); - -spin_unlock_irqrestore (&hmidi->lock, flags); }static void snd_hdspm_midi_output_trigger (struct snd_rawmidi_substream *substream,int up) {struct hdspm_midi *hmidi; -unsigned long flags; hmidi = substream->rmidi->private_data; -spin_lock_irqsave (&hmidi->lock, flags); -if (up) { -if (!hmidi->istimer) { -timer_setup (&hmidi->timer, - snd_hdspm_midi_output_timer,0 ); -mod_timer (&hmidi->timer,1 + jiffies); - hmidi->istimer++; + scoped_guard(spinlock_irqsave, &hmidi->lock) { +if (up) { +if (!hmidi->istimer) { +timer_setup (&hmidi->timer, + snd_hdspm_midi_output_timer,0 ); +mod_timer (&hmidi->timer,1 + jiffies); + hmidi->istimer++; + } + }else { +if (hmidi->istimer && --hmidi->istimer <=0 ) +timer_delete (&hmidi->timer); } - }else { -if (hmidi->istimer && --hmidi->istimer <=0 ) -timer_delete (&hmidi->timer); } -spin_unlock_irqrestore (&hmidi->lock, flags);if (up)snd_hdspm_midi_output_write (hmidi); }
@@ -1990,10 +1974,9 @@ static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock);snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); hmidi->input = substream; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -2003,9 +1986,8 @@ static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->output = substream; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -2017,9 +1999,8 @@ static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)snd_hdspm_midi_input_trigger (substream,0 ); hmidi = substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->input =NULL ; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -2031,9 +2012,8 @@ static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)snd_hdspm_midi_output_trigger (substream,0 ); hmidi = substream->rmidi->private_data; -spin_lock_irq (&hmidi->lock); +guard (spinlock_irq)(&hmidi->lock); hmidi->output =NULL ; -spin_unlock_irq (&hmidi->lock);return 0 ; }
@@ -2671,12 +2651,11 @@ static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, val =0 ;if (val >9 ) val =9 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock);if (val !=hdspm_clock_source (hdspm)) change = (hdspm_set_clock_source (hdspm, val) ==0 ) ?1 :0 ;else change =0 ; -spin_unlock_irq (&hdspm->lock);return change; }
@@ -2999,11 +2978,10 @@ static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,else if (val >= hdspm->texts_autosync_items) val = hdspm->texts_autosync_items-1 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock);if (val !=hdspm_pref_sync_ref (hdspm)) change = (0 ==hdspm_set_pref_sync_ref (hdspm, val)) ?1 :0 ; -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3239,9 +3217,8 @@ static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol,struct hdspm *hdspm =snd_kcontrol_chip (kcontrol);u32 regmask = kcontrol->private_value; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.integer.value[0 ] =hdspm_toggle_setting (hdspm, regmask); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3256,10 +3233,9 @@ static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol,if (!snd_hdspm_use_is_exclusive (hdspm))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = (int ) val !=hdspm_toggle_setting (hdspm, regmask);hdspm_set_toggle_setting (hdspm, regmask, val); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3301,9 +3277,8 @@ static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, {struct hdspm *hdspm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0 ] =hdspm_input_select (hdspm); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3317,10 +3292,9 @@ static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,if (!snd_hdspm_use_is_exclusive (hdspm))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = (int ) val !=hdspm_input_select (hdspm);hdspm_set_input_select (hdspm, val); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3363,9 +3337,8 @@ static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, {struct hdspm *hdspm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0 ] =hdspm_ds_wire (hdspm); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3379,10 +3352,9 @@ static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,if (!snd_hdspm_use_is_exclusive (hdspm))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = (int ) val !=hdspm_ds_wire (hdspm);hdspm_set_ds_wire (hdspm, val); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3436,9 +3408,8 @@ static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, {struct hdspm *hdspm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0 ] =hdspm_qs_wire (hdspm); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3456,10 +3427,9 @@ static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, val =0 ;if (val >2 ) val =2 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = val !=hdspm_qs_wire (hdspm);hdspm_set_qs_wire (hdspm, val); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3512,9 +3482,8 @@ static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol,struct hdspm *hdspm =snd_kcontrol_chip (kcontrol);u32 regmask = kcontrol->private_value; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0 ] =hdspm_tristate (hdspm, regmask); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3534,10 +3503,9 @@ static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol,if (val >2 ) val =2 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = val !=hdspm_tristate (hdspm, regmask);hdspm_set_tristate (hdspm, val, regmask); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3590,9 +3558,8 @@ static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, {struct hdspm *hdspm =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0 ] =hdspm_madi_speedmode (hdspm); -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3610,10 +3577,9 @@ static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, val =0 ;if (val >2 ) val =2 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = val !=hdspm_madi_speedmode (hdspm);hdspm_set_madi_speedmode (hdspm, val); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3659,7 +3625,7 @@ static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,else if (destination >=HDSPM_MAX_CHANNELS ) destination =HDSPM_MAX_CHANNELS -1 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock);if (source >=HDSPM_MAX_CHANNELS ) ucontrol->value.integer.value[2 ] = hdspm_read_pb_gain(hdspm, destination,
@@ -3668,8 +3634,6 @@ static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[2 ] =hdspm_read_in_gain (hdspm, destination, source); -spin_unlock_irq (&hdspm->lock); -return 0 ; }
@@ -3695,7 +3659,7 @@ static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, gain = ucontrol->value.integer.value[2 ]; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock);if (source >=HDSPM_MAX_CHANNELS ) change = gain != hdspm_read_pb_gain(hdspm, destination,
@@ -3714,7 +3678,6 @@ static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,hdspm_write_in_gain (hdspm, destination, source, gain); } -spin_unlock_irq (&hdspm->lock);return change; }
@@ -3755,10 +3718,9 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,if (snd_BUG_ON (channel <0 || channel >=HDSPM_MAX_CHANNELS ))return -EINVAL ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); ucontrol->value.integer.value[0 ] = (hdspm_read_pb_gain (hdspm, channel, channel)*64 )/UNITY_GAIN ; -spin_unlock_irq (&hdspm->lock);return 0 ; }
@@ -3781,14 +3743,13 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, gain = ucontrol->value.integer.value[0 ]*UNITY_GAIN /64 ; -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock); change = gain !=hdspm_read_pb_gain (hdspm, channel, channel);if (change)hdspm_write_pb_gain (hdspm, channel, channel, gain); -spin_unlock_irq (&hdspm->lock);return change; }
@@ -5496,53 +5457,50 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,pid_t this_pid;pid_t other_pid; -spin_lock_irq (&hdspm->lock); + scoped_guard(spinlock_irq, &hdspm->lock) { -if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { - this_pid = hdspm->playback_pid; - other_pid = hdspm->capture_pid; - }else { - this_pid = hdspm->capture_pid; - other_pid = hdspm->playback_pid; - } - -if (other_pid >0 && this_pid != other_pid) { - -/* The other stream is open, and not by the same -task as this one. Make sure that the parameters -that matter are the same. -*/ - -if (params_rate (params) != hdspm->system_sample_rate) { -spin_unlock_irq (&hdspm->lock); -_snd_pcm_hw_param_setempty (params, -SNDRV_PCM_HW_PARAM_RATE ); -return -EBUSY ; +if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + this_pid = hdspm->playback_pid; + other_pid = hdspm->capture_pid; + }else { + this_pid = hdspm->capture_pid; + other_pid = hdspm->playback_pid; } -if (params_period_size (params) != hdspm->period_bytes /4 ) { -spin_unlock_irq (&hdspm->lock); -_snd_pcm_hw_param_setempty (params, -SNDRV_PCM_HW_PARAM_PERIOD_SIZE ); -return -EBUSY ; - } +if (other_pid >0 && this_pid != other_pid) { +/* The other stream is open, and not by the same +task as this one. Make sure that the parameters +that matter are the same. +*/ + +if (params_rate (params) != hdspm->system_sample_rate) { +_snd_pcm_hw_param_setempty (params, +SNDRV_PCM_HW_PARAM_RATE ); +return -EBUSY ; + } + +if (params_period_size (params) != hdspm->period_bytes /4 ) { +_snd_pcm_hw_param_setempty (params, +SNDRV_PCM_HW_PARAM_PERIOD_SIZE ); +return -EBUSY ; + } + + } }/* We're fine. */ -spin_unlock_irq (&hdspm->lock);/* how to make sure that the rate matches an externally-set one ? */ -spin_lock_irq (&hdspm->lock); - err =hdspm_set_rate (hdspm,params_rate (params),0 ); -if (err <0 ) { -dev_info (hdspm->card->dev,"err on hdspm_set_rate: %d\n" , err); -spin_unlock_irq (&hdspm->lock); -_snd_pcm_hw_param_setempty (params, -SNDRV_PCM_HW_PARAM_RATE ); -return err; + scoped_guard(spinlock_irq, &hdspm->lock) { + err =hdspm_set_rate (hdspm,params_rate (params),0 ); +if (err <0 ) { +dev_info (hdspm->card->dev,"err on hdspm_set_rate: %d\n" , err); +_snd_pcm_hw_param_setempty (params, +SNDRV_PCM_HW_PARAM_RATE ); +return err; + } } -spin_unlock_irq (&hdspm->lock); err =hdspm_set_interrupt_interval (hdspm,params_period_size (params));
@@ -5750,7 +5708,7 @@ static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)struct snd_pcm_substream *other;int running; -spin_lock (&hdspm->lock); +guard (spinlock)(&hdspm->lock); running = hdspm->running;switch (cmd) {case SNDRV_PCM_TRIGGER_START :
@@ -5761,7 +5719,6 @@ static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)break ;default :snd_BUG (); -spin_unlock (&hdspm->lock);return -EINVAL ; }if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK )
@@ -5802,7 +5759,6 @@ static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)else if (hdspm->running && !running)hdspm_stop_audio (hdspm); hdspm->running = running; -spin_unlock (&hdspm->lock);return 0 ; }
@@ -6035,27 +5991,26 @@ static int snd_hdspm_open(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;bool playback = (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ); -spin_lock_irq (&hdspm->lock); -snd_pcm_set_sync (substream); - runtime->hw = (playback) ? snd_hdspm_playback_subinfo : - snd_hdspm_capture_subinfo; + scoped_guard(spinlock_irq, &hdspm->lock) { +snd_pcm_set_sync (substream); + runtime->hw = (playback) ? snd_hdspm_playback_subinfo : + snd_hdspm_capture_subinfo; -if (playback) { -if (!hdspm->capture_substream) -hdspm_stop_audio (hdspm); +if (playback) { +if (!hdspm->capture_substream) +hdspm_stop_audio (hdspm); - hdspm->playback_pid = current->pid; - hdspm->playback_substream = substream; - }else { -if (!hdspm->playback_substream) -hdspm_stop_audio (hdspm); + hdspm->playback_pid = current->pid; + hdspm->playback_substream = substream; + }else { +if (!hdspm->playback_substream) +hdspm_stop_audio (hdspm); - hdspm->capture_pid = current->pid; - hdspm->capture_substream = substream; + hdspm->capture_pid = current->pid; + hdspm->capture_substream = substream; + } } -spin_unlock_irq (&hdspm->lock); -snd_pcm_hw_constraint_msbits (runtime,0 ,32 ,24 );snd_pcm_hw_constraint_pow2 (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE );
@@ -6108,7 +6063,7 @@ static int snd_hdspm_release(struct snd_pcm_substream *substream)struct hdspm *hdspm =snd_pcm_substream_chip (substream);bool playback = (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ); -spin_lock_irq (&hdspm->lock); +guard (spinlock_irq)(&hdspm->lock);if (playback) { hdspm->playback_pid =-1 ;
@@ -6118,8 +6073,6 @@ static int snd_hdspm_release(struct snd_pcm_substream *substream) hdspm->capture_substream =NULL ; } -spin_unlock_irq (&hdspm->lock); -return 0 ; }
@@ -6242,19 +6195,19 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,case SNDRV_HDSPM_IOCTL_GET_CONFIG :memset (&info,0 ,sizeof (info)); -spin_lock_irq (&hdspm->lock); - info.pref_sync_ref =hdspm_pref_sync_ref (hdspm); - info.wordclock_sync_check =hdspm_wc_sync_check (hdspm); + scoped_guard(spinlock_irq, &hdspm->lock) { + info.pref_sync_ref =hdspm_pref_sync_ref (hdspm); + info.wordclock_sync_check =hdspm_wc_sync_check (hdspm); - info.system_sample_rate = hdspm->system_sample_rate; - info.autosync_sample_rate = -hdspm_external_sample_rate (hdspm); - info.system_clock_mode =hdspm_system_clock_mode (hdspm); - info.clock_source =hdspm_clock_source (hdspm); - info.autosync_ref =hdspm_autosync_ref (hdspm); - info.line_out =hdspm_toggle_setting (hdspm, HDSPM_LineOut); - info.passthru =0 ; -spin_unlock_irq (&hdspm->lock); + info.system_sample_rate = hdspm->system_sample_rate; + info.autosync_sample_rate = +hdspm_external_sample_rate (hdspm); + info.system_clock_mode =hdspm_system_clock_mode (hdspm); + info.clock_source =hdspm_clock_source (hdspm); + info.autosync_ref =hdspm_autosync_ref (hdspm); + info.line_out =hdspm_toggle_setting (hdspm, HDSPM_LineOut); + info.passthru =0 ; + }if (copy_to_user (argp, &info,sizeof (info)))return -EFAULT ;break ;
Signature · 1 line
2.50.1
PATCH 53/61 ALSA: rme9652: 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/pci/rme9652/rme9652.c | 203 ++++++++++++++---------------------- 1 file changed, 80 insertions(+), 123 deletions(-)
sound/pci/rme9652/rme9652.c +80 -123
@@ -308,16 +308,11 @@ static inline unsigned int rme9652_read(struct snd_rme9652 *rme9652, int reg)static inline int snd_rme9652_use_is_exclusive (struct snd_rme9652 *rme9652) { -unsigned long flags; -int ret =1 ; - -spin_lock_irqsave (&rme9652->lock, flags); +guard (spinlock_irqsave)(&rme9652->lock);if ((rme9652->playback_pid != rme9652->capture_pid) && - (rme9652->playback_pid >=0 ) && (rme9652->capture_pid >=0 )) { - ret =0 ; - } -spin_unlock_irqrestore (&rme9652->lock, flags); -return ret; + (rme9652->playback_pid >=0 ) && (rme9652->capture_pid >=0 )) +return 0 ; +return 1 ; }static inline int rme9652_adat_sample_rate (struct snd_rme9652 *rme9652)
@@ -428,7 +423,7 @@ static int rme9652_set_interrupt_interval(struct snd_rme9652 *s,int restart =0 ;int n; -spin_lock_irq (&s->lock); +guard (spinlock_irq)(&s->lock); restart = s->running;if (restart)
@@ -451,8 +446,6 @@ static int rme9652_set_interrupt_interval(struct snd_rme9652 *s,if (restart)rme9652_start (s); -spin_unlock_irq (&s->lock); -return 0 ; }
@@ -477,7 +470,7 @@ static int rme9652_set_rate(struct snd_rme9652 *rme9652, int rate)is to flag rate changes in the read/write routines. */ -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); xrate =rme9652_adat_sample_rate (rme9652);switch (rate) {
@@ -506,14 +499,11 @@ static int rme9652_set_rate(struct snd_rme9652 *rme9652, int rate) rate =RME9652_DS | RME9652_freq;break ;default : -spin_unlock_irq (&rme9652->lock);return -EINVAL ; } -if (reject_if_open && (rme9652->capture_pid >=0 || rme9652->playback_pid >=0 )) { -spin_unlock_irq (&rme9652->lock); +if (reject_if_open && (rme9652->capture_pid >=0 || rme9652->playback_pid >=0 ))return -EBUSY ; - } restart = rme9652->running;if (restart)
@@ -539,7 +529,6 @@ static int rme9652_set_rate(struct snd_rme9652 *rme9652, int rate) } } -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -798,10 +787,9 @@ static int snd_rme9652_control_spdif_put(struct snd_kcontrol *kcontrol, struct su32 val; val =snd_rme9652_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = val != rme9652->creg_spdif; rme9652->creg_spdif = val; -spin_unlock_irq (&rme9652->lock);return change; }
@@ -827,12 +815,11 @@ static int snd_rme9652_control_spdif_stream_put(struct snd_kcontrol *kcontrol, su32 val; val =snd_rme9652_convert_from_aes (&ucontrol->value.iec958); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = val != rme9652->creg_spdif_stream; rme9652->creg_spdif_stream = val; rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby |RME9652_EMP );rme9652_write (rme9652, RME9652_control_register, rme9652->control_register |= val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -897,9 +884,8 @@ static int snd_rme9652_get_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ct {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.enumerated.item[0 ] =rme9652_adat1_in (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -912,11 +898,10 @@ static int snd_rme9652_put_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctif (!snd_rme9652_use_is_exclusive (rme9652))return -EBUSY ; val = ucontrol->value.enumerated.item[0 ] %2 ; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = val !=rme9652_adat1_in (rme9652);if (change)rme9652_set_adat1_input (rme9652, val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -961,9 +946,8 @@ static int snd_rme9652_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ct {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.enumerated.item[0 ] =rme9652_spdif_in (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -976,11 +960,10 @@ static int snd_rme9652_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctif (!snd_rme9652_use_is_exclusive (rme9652))return -EBUSY ; val = ucontrol->value.enumerated.item[0 ] %3 ; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = val !=rme9652_spdif_in (rme9652);if (change)rme9652_set_spdif_input (rme9652, val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -1022,9 +1005,8 @@ static int snd_rme9652_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_c {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.integer.value[0 ] =rme9652_spdif_out (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -1037,10 +1019,9 @@ static int snd_rme9652_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_cif (!snd_rme9652_use_is_exclusive (rme9652))return -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = (int )val !=rme9652_spdif_out (rme9652);rme9652_set_spdif_output (rme9652, val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -1104,9 +1085,8 @@ static int snd_rme9652_get_sync_mode(struct snd_kcontrol *kcontrol, struct snd_c {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.enumerated.item[0 ] =rme9652_sync_mode (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -1117,10 +1097,9 @@ static int snd_rme9652_put_sync_mode(struct snd_kcontrol *kcontrol, struct snd_cunsigned int val; val = ucontrol->value.enumerated.item[0 ] %3 ; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = (int )val !=rme9652_sync_mode (rme9652);rme9652_set_sync_mode (rme9652, val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -1193,9 +1172,8 @@ static int snd_rme9652_get_sync_pref(struct snd_kcontrol *kcontrol, struct snd_c {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.enumerated.item[0 ] =rme9652_sync_pref (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -1209,10 +1187,9 @@ static int snd_rme9652_put_sync_pref(struct snd_kcontrol *kcontrol, struct snd_creturn -EBUSY ; max = rme9652->ss_channels ==RME9652_NCHANNELS ?4 :3 ; val = ucontrol->value.enumerated.item[0 ] % max; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = (int )val !=rme9652_sync_pref (rme9652);rme9652_set_sync_pref (rme9652, val); -spin_unlock_irq (&rme9652->lock);return change; }
@@ -1253,7 +1230,7 @@ static int snd_rme9652_put_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_el thru_bits |=1 << chn; } -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = thru_bits ^ rme9652->thru_bits;if (change) {for (chn =0 ; chn < rme9652->ss_channels; ++chn) {
@@ -1262,7 +1239,6 @@ static int snd_rme9652_put_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elrme9652_set_thru (rme9652,chn,thru_bits&(1 <<chn)); } } -spin_unlock_irq (&rme9652->lock);return !!change; }
@@ -1278,9 +1254,8 @@ static int snd_rme9652_get_passthru(struct snd_kcontrol *kcontrol, struct snd_ct {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.integer.value[0 ] = rme9652->passthru; -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -1295,11 +1270,10 @@ static int snd_rme9652_put_passthru(struct snd_kcontrol *kcontrol, struct snd_ctreturn -EBUSY ; val = ucontrol->value.integer.value[0 ] &1 ; -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); change = (ucontrol->value.integer.value[0 ] != rme9652->passthru);if (change) err =rme9652_set_passthru (rme9652, val); -spin_unlock_irq (&rme9652->lock);return err ? err : change; }
@@ -1324,9 +1298,8 @@ static int snd_rme9652_get_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_ {struct snd_rme9652 *rme9652 =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); ucontrol->value.integer.value[0 ] =rme9652_spdif_sample_rate (rme9652); -spin_unlock_irq (&rme9652->lock);return 0 ; }
@@ -1931,45 +1904,39 @@ static int snd_rme9652_hw_params(struct snd_pcm_substream *substream,pid_t this_pid;pid_t other_pid; -spin_lock_irq (&rme9652->lock); + scoped_guard(spinlock_irq, &rme9652->lock) { -if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { - rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby |RME9652_EMP ); -rme9652_write (rme9652, RME9652_control_register, rme9652->control_register |= rme9652->creg_spdif_stream); - this_pid = rme9652->playback_pid; - other_pid = rme9652->capture_pid; - }else { - this_pid = rme9652->capture_pid; - other_pid = rme9652->playback_pid; - } - -if ((other_pid >0 ) && (this_pid != other_pid)) { - -/* The other stream is open, and not by the same -task as this one. Make sure that the parameters -that matter are the same. -*/ - -if ((int )params_rate (params) != -rme9652_adat_sample_rate (rme9652)) { -spin_unlock_irq (&rme9652->lock); -_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_RATE ); -return -EBUSY ; +if (substream->pstr->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby |RME9652_EMP ); +rme9652_write (rme9652, RME9652_control_register, rme9652->control_register |= rme9652->creg_spdif_stream); + this_pid = rme9652->playback_pid; + other_pid = rme9652->capture_pid; + }else { + this_pid = rme9652->capture_pid; + other_pid = rme9652->playback_pid; } -if (params_period_size (params) != rme9652->period_bytes /4 ) { -spin_unlock_irq (&rme9652->lock); -_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_PERIOD_SIZE ); -return -EBUSY ; +if ((other_pid >0 ) && (this_pid != other_pid)) { + +/* The other stream is open, and not by the same +task as this one. Make sure that the parameters +that matter are the same. +*/ + +if ((int )params_rate (params) != +rme9652_adat_sample_rate (rme9652)) { +_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_RATE ); +return -EBUSY ; + } + +if (params_period_size (params) != rme9652->period_bytes /4 ) { +_snd_pcm_hw_param_setempty (params,SNDRV_PCM_HW_PARAM_PERIOD_SIZE ); +return -EBUSY ; + } + +/* We're fine. */ +return 0 ; } - -/* We're fine. */ - -spin_unlock_irq (&rme9652->lock); -return 0 ; - - }else { -spin_unlock_irq (&rme9652->lock); }/* how to make sure that the rate matches an externally-set one ?
@@ -2041,7 +2008,8 @@ static int snd_rme9652_trigger(struct snd_pcm_substream *substream,struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream);struct snd_pcm_substream *other;int running; -spin_lock (&rme9652->lock); + +guard (spinlock)(&rme9652->lock); running = rme9652->running;switch (cmd) {case SNDRV_PCM_TRIGGER_START :
@@ -2052,7 +2020,6 @@ static int snd_rme9652_trigger(struct snd_pcm_substream *substream,break ;default :snd_BUG (); -spin_unlock (&rme9652->lock);return -EINVAL ; }if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK )
@@ -2092,7 +2059,6 @@ static int snd_rme9652_trigger(struct snd_pcm_substream *substream,else if (rme9652->running && !running)rme9652_stop (rme9652); rme9652->running = running; -spin_unlock (&rme9652->lock);return 0 ; }
@@ -2100,12 +2066,10 @@ static int snd_rme9652_trigger(struct snd_pcm_substream *substream,static int snd_rme9652_prepare (struct snd_pcm_substream *substream) {struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream); -unsigned long flags; -spin_lock_irqsave (&rme9652->lock, flags); +guard (spinlock_irqsave)(&rme9652->lock);if (!rme9652->running)rme9652_reset_hw_pointer (rme9652); -spin_unlock_irqrestore (&rme9652->lock, flags);return 0 ; }
@@ -2226,23 +2190,21 @@ static int snd_rme9652_playback_open(struct snd_pcm_substream *substream)struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime; -spin_lock_irq (&rme9652->lock); + scoped_guard(spinlock_irq, &rme9652->lock) { +snd_pcm_set_sync (substream); -snd_pcm_set_sync (substream); + runtime->hw = snd_rme9652_playback_subinfo; +snd_pcm_set_runtime_buffer (substream, &rme9652->playback_dma_buf); - runtime->hw = snd_rme9652_playback_subinfo; -snd_pcm_set_runtime_buffer (substream, &rme9652->playback_dma_buf); +if (rme9652->capture_substream ==NULL ) { +rme9652_stop (rme9652); +rme9652_set_thru (rme9652,-1 ,0 ); + } -if (rme9652->capture_substream ==NULL ) { -rme9652_stop (rme9652); -rme9652_set_thru (rme9652,-1 ,0 ); + rme9652->playback_pid = current->pid; + rme9652->playback_substream = substream; } - rme9652->playback_pid = current->pid; - rme9652->playback_substream = substream; - -spin_unlock_irq (&rme9652->lock); -snd_pcm_hw_constraint_msbits (runtime,0 ,32 ,24 );snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , &hw_constraints_period_sizes); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
@@ -2266,12 +2228,10 @@ static int snd_rme9652_playback_release(struct snd_pcm_substream *substream) {struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme9652->lock); - - rme9652->playback_pid =-1 ; - rme9652->playback_substream =NULL ; - -spin_unlock_irq (&rme9652->lock); + scoped_guard(spinlock_irq, &rme9652->lock) { + rme9652->playback_pid =-1 ; + rme9652->playback_substream =NULL ; + } rme9652->spdif_ctl->vd[0 ].access |=SNDRV_CTL_ELEM_ACCESS_INACTIVE ; snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
@@ -2285,23 +2245,21 @@ static int snd_rme9652_capture_open(struct snd_pcm_substream *substream)struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime; -spin_lock_irq (&rme9652->lock); + scoped_guard(spinlock_irq, &rme9652->lock) { +snd_pcm_set_sync (substream); -snd_pcm_set_sync (substream); + runtime->hw = snd_rme9652_capture_subinfo; +snd_pcm_set_runtime_buffer (substream, &rme9652->capture_dma_buf); - runtime->hw = snd_rme9652_capture_subinfo; -snd_pcm_set_runtime_buffer (substream, &rme9652->capture_dma_buf); +if (rme9652->playback_substream ==NULL ) { +rme9652_stop (rme9652); +rme9652_set_thru (rme9652,-1 ,0 ); + } -if (rme9652->playback_substream ==NULL ) { -rme9652_stop (rme9652); -rme9652_set_thru (rme9652,-1 ,0 ); + rme9652->capture_pid = current->pid; + rme9652->capture_substream = substream; } - rme9652->capture_pid = current->pid; - rme9652->capture_substream = substream; - -spin_unlock_irq (&rme9652->lock); -snd_pcm_hw_constraint_msbits (runtime,0 ,32 ,24 );snd_pcm_hw_constraint_list (runtime,0 ,SNDRV_PCM_HW_PARAM_PERIOD_SIZE , &hw_constraints_period_sizes); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
@@ -2320,12 +2278,11 @@ static int snd_rme9652_capture_release(struct snd_pcm_substream *substream) {struct snd_rme9652 *rme9652 =snd_pcm_substream_chip (substream); -spin_lock_irq (&rme9652->lock); +guard (spinlock_irq)(&rme9652->lock); rme9652->capture_pid =-1 ; rme9652->capture_substream =NULL ; -spin_unlock_irq (&rme9652->lock);return 0 ; }
Signature · 1 line
2.50.1
PATCH 54/61 ALSA: sis7019: 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/pci/sis7019.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/pci/sis7019.c +1 -3
@@ -902,7 +902,7 @@ static unsigned short sis_ac97_rw(struct sis7019 *sis, int codec, u32 cmd)/* Get the AC97 semaphore -- software first, so we don't spin * pounding out IO reads on the hardware semaphore... */ -mutex_lock (&sis->ac97_mutex); +guard (mutex)(&sis->ac97_mutex); count =0xffff ;while ((inw (io +SIS_AC97_SEMA ) &SIS_AC97_SEMA_BUSY ) && --count)
@@ -941,8 +941,6 @@ static unsigned short sis_ac97_rw(struct sis7019 *sis, int codec, u32 cmd) timeout_sema:outl (SIS_AC97_SEMA_RELEASE , io +SIS_AC97_SEMA ); timeout: -mutex_unlock (&sis->ac97_mutex); -if (!count) {dev_err (&sis->pci->dev,"ac97 codec %d timeout cmd 0x%08x\n" , codec, cmd);
Signature · 1 line
2.50.1
PATCH 55/61 ALSA: sis7019: 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/pci/sis7019.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-)
sound/pci/sis7019.c +14 -25
@@ -383,9 +383,7 @@ static void __sis_unmap_silence(struct sis7019 *sis)static void sis_free_voice (struct sis7019 *sis,struct voice *voice) { -unsigned long flags; - -spin_lock_irqsave (&sis->voice_lock, flags); +guard (spinlock_irqsave)(&sis->voice_lock);if (voice->timing) {__sis_unmap_silence (sis); voice->timing->flags &= ~(VOICE_IN_USE | VOICE_SSO_TIMING |
@@ -393,7 +391,6 @@ static void sis_free_voice(struct sis7019 *sis, struct voice *voice) voice->timing =NULL ; } voice->flags &= ~(VOICE_IN_USE |VOICE_SSO_TIMING |VOICE_SYNC_TIMING ); -spin_unlock_irqrestore (&sis->voice_lock, flags); }static struct voice *__sis_alloc_playback_voice (struct sis7019 *sis)
@@ -417,14 +414,8 @@ static struct voice *__sis_alloc_playback_voice(struct sis7019 *sis)static struct voice *sis_alloc_playback_voice (struct sis7019 *sis) { -struct voice *voice; -unsigned long flags; - -spin_lock_irqsave (&sis->voice_lock, flags); - voice =__sis_alloc_playback_voice (sis); -spin_unlock_irqrestore (&sis->voice_lock, flags); - -return voice; +guard (spinlock_irqsave)(&sis->voice_lock); +return __sis_alloc_playback_voice (sis); } static int sis_alloc_timing_voice(struct snd_pcm_substream *substream,
@@ -434,7 +425,6 @@ static int sis_alloc_timing_voice(struct snd_pcm_substream *substream,struct snd_pcm_runtime *runtime = substream->runtime;struct voice *voice = runtime->private_data;unsigned int period_size, buffer_size; -unsigned long flags;int needed;/* If there are one or two periods per buffer, we don't need a
@@ -447,11 +437,11 @@ static int sis_alloc_timing_voice(struct snd_pcm_substream *substream, period_size != (buffer_size / 2));if (needed && !voice->timing) { -spin_lock_irqsave (&sis->voice_lock, flags); - voice->timing =__sis_alloc_playback_voice (sis); -if (voice->timing) -__sis_map_silence (sis); -spin_unlock_irqrestore (&sis->voice_lock, flags); + scoped_guard(spinlock_irqsave, &sis->voice_lock) { + voice->timing =__sis_alloc_playback_voice (sis); +if (voice->timing) +__sis_map_silence (sis); + }if (!voice->timing)return -ENOMEM ; voice->timing->substream = substream;
@@ -645,17 +635,16 @@ static int sis_capture_open(struct snd_pcm_substream *substream)struct sis7019 *sis =snd_pcm_substream_chip (substream);struct snd_pcm_runtime *runtime = substream->runtime;struct voice *voice = &sis->capture_voice; -unsigned long flags;/* FIXME: The driver only supports recording from one channel * at the moment, but it could support more. */ -spin_lock_irqsave (&sis->voice_lock, flags); -if (voice->flags &VOICE_IN_USE ) - voice =NULL ; -else - voice->flags |=VOICE_IN_USE ; -spin_unlock_irqrestore (&sis->voice_lock, flags); + scoped_guard(spinlock_irqsave, &sis->voice_lock) { +if (voice->flags &VOICE_IN_USE ) + voice =NULL ; +else + voice->flags |=VOICE_IN_USE ; + }if (!voice)return -EAGAIN ;
Signature · 1 line
2.50.1
PATCH 56/61 ALSA: sonicvibes: 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/pci/sonicvibes.c | 113 ++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 69 deletions(-)
sound/pci/sonicvibes.c +44 -69
@@ -303,14 +303,11 @@ static void snd_sonicvibes_out(struct sonicvibes * sonic,unsigned char reg, unsigned char value) { -unsigned long flags; - -spin_lock_irqsave (&sonic->reg_lock, flags); + guard(spinlock_irqsave)(&sonic->reg_lock);outb (reg,SV_REG (sonic,INDEX ));udelay (10 );outb (value,SV_REG (sonic,DATA ));udelay (10 ); -spin_unlock_irqrestore (&sonic->reg_lock, flags); }static unsigned char snd_sonicvibes_in1 (struct sonicvibes * sonic,unsigned char reg)
@@ -326,15 +323,13 @@ static unsigned char snd_sonicvibes_in1(struct sonicvibes * sonic, unsigned charstatic unsigned char snd_sonicvibes_in (struct sonicvibes * sonic,unsigned char reg) { -unsigned long flags;unsigned char value; -spin_lock_irqsave (&sonic->reg_lock, flags); +guard (spinlock_irqsave)(&sonic->reg_lock);outb (reg,SV_REG (sonic,INDEX ));udelay (10 ); value =inb (SV_REG (sonic,DATA ));udelay (10 ); -spin_unlock_irqrestore (&sonic->reg_lock, flags);return value; }
@@ -448,9 +443,7 @@ static void snd_sonicvibes_setfmt(struct sonicvibes * sonic,unsigned char mask, unsigned char value) { -unsigned long flags; - -spin_lock_irqsave (&sonic->reg_lock, flags); + guard(spinlock_irqsave)(&sonic->reg_lock);outb (SV_MCE |SV_IREG_DMA_DATA_FMT ,SV_REG (sonic,INDEX ));if (mask) { sonic->format =inb (SV_REG (sonic,DATA ));
@@ -461,7 +454,6 @@ static void snd_sonicvibes_setfmt(struct sonicvibes * sonic,udelay (10 );outb (0 ,SV_REG (sonic,INDEX ));udelay (10 ); -spin_unlock_irqrestore (&sonic->reg_lock, flags); } static void snd_sonicvibes_pll(unsigned int rate,
@@ -506,21 +498,18 @@ static void snd_sonicvibes_setpll(struct sonicvibes * sonic, unsigned char reg, unsigned int rate) { -unsigned long flags;unsigned int r, m, n;snd_sonicvibes_pll (rate, &r, &m, &n);if (sonic !=NULL ) { -spin_lock_irqsave (&sonic->reg_lock, flags); +guard (spinlock_irqsave)(&sonic->reg_lock);snd_sonicvibes_out1 (sonic, reg, m);snd_sonicvibes_out1 (sonic, reg +1 , r | n); -spin_unlock_irqrestore (&sonic->reg_lock, flags); } }static void snd_sonicvibes_set_adc_rate (struct sonicvibes * sonic,unsigned int rate) { -unsigned long flags;unsigned int div;unsigned char clock;
@@ -533,10 +522,9 @@ static void snd_sonicvibes_set_adc_rate(struct sonicvibes * sonic, unsigned int clock =0x00 ;snd_sonicvibes_setpll (sonic,SV_IREG_ADC_PLL , rate); } -spin_lock_irqsave (&sonic->reg_lock, flags); +guard (spinlock_irqsave)(&sonic->reg_lock);snd_sonicvibes_out1 (sonic,SV_IREG_ADC_ALT_RATE , (div -1 ) <<4 );snd_sonicvibes_out1 (sonic,SV_IREG_ADC_CLOCK , clock); -spin_unlock_irqrestore (&sonic->reg_lock, flags); } static int snd_sonicvibes_hw_constraint_dac_rate(struct snd_pcm_hw_params *params,
@@ -567,22 +555,18 @@ static int snd_sonicvibes_hw_constraint_dac_rate(struct snd_pcm_hw_params *paramstatic void snd_sonicvibes_set_dac_rate (struct sonicvibes * sonic,unsigned int rate) {unsigned int div; -unsigned long flags; div =DIV_ROUND_CLOSEST (rate *65536 ,SV_FULLRATE );if (div >65535 ) div =65535 ; -spin_lock_irqsave (&sonic->reg_lock, flags); +guard (spinlock_irqsave)(&sonic->reg_lock);snd_sonicvibes_out1 (sonic,SV_IREG_PCM_RATE_HIGH , div >>8 );snd_sonicvibes_out1 (sonic,SV_IREG_PCM_RATE_LOW , div); -spin_unlock_irqrestore (&sonic->reg_lock, flags); }static int snd_sonicvibes_trigger (struct sonicvibes * sonic,int what,int cmd) { -int result =0 ; - -spin_lock (&sonic->reg_lock); +guard (spinlock)(&sonic->reg_lock);if (cmd ==SNDRV_PCM_TRIGGER_START ) {if (!(sonic->enable & what)) { sonic->enable |= what;
@@ -594,10 +578,9 @@ static int snd_sonicvibes_trigger(struct sonicvibes * sonic, int what, int cmd)snd_sonicvibes_out1 (sonic,SV_IREG_PC_ENABLE , sonic->enable); } }else { - result = -EINVAL ; +return -EINVAL ; } -spin_unlock (&sonic->reg_lock); -return result; +return 0 ; }static irqreturn_t snd_sonicvibes_interrupt (int irq,void *dev_id)
@@ -628,34 +611,34 @@ static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id)unsigned char udreg;int vol, oleft, oright, mleft, mright; -spin_lock (&sonic->reg_lock); - udreg =snd_sonicvibes_in1 (sonic,SV_IREG_UD_BUTTON ); - vol = udreg &0x3f ; -if (!(udreg &0x40 )) - vol = -vol; - oleft = mleft =snd_sonicvibes_in1 (sonic,SV_IREG_LEFT_ANALOG ); - oright = mright =snd_sonicvibes_in1 (sonic,SV_IREG_RIGHT_ANALOG ); - oleft &=0x1f ; - oright &=0x1f ; - oleft += vol; -if (oleft <0 ) - oleft =0 ; -if (oleft >0x1f ) - oleft =0x1f ; - oright += vol; -if (oright <0 ) - oright =0 ; -if (oright >0x1f ) - oright =0x1f ; -if (udreg &0x80 ) { - mleft ^=0x80 ; - mright ^=0x80 ; + scoped_guard(spinlock, &sonic->reg_lock) { + udreg =snd_sonicvibes_in1 (sonic,SV_IREG_UD_BUTTON ); + vol = udreg &0x3f ; +if (!(udreg &0x40 )) + vol = -vol; + oleft = mleft =snd_sonicvibes_in1 (sonic,SV_IREG_LEFT_ANALOG ); + oright = mright =snd_sonicvibes_in1 (sonic,SV_IREG_RIGHT_ANALOG ); + oleft &=0x1f ; + oright &=0x1f ; + oleft += vol; +if (oleft <0 ) + oleft =0 ; +if (oleft >0x1f ) + oleft =0x1f ; + oright += vol; +if (oright <0 ) + oright =0 ; +if (oright >0x1f ) + oright =0x1f ; +if (udreg &0x80 ) { + mleft ^=0x80 ; + mright ^=0x80 ; + } + oleft |= mleft &0x80 ; + oright |= mright &0x80 ; +snd_sonicvibes_out1 (sonic,SV_IREG_LEFT_ANALOG , oleft); +snd_sonicvibes_out1 (sonic,SV_IREG_RIGHT_ANALOG , oright); } - oleft |= mleft &0x80 ; - oright |= mright &0x80 ; -snd_sonicvibes_out1 (sonic,SV_IREG_LEFT_ANALOG , oleft); -snd_sonicvibes_out1 (sonic,SV_IREG_RIGHT_ANALOG , oright); -spin_unlock (&sonic->reg_lock);snd_ctl_notify (sonic->card,SNDRV_CTL_EVENT_MASK_VALUE , &sonic->master_mute->id);snd_ctl_notify (sonic->card,SNDRV_CTL_EVENT_MASK_VALUE , &sonic->master_volume->id); }
@@ -696,11 +679,10 @@ static int snd_sonicvibes_playback_prepare(struct snd_pcm_substream *substream) fmt |=2 ;snd_sonicvibes_setfmt (sonic, ~3 , fmt);snd_sonicvibes_set_dac_rate (sonic, runtime->rate); -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock);snd_sonicvibes_setdmaa (sonic, runtime->dma_addr, size);snd_sonicvibes_out1 (sonic,SV_IREG_DMA_A_UPPER , count >>8 );snd_sonicvibes_out1 (sonic,SV_IREG_DMA_A_LOWER , count); -spin_unlock_irq (&sonic->reg_lock);return 0 ; }
@@ -721,11 +703,10 @@ static int snd_sonicvibes_capture_prepare(struct snd_pcm_substream *substream) fmt |=0x20 ;snd_sonicvibes_setfmt (sonic, ~0x30 , fmt);snd_sonicvibes_set_adc_rate (sonic, runtime->rate); -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock);snd_sonicvibes_setdmac (sonic, runtime->dma_addr, size);snd_sonicvibes_out1 (sonic,SV_IREG_DMA_C_UPPER , count >>8 );snd_sonicvibes_out1 (sonic,SV_IREG_DMA_C_LOWER , count); -spin_unlock_irq (&sonic->reg_lock);return 0 ; }
@@ -894,10 +875,9 @@ static int snd_sonicvibes_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_ {struct sonicvibes *sonic =snd_kcontrol_chip (kcontrol); -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); ucontrol->value.enumerated.item[0 ] = ((snd_sonicvibes_in1 (sonic,SV_IREG_LEFT_ADC ) &SV_RECSRC_OUT ) >>5 ) -1 ; ucontrol->value.enumerated.item[1 ] = ((snd_sonicvibes_in1 (sonic,SV_IREG_RIGHT_ADC ) &SV_RECSRC_OUT ) >>5 ) -1 ; -spin_unlock_irq (&sonic->reg_lock);return 0 ; }
@@ -912,7 +892,7 @@ static int snd_sonicvibes_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_return -EINVAL ; left = (ucontrol->value.enumerated.item[0 ] +1 ) <<5 ; right = (ucontrol->value.enumerated.item[1 ] +1 ) <<5 ; -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); oval1 =snd_sonicvibes_in1 (sonic,SV_IREG_LEFT_ADC ); oval2 =snd_sonicvibes_in1 (sonic,SV_IREG_RIGHT_ADC ); left = (oval1 & ~SV_RECSRC_OUT ) | left;
@@ -920,7 +900,6 @@ static int snd_sonicvibes_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_ change = left != oval1 || right != oval2;snd_sonicvibes_out1 (sonic,SV_IREG_LEFT_ADC , left);snd_sonicvibes_out1 (sonic,SV_IREG_RIGHT_ADC , right); -spin_unlock_irq (&sonic->reg_lock);return change; }
@@ -949,9 +928,8 @@ static int snd_sonicvibes_get_single(struct snd_kcontrol *kcontrol, struct snd_cint mask = (kcontrol->private_value >>16 ) &0xff ;int invert = (kcontrol->private_value >>24 ) &0xff ; -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); ucontrol->value.integer.value[0 ] = (snd_sonicvibes_in1 (sonic, reg)>> shift) & mask; -spin_unlock_irq (&sonic->reg_lock);if (invert) ucontrol->value.integer.value[0 ] = mask - ucontrol->value.integer.value[0 ];return 0 ;
@@ -971,12 +949,11 @@ static int snd_sonicvibes_put_single(struct snd_kcontrol *kcontrol, struct snd_cif (invert) val = mask - val; val <<= shift; -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); oval =snd_sonicvibes_in1 (sonic, reg); val = (oval & ~(mask << shift)) | val; change = val != oval;snd_sonicvibes_out1 (sonic, reg, val); -spin_unlock_irq (&sonic->reg_lock);return change; }
@@ -1007,10 +984,9 @@ static int snd_sonicvibes_get_double(struct snd_kcontrol *kcontrol, struct snd_cint mask = (kcontrol->private_value >>24 ) &0xff ;int invert = (kcontrol->private_value >>22 ) &1 ; -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); ucontrol->value.integer.value[0 ] = (snd_sonicvibes_in1 (sonic, left_reg) >> shift_left) & mask; ucontrol->value.integer.value[1 ] = (snd_sonicvibes_in1 (sonic, right_reg) >> shift_right) & mask; -spin_unlock_irq (&sonic->reg_lock);if (invert) { ucontrol->value.integer.value[0 ] = mask - ucontrol->value.integer.value[0 ]; ucontrol->value.integer.value[1 ] = mask - ucontrol->value.integer.value[1 ];
@@ -1038,7 +1014,7 @@ static int snd_sonicvibes_put_double(struct snd_kcontrol *kcontrol, struct snd_c } val1 <<= shift_left; val2 <<= shift_right; -spin_lock_irq (&sonic->reg_lock); +guard (spinlock_irq)(&sonic->reg_lock); oval1 =snd_sonicvibes_in1 (sonic, left_reg); oval2 =snd_sonicvibes_in1 (sonic, right_reg); val1 = (oval1 & ~(mask << shift_left)) | val1;
@@ -1046,7 +1022,6 @@ static int snd_sonicvibes_put_double(struct snd_kcontrol *kcontrol, struct snd_c change = val1 != oval1 || val2 != oval2;snd_sonicvibes_out1 (sonic, left_reg, val1);snd_sonicvibes_out1 (sonic, right_reg, val2); -spin_unlock_irq (&sonic->reg_lock);return change; }
Signature · 1 line
2.50.1
PATCH 57/61 ALSA: trident: 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/pci/trident/trident_memory.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
sound/pci/trident/trident_memory.c +5 -14
@@ -172,12 +172,10 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident, -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex); blk =search_empty (hdr, runtime->dma_bytes); -if (blk ==NULL ) { -mutex_unlock (&hdr->block_mutex); +if (blk ==NULL )return NULL ; - }/* set TLB entries */ idx =0 ;
@@ -186,12 +184,10 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,dma_addr_t addr =snd_pcm_sgbuf_get_addr (substream, ofs);if (!is_valid_page (trident, addr)) {__snd_util_mem_free (hdr, blk); -mutex_unlock (&hdr->block_mutex);return NULL ; }set_tlb_bus (trident, page, addr); } -mutex_unlock (&hdr->block_mutex);return blk; }
@@ -216,12 +212,10 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident,if (snd_BUG_ON (!hdr))return NULL ; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex); blk =search_empty (hdr, runtime->dma_bytes); -if (blk ==NULL ) { -mutex_unlock (&hdr->block_mutex); +if (blk ==NULL )return NULL ; - }/* set TLB entries */ addr = runtime->dma_addr;
@@ -229,12 +223,10 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident, addr += SNDRV_TRIDENT_PAGE_SIZE) {if (!is_valid_page (trident, addr)) {__snd_util_mem_free (hdr, blk); -mutex_unlock (&hdr->block_mutex);return NULL ; }set_tlb_bus (trident, page, addr); } -mutex_unlock (&hdr->block_mutex);return blk; }
@@ -267,12 +259,11 @@ int snd_trident_free_pages(struct snd_trident *trident,return -EINVAL ; hdr = trident->tlb.memhdr; -mutex_lock (&hdr->block_mutex); +guard (mutex)(&hdr->block_mutex);/* reset TLB entries */ for (page =firstpg (blk); page <=lastpg (blk); page++)set_silent_tlb (trident, page);/* free memory block */ __snd_util_mem_free (hdr, blk); -mutex_unlock (&hdr->block_mutex);return 0 ; }
Signature · 1 line
2.50.1