ALSA: ctxfi: 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/20250829144342.4290-24-tiwai@suse.de
This commit is contained in:
Takashi Iwai
2025-08-29 16:42:58 +02:00
parent e1d4c746bb
commit be9478bd3a
5 changed files with 115 additions and 197 deletions
+30 -37
View File
@@ -231,7 +231,6 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,
int err, i;
unsigned int idx;
struct amixer *amixer;
unsigned long flags;
*ramixer = NULL;
@@ -243,15 +242,15 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,
/* Check whether there are sufficient
* amixer resources to meet request. */
err = 0;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
amixer->idx[i] = idx;
amixer->idx[i] = idx;
}
}
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
if (err) {
dev_err(mgr->card->dev,
"Can't meet AMIXER resource request!\n");
@@ -267,25 +266,23 @@ static int get_amixer_rsc(struct amixer_mgr *mgr,
return 0;
error:
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
}
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
kfree(amixer);
return err;
}
static int put_amixer_rsc(struct amixer_mgr *mgr, struct amixer *amixer)
{
unsigned long flags;
int i;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < amixer->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < amixer->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, amixer->idx[i]);
}
amixer_rsc_uninit(amixer);
kfree(amixer);
@@ -387,7 +384,6 @@ static int get_sum_rsc(struct sum_mgr *mgr,
int err, i;
unsigned int idx;
struct sum *sum;
unsigned long flags;
*rsum = NULL;
@@ -398,15 +394,15 @@ static int get_sum_rsc(struct sum_mgr *mgr,
/* Check whether there are sufficient sum resources to meet request. */
err = 0;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
sum->idx[i] = idx;
sum->idx[i] = idx;
}
}
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
if (err) {
dev_err(mgr->card->dev,
"Can't meet SUM resource request!\n");
@@ -422,25 +418,22 @@ static int get_sum_rsc(struct sum_mgr *mgr,
return 0;
error:
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
}
kfree(sum);
return err;
}
static int put_sum_rsc(struct sum_mgr *mgr, struct sum *sum)
{
unsigned long flags;
int i;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < sum->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < sum->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, sum->idx[i]);
}
sum_rsc_uninit(sum);
kfree(sum);
+15 -27
View File
@@ -503,14 +503,13 @@ static int get_daio_rsc(struct daio_mgr *mgr,
struct daio **rdaio)
{
int err;
unsigned long flags;
*rdaio = NULL;
/* Check whether there are sufficient daio resources to meet request. */
spin_lock_irqsave(&mgr->mgr_lock, flags);
err = daio_mgr_get_rsc(&mgr->mgr, desc->type);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
err = daio_mgr_get_rsc(&mgr->mgr, desc->type);
}
if (err) {
dev_err(mgr->card->dev,
"Can't meet DAIO resource request!\n");
@@ -551,22 +550,20 @@ static int get_daio_rsc(struct daio_mgr *mgr,
return 0;
error:
spin_lock_irqsave(&mgr->mgr_lock, flags);
daio_mgr_put_rsc(&mgr->mgr, desc->type);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
daio_mgr_put_rsc(&mgr->mgr, desc->type);
}
return err;
}
static int put_daio_rsc(struct daio_mgr *mgr, struct daio *daio)
{
unsigned long flags;
mgr->daio_disable(mgr, daio);
mgr->commit_write(mgr);
spin_lock_irqsave(&mgr->mgr_lock, flags);
daio_mgr_put_rsc(&mgr->mgr, daio->type);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
daio_mgr_put_rsc(&mgr->mgr, daio->type);
}
if (daio->type <= DAIO_OUT_MAX) {
dao_rsc_uninit(container_of(daio, struct dao, daio));
@@ -622,34 +619,26 @@ static int daio_map_op(void *data, struct imapper *entry)
static int daio_imap_add(struct daio_mgr *mgr, struct imapper *entry)
{
unsigned long flags;
int err;
spin_lock_irqsave(&mgr->imap_lock, flags);
guard(spinlock_irqsave)(&mgr->imap_lock);
if (!entry->addr && mgr->init_imap_added) {
input_mapper_delete(&mgr->imappers, mgr->init_imap,
daio_map_op, mgr);
mgr->init_imap_added = 0;
}
err = input_mapper_add(&mgr->imappers, entry, daio_map_op, mgr);
spin_unlock_irqrestore(&mgr->imap_lock, flags);
return err;
return input_mapper_add(&mgr->imappers, entry, daio_map_op, mgr);
}
static int daio_imap_delete(struct daio_mgr *mgr, struct imapper *entry)
{
unsigned long flags;
int err;
spin_lock_irqsave(&mgr->imap_lock, flags);
guard(spinlock_irqsave)(&mgr->imap_lock);
err = input_mapper_delete(&mgr->imappers, entry, daio_map_op, mgr);
if (list_empty(&mgr->imappers)) {
input_mapper_add(&mgr->imappers, mgr->init_imap,
daio_map_op, mgr);
mgr->init_imap_added = 1;
}
spin_unlock_irqrestore(&mgr->imap_lock, flags);
return err;
}
@@ -719,12 +708,11 @@ error1:
int daio_mgr_destroy(void *ptr)
{
struct daio_mgr *daio_mgr = ptr;
unsigned long flags;
/* free daio input mapper list */
spin_lock_irqsave(&daio_mgr->imap_lock, flags);
free_input_mapper_list(&daio_mgr->imappers);
spin_unlock_irqrestore(&daio_mgr->imap_lock, flags);
scoped_guard(spinlock_irqsave, &daio_mgr->imap_lock) {
free_input_mapper_list(&daio_mgr->imappers);
}
rsc_mgr_uninit(&daio_mgr->mgr);
kfree(daio_mgr);
+6 -33
View File
@@ -2091,57 +2091,30 @@ static int hw_resume(struct hw *hw, struct card_conf *info)
static u32 hw_read_20kx(struct hw *hw, u32 reg)
{
u32 value;
unsigned long flags;
spin_lock_irqsave(
&container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_20k1_lock);
outl(reg, hw->io_base + 0x0);
value = inl(hw->io_base + 0x4);
spin_unlock_irqrestore(
&container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
return value;
return inl(hw->io_base + 0x4);
}
static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
{
unsigned long flags;
spin_lock_irqsave(
&container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_20k1_lock);
outl(reg, hw->io_base + 0x0);
outl(data, hw->io_base + 0x4);
spin_unlock_irqrestore(
&container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
}
static u32 hw_read_pci(struct hw *hw, u32 reg)
{
u32 value;
unsigned long flags;
spin_lock_irqsave(
&container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_pci_lock);
outl(reg, hw->io_base + 0x10);
value = inl(hw->io_base + 0x14);
spin_unlock_irqrestore(
&container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
return value;
return inl(hw->io_base + 0x14);
}
static void hw_write_pci(struct hw *hw, u32 reg, u32 data)
{
unsigned long flags;
spin_lock_irqsave(
&container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
guard(spinlock_irqsave)(&container_of(hw, struct hw20k1, hw)->reg_pci_lock);
outl(reg, hw->io_base + 0x10);
outl(data, hw->io_base + 0x14);
spin_unlock_irqrestore(
&container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
}
static const struct hw ct20k1_preset = {
+41 -60
View File
@@ -414,18 +414,16 @@ get_src_rsc(struct src_mgr *mgr, const struct src_desc *desc, struct src **rsrc)
unsigned int idx = SRC_RESOURCE_NUM;
int err;
struct src *src;
unsigned long flags;
*rsrc = NULL;
/* Check whether there are sufficient src resources to meet request. */
spin_lock_irqsave(&mgr->mgr_lock, flags);
if (MEMRD == desc->mode)
err = mgr_get_resource(&mgr->mgr, desc->multi, &idx);
else
err = mgr_get_resource(&mgr->mgr, 1, &idx);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
if (MEMRD == desc->mode)
err = mgr_get_resource(&mgr->mgr, desc->multi, &idx);
else
err = mgr_get_resource(&mgr->mgr, 1, &idx);
}
if (err) {
dev_err(mgr->card->dev,
"Can't meet SRC resource request!\n");
@@ -454,29 +452,25 @@ get_src_rsc(struct src_mgr *mgr, const struct src_desc *desc, struct src **rsrc)
error2:
kfree(src);
error1:
spin_lock_irqsave(&mgr->mgr_lock, flags);
if (MEMRD == desc->mode)
mgr_put_resource(&mgr->mgr, desc->multi, idx);
else
mgr_put_resource(&mgr->mgr, 1, idx);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
if (MEMRD == desc->mode)
mgr_put_resource(&mgr->mgr, desc->multi, idx);
else
mgr_put_resource(&mgr->mgr, 1, idx);
}
return err;
}
static int put_src_rsc(struct src_mgr *mgr, struct src *src)
{
unsigned long flags;
spin_lock_irqsave(&mgr->mgr_lock, flags);
src->rsc.ops->master(&src->rsc);
if (MEMRD == src->mode)
mgr_put_resource(&mgr->mgr, src->multi,
src->rsc.ops->index(&src->rsc));
else
mgr_put_resource(&mgr->mgr, 1, src->rsc.ops->index(&src->rsc));
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
src->rsc.ops->master(&src->rsc);
if (MEMRD == src->mode)
mgr_put_resource(&mgr->mgr, src->multi,
src->rsc.ops->index(&src->rsc));
else
mgr_put_resource(&mgr->mgr, 1, src->rsc.ops->index(&src->rsc));
}
src_rsc_uninit(src, mgr);
kfree(src);
@@ -714,7 +708,6 @@ static int get_srcimp_rsc(struct srcimp_mgr *mgr,
int err, i;
unsigned int idx;
struct srcimp *srcimp;
unsigned long flags;
*rsrcimp = NULL;
@@ -725,15 +718,15 @@ static int get_srcimp_rsc(struct srcimp_mgr *mgr,
/* Check whether there are sufficient SRCIMP resources. */
err = 0;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < desc->msr; i++) {
err = mgr_get_resource(&mgr->mgr, 1, &idx);
if (err)
break;
srcimp->idx[i] = idx;
srcimp->idx[i] = idx;
}
}
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
if (err) {
dev_err(mgr->card->dev,
"Can't meet SRCIMP resource request!\n");
@@ -749,25 +742,22 @@ static int get_srcimp_rsc(struct srcimp_mgr *mgr,
return 0;
error1:
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, srcimp->idx[i]);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i--; i >= 0; i--)
mgr_put_resource(&mgr->mgr, 1, srcimp->idx[i]);
}
kfree(srcimp);
return err;
}
static int put_srcimp_rsc(struct srcimp_mgr *mgr, struct srcimp *srcimp)
{
unsigned long flags;
int i;
spin_lock_irqsave(&mgr->mgr_lock, flags);
for (i = 0; i < srcimp->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, srcimp->idx[i]);
spin_unlock_irqrestore(&mgr->mgr_lock, flags);
scoped_guard(spinlock_irqsave, &mgr->mgr_lock) {
for (i = 0; i < srcimp->rsc.msr; i++)
mgr_put_resource(&mgr->mgr, 1, srcimp->idx[i]);
}
srcimp_rsc_uninit(srcimp);
kfree(srcimp);
@@ -790,34 +780,26 @@ static int srcimp_map_op(void *data, struct imapper *entry)
static int srcimp_imap_add(struct srcimp_mgr *mgr, struct imapper *entry)
{
unsigned long flags;
int err;
spin_lock_irqsave(&mgr->imap_lock, flags);
guard(spinlock_irqsave)(&mgr->imap_lock);
if ((0 == entry->addr) && (mgr->init_imap_added)) {
input_mapper_delete(&mgr->imappers,
mgr->init_imap, srcimp_map_op, mgr);
mgr->init_imap_added = 0;
}
err = input_mapper_add(&mgr->imappers, entry, srcimp_map_op, mgr);
spin_unlock_irqrestore(&mgr->imap_lock, flags);
return err;
return input_mapper_add(&mgr->imappers, entry, srcimp_map_op, mgr);
}
static int srcimp_imap_delete(struct srcimp_mgr *mgr, struct imapper *entry)
{
unsigned long flags;
int err;
spin_lock_irqsave(&mgr->imap_lock, flags);
guard(spinlock_irqsave)(&mgr->imap_lock);
err = input_mapper_delete(&mgr->imappers, entry, srcimp_map_op, mgr);
if (list_empty(&mgr->imappers)) {
input_mapper_add(&mgr->imappers, mgr->init_imap,
srcimp_map_op, mgr);
mgr->init_imap_added = 1;
}
spin_unlock_irqrestore(&mgr->imap_lock, flags);
return err;
}
@@ -870,12 +852,11 @@ error1:
int srcimp_mgr_destroy(void *ptr)
{
struct srcimp_mgr *srcimp_mgr = ptr;
unsigned long flags;
/* free src input mapper list */
spin_lock_irqsave(&srcimp_mgr->imap_lock, flags);
free_input_mapper_list(&srcimp_mgr->imappers);
spin_unlock_irqrestore(&srcimp_mgr->imap_lock, flags);
scoped_guard(spinlock_irqsave, &srcimp_mgr->imap_lock) {
free_input_mapper_list(&srcimp_mgr->imappers);
}
rsc_mgr_uninit(&srcimp_mgr->mgr);
kfree(srcimp_mgr);
+23 -40
View File
@@ -68,7 +68,6 @@ static void ct_systimer_callback(struct timer_list *t)
struct ct_atc_pcm *apcm = ti->apcm;
unsigned int period_size = runtime->period_size;
unsigned int buffer_size = runtime->buffer_size;
unsigned long flags;
unsigned int position, dist, interval;
position = substream->ops->pointer(substream);
@@ -82,10 +81,9 @@ static void ct_systimer_callback(struct timer_list *t)
* at 8kHz in 8-bit format or at 88kHz in 24-bit format. */
interval = ((period_size - (position % period_size))
* HZ + (runtime->rate - 1)) / runtime->rate + HZ * 5 / 1000;
spin_lock_irqsave(&ti->lock, flags);
guard(spinlock_irqsave)(&ti->lock);
if (ti->running)
mod_timer(&ti->timer, jiffies + interval);
spin_unlock_irqrestore(&ti->lock, flags);
}
static void ct_systimer_init(struct ct_timer_instance *ti)
@@ -96,24 +94,19 @@ static void ct_systimer_init(struct ct_timer_instance *ti)
static void ct_systimer_start(struct ct_timer_instance *ti)
{
struct snd_pcm_runtime *runtime = ti->substream->runtime;
unsigned long flags;
spin_lock_irqsave(&ti->lock, flags);
guard(spinlock_irqsave)(&ti->lock);
ti->running = 1;
mod_timer(&ti->timer,
jiffies + (runtime->period_size * HZ +
(runtime->rate - 1)) / runtime->rate);
spin_unlock_irqrestore(&ti->lock, flags);
}
static void ct_systimer_stop(struct ct_timer_instance *ti)
{
unsigned long flags;
spin_lock_irqsave(&ti->lock, flags);
guard(spinlock_irqsave)(&ti->lock);
ti->running = 0;
timer_delete(&ti->timer);
spin_unlock_irqrestore(&ti->lock, flags);
}
static void ct_systimer_prepare(struct ct_timer_instance *ti)
@@ -229,25 +222,22 @@ static int ct_xfitimer_reprogram(struct ct_timer *atimer, int can_update)
static void ct_xfitimer_check_period(struct ct_timer *atimer)
{
struct ct_timer_instance *ti;
unsigned long flags;
spin_lock_irqsave(&atimer->list_lock, flags);
guard(spinlock_irqsave)(&atimer->list_lock);
list_for_each_entry(ti, &atimer->instance_head, instance_list) {
if (ti->running && ti->need_update) {
ti->need_update = 0;
ti->apcm->interrupt(ti->apcm);
}
}
spin_unlock_irqrestore(&atimer->list_lock, flags);
}
/* Handle timer-interrupt */
static void ct_xfitimer_callback(struct ct_timer *atimer)
{
int update;
unsigned long flags;
spin_lock_irqsave(&atimer->lock, flags);
guard(spinlock_irqsave)(&atimer->lock);
atimer->irq_handling = 1;
do {
update = ct_xfitimer_reprogram(atimer, 1);
@@ -257,7 +247,6 @@ static void ct_xfitimer_callback(struct ct_timer *atimer)
spin_lock(&atimer->lock);
} while (atimer->reprogram);
atimer->irq_handling = 0;
spin_unlock_irqrestore(&atimer->lock, flags);
}
static void ct_xfitimer_prepare(struct ct_timer_instance *ti)
@@ -271,45 +260,39 @@ static void ct_xfitimer_prepare(struct ct_timer_instance *ti)
/* start/stop the timer */
static void ct_xfitimer_update(struct ct_timer *atimer)
{
unsigned long flags;
spin_lock_irqsave(&atimer->lock, flags);
guard(spinlock_irqsave)(&atimer->lock);
if (atimer->irq_handling) {
/* reached from IRQ handler; let it handle later */
atimer->reprogram = 1;
spin_unlock_irqrestore(&atimer->lock, flags);
return;
}
ct_xfitimer_irq_stop(atimer);
ct_xfitimer_reprogram(atimer, 0);
spin_unlock_irqrestore(&atimer->lock, flags);
}
static void ct_xfitimer_start(struct ct_timer_instance *ti)
{
struct ct_timer *atimer = ti->timer_base;
unsigned long flags;
spin_lock_irqsave(&atimer->lock, flags);
if (list_empty(&ti->running_list))
atimer->wc = ct_xfitimer_get_wc(atimer);
ti->running = 1;
ti->need_update = 0;
list_add(&ti->running_list, &atimer->running_head);
spin_unlock_irqrestore(&atimer->lock, flags);
scoped_guard(spinlock_irqsave, &atimer->lock) {
if (list_empty(&ti->running_list))
atimer->wc = ct_xfitimer_get_wc(atimer);
ti->running = 1;
ti->need_update = 0;
list_add(&ti->running_list, &atimer->running_head);
}
ct_xfitimer_update(atimer);
}
static void ct_xfitimer_stop(struct ct_timer_instance *ti)
{
struct ct_timer *atimer = ti->timer_base;
unsigned long flags;
spin_lock_irqsave(&atimer->lock, flags);
list_del_init(&ti->running_list);
ti->running = 0;
spin_unlock_irqrestore(&atimer->lock, flags);
scoped_guard(spinlock_irqsave, &atimer->lock) {
list_del_init(&ti->running_list);
ti->running = 0;
}
ct_xfitimer_update(atimer);
}
@@ -347,9 +330,9 @@ ct_timer_instance_new(struct ct_timer *atimer, struct ct_atc_pcm *apcm)
if (atimer->ops->init)
atimer->ops->init(ti);
spin_lock_irq(&atimer->list_lock);
list_add(&ti->instance_list, &atimer->instance_head);
spin_unlock_irq(&atimer->list_lock);
scoped_guard(spinlock_irq, &atimer->list_lock) {
list_add(&ti->instance_list, &atimer->instance_head);
}
return ti;
}
@@ -382,9 +365,9 @@ void ct_timer_instance_free(struct ct_timer_instance *ti)
if (atimer->ops->free_instance)
atimer->ops->free_instance(ti);
spin_lock_irq(&atimer->list_lock);
list_del(&ti->instance_list);
spin_unlock_irq(&atimer->list_lock);
scoped_guard(spinlock_irq, &atimer->list_lock) {
list_del(&ti->instance_list);
}
kfree(ti);
}