Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: pdaudiocf: 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/20250829151335.7342-11-tiwai@suse.de

+13 -15
+1 -2
sound/pcmcia/pdaudiocf/pdaudiocf_core.c
··· 161 161 162 162 if (!(c0 & AK4117_UNLCK)) 163 163 return; 164 - mutex_lock(&chip->reg_lock); 164 + guard(mutex)(&chip->reg_lock); 165 165 val = chip->regmap[PDAUDIOCF_REG_SCR>>1]; 166 166 if (ak4117->rcs0 & AK4117_UNLCK) 167 167 val |= PDAUDIOCF_BLUE_LED_OFF; 168 168 else 169 169 val &= ~PDAUDIOCF_BLUE_LED_OFF; 170 170 pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, val); 171 - mutex_unlock(&chip->reg_lock); 172 171 } 173 172 174 173 int snd_pdacf_ak4117_create(struct snd_pdacf *chip)
+12 -13
sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
··· 64 64 default: 65 65 return -EINVAL; 66 66 } 67 - mutex_lock(&chip->reg_lock); 68 - chip->pcm_running += inc; 69 - tmp = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); 70 - if (chip->pcm_running) { 71 - if ((chip->ak4117->rcs0 & AK4117_UNLCK) || runtime->rate != rate) { 72 - chip->pcm_running -= inc; 73 - ret = -EIO; 74 - goto __end; 67 + scoped_guard(mutex, &chip->reg_lock) { 68 + chip->pcm_running += inc; 69 + tmp = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR); 70 + if (chip->pcm_running) { 71 + if ((chip->ak4117->rcs0 & AK4117_UNLCK) || runtime->rate != rate) { 72 + chip->pcm_running -= inc; 73 + ret = -EIO; 74 + break; 75 + } 75 76 } 77 + tmp &= ~mask; 78 + tmp |= val; 79 + pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, tmp); 76 80 } 77 - tmp &= ~mask; 78 - tmp |= val; 79 - pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, tmp); 80 - __end: 81 - mutex_unlock(&chip->reg_lock); 82 81 snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_RATE); 83 82 return ret; 84 83 }