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

ALSA: opl3sa2: Use guard() for spin locks

Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829145300.5460-11-tiwai@suse.de

+7 -22
+7 -22
sound/isa/opl3sa2.c
··· 172 172 /* read control port (with spinlock) */ 173 173 static unsigned char snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) 174 174 { 175 - unsigned long flags; 176 - unsigned char result; 177 - 178 - spin_lock_irqsave(&chip->reg_lock, flags); 179 - result = __snd_opl3sa2_read(chip, reg); 180 - spin_unlock_irqrestore(&chip->reg_lock, flags); 181 - return result; 175 + guard(spinlock_irqsave)(&chip->reg_lock); 176 + return __snd_opl3sa2_read(chip, reg); 182 177 } 183 178 184 179 /* write control port (w/o spinlock) */ ··· 190 195 /* write control port (with spinlock) */ 191 196 static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) 192 197 { 193 - unsigned long flags; 194 - spin_lock_irqsave(&chip->reg_lock, flags); 198 + guard(spinlock_irqsave)(&chip->reg_lock); 195 199 __snd_opl3sa2_write(chip, reg, value); 196 - spin_unlock_irqrestore(&chip->reg_lock, flags); 197 200 } 198 201 199 202 static int snd_opl3sa2_detect(struct snd_card *card) ··· 329 336 static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 330 337 { 331 338 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 332 - unsigned long flags; 333 339 int reg = kcontrol->private_value & 0xff; 334 340 int shift = (kcontrol->private_value >> 8) & 0xff; 335 341 int mask = (kcontrol->private_value >> 16) & 0xff; 336 342 int invert = (kcontrol->private_value >> 24) & 0xff; 337 343 338 - spin_lock_irqsave(&chip->reg_lock, flags); 344 + guard(spinlock_irqsave)(&chip->reg_lock); 339 345 ucontrol->value.integer.value[0] = (chip->ctlregs[reg] >> shift) & mask; 340 - spin_unlock_irqrestore(&chip->reg_lock, flags); 341 346 if (invert) 342 347 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 343 348 return 0; ··· 344 353 static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 345 354 { 346 355 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 347 - unsigned long flags; 348 356 int reg = kcontrol->private_value & 0xff; 349 357 int shift = (kcontrol->private_value >> 8) & 0xff; 350 358 int mask = (kcontrol->private_value >> 16) & 0xff; ··· 355 365 if (invert) 356 366 val = mask - val; 357 367 val <<= shift; 358 - spin_lock_irqsave(&chip->reg_lock, flags); 368 + guard(spinlock_irqsave)(&chip->reg_lock); 359 369 oval = chip->ctlregs[reg]; 360 370 val = (oval & ~(mask << shift)) | val; 361 371 change = val != oval; 362 372 __snd_opl3sa2_write(chip, reg, val); 363 - spin_unlock_irqrestore(&chip->reg_lock, flags); 364 373 return change; 365 374 } 366 375 ··· 380 391 static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 381 392 { 382 393 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 383 - unsigned long flags; 384 394 int left_reg = kcontrol->private_value & 0xff; 385 395 int right_reg = (kcontrol->private_value >> 8) & 0xff; 386 396 int shift_left = (kcontrol->private_value >> 16) & 0x07; ··· 387 399 int mask = (kcontrol->private_value >> 24) & 0xff; 388 400 int invert = (kcontrol->private_value >> 22) & 1; 389 401 390 - spin_lock_irqsave(&chip->reg_lock, flags); 402 + guard(spinlock_irqsave)(&chip->reg_lock); 391 403 ucontrol->value.integer.value[0] = (chip->ctlregs[left_reg] >> shift_left) & mask; 392 404 ucontrol->value.integer.value[1] = (chip->ctlregs[right_reg] >> shift_right) & mask; 393 - spin_unlock_irqrestore(&chip->reg_lock, flags); 394 405 if (invert) { 395 406 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 396 407 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; ··· 400 413 static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 401 414 { 402 415 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 403 - unsigned long flags; 404 416 int left_reg = kcontrol->private_value & 0xff; 405 417 int right_reg = (kcontrol->private_value >> 8) & 0xff; 406 418 int shift_left = (kcontrol->private_value >> 16) & 0x07; ··· 417 431 } 418 432 val1 <<= shift_left; 419 433 val2 <<= shift_right; 420 - spin_lock_irqsave(&chip->reg_lock, flags); 434 + guard(spinlock_irqsave)(&chip->reg_lock); 421 435 if (left_reg != right_reg) { 422 436 oval1 = chip->ctlregs[left_reg]; 423 437 oval2 = chip->ctlregs[right_reg]; ··· 432 446 change = val1 != oval1; 433 447 __snd_opl3sa2_write(chip, left_reg, val1); 434 448 } 435 - spin_unlock_irqrestore(&chip->reg_lock, flags); 436 449 return change; 437 450 } 438 451