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: hrtimer: Use guard() for locking

We can simplify the code gracefully with new guard() macro and co for
automatic cleanup of locks.

Only the code refactoring, and no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240227085306.9764-5-tiwai@suse.de

+11 -13
+11 -13
sound/core/hrtimer.c
··· 35 35 unsigned long ticks; 36 36 enum hrtimer_restart ret = HRTIMER_NORESTART; 37 37 38 - spin_lock(&t->lock); 39 - if (!t->running) 40 - goto out; /* fast path */ 41 - stime->in_callback = true; 42 - ticks = t->sticks; 43 - spin_unlock(&t->lock); 38 + scoped_guard(spinlock, &t->lock) { 39 + if (!t->running) 40 + return HRTIMER_NORESTART; /* fast path */ 41 + stime->in_callback = true; 42 + ticks = t->sticks; 43 + } 44 44 45 45 /* calculate the drift */ 46 46 delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt)); ··· 49 49 50 50 snd_timer_interrupt(stime->timer, ticks); 51 51 52 - spin_lock(&t->lock); 52 + guard(spinlock)(&t->lock); 53 53 if (t->running) { 54 54 hrtimer_add_expires_ns(hrt, t->sticks * resolution); 55 55 ret = HRTIMER_RESTART; 56 56 } 57 57 58 58 stime->in_callback = false; 59 - out: 60 - spin_unlock(&t->lock); 61 59 return ret; 62 60 } 63 61 ··· 78 80 struct snd_hrtimer *stime = t->private_data; 79 81 80 82 if (stime) { 81 - spin_lock_irq(&t->lock); 82 - t->running = 0; /* just to be sure */ 83 - stime->in_callback = 1; /* skip start/stop */ 84 - spin_unlock_irq(&t->lock); 83 + scoped_guard(spinlock_irq, &t->lock) { 84 + t->running = 0; /* just to be sure */ 85 + stime->in_callback = 1; /* skip start/stop */ 86 + } 85 87 86 88 hrtimer_cancel(&stime->hrt); 87 89 kfree(stime);