mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 10:01:39 -05:00
ALSA: ens137x: 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-6-tiwai@suse.de
This commit is contained in:
@@ -77,9 +77,8 @@ static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_e
|
||||
int 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_e
|
||||
int 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_ctl
|
||||
int 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_ctl
|
||||
int 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user