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. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250829144342.4290-2-tiwai@suse.de
This commit is contained in:
@@ -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 va
|
||||
|
||||
if (!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, uns
|
||||
int 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, struct
|
||||
struct 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,12 +54,11 @@ static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsi
|
||||
unsigned 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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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_in
|
||||
struct 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_in
|
||||
if (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)
|
||||
|
||||
Reference in New Issue
Block a user