Skip to content

Commit 659ff9c

Browse files
committed
genirq/proc: Switch to lock guards
Convert all lock/unlock pairs to guards and tidy up the code. No functional change. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/all/20250429065420.373998838@linutronix.de
1 parent 4bcdf07 commit 659ff9c

1 file changed

Lines changed: 24 additions & 41 deletions

File tree

kernel/irq/proc.c

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,18 @@ static int show_irq_affinity(int type, struct seq_file *m)
8181
static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
8282
{
8383
struct irq_desc *desc = irq_to_desc((long)m->private);
84-
unsigned long flags;
8584
cpumask_var_t mask;
8685

8786
if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
8887
return -ENOMEM;
8988

90-
raw_spin_lock_irqsave(&desc->lock, flags);
91-
if (desc->affinity_hint)
92-
cpumask_copy(mask, desc->affinity_hint);
93-
raw_spin_unlock_irqrestore(&desc->lock, flags);
89+
scoped_guard(raw_spinlock_irq, &desc->lock) {
90+
if (desc->affinity_hint)
91+
cpumask_copy(mask, desc->affinity_hint);
92+
}
9493

9594
seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
9695
free_cpumask_var(mask);
97-
9896
return 0;
9997
}
10098

@@ -295,32 +293,26 @@ static int irq_spurious_proc_show(struct seq_file *m, void *v)
295293

296294
#define MAX_NAMELEN 128
297295

298-
static int name_unique(unsigned int irq, struct irqaction *new_action)
296+
static bool name_unique(unsigned int irq, struct irqaction *new_action)
299297
{
300298
struct irq_desc *desc = irq_to_desc(irq);
301299
struct irqaction *action;
302-
unsigned long flags;
303-
int ret = 1;
304300

305-
raw_spin_lock_irqsave(&desc->lock, flags);
301+
guard(raw_spinlock_irq)(&desc->lock);
306302
for_each_action_of_desc(desc, action) {
307303
if ((action != new_action) && action->name &&
308-
!strcmp(new_action->name, action->name)) {
309-
ret = 0;
310-
break;
311-
}
304+
!strcmp(new_action->name, action->name))
305+
return false;
312306
}
313-
raw_spin_unlock_irqrestore(&desc->lock, flags);
314-
return ret;
307+
return true;
315308
}
316309

317310
void register_handler_proc(unsigned int irq, struct irqaction *action)
318311
{
319312
char name [MAX_NAMELEN];
320313
struct irq_desc *desc = irq_to_desc(irq);
321314

322-
if (!desc->dir || action->dir || !action->name ||
323-
!name_unique(irq, action))
315+
if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
324316
return;
325317

326318
snprintf(name, MAX_NAMELEN, "%s", action->name);
@@ -347,17 +339,16 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
347339
* added, not when the descriptor is created, so multiple
348340
* tasks might try to register at the same time.
349341
*/
350-
mutex_lock(&register_lock);
342+
guard(mutex)(&register_lock);
351343

352344
if (desc->dir)
353-
goto out_unlock;
354-
355-
sprintf(name, "%d", irq);
345+
return;
356346

357347
/* create /proc/irq/1234 */
348+
sprintf(name, "%d", irq);
358349
desc->dir = proc_mkdir(name, root_irq_dir);
359350
if (!desc->dir)
360-
goto out_unlock;
351+
return;
361352

362353
#ifdef CONFIG_SMP
363354
umode_t umode = S_IRUGO;
@@ -366,31 +357,27 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
366357
umode |= S_IWUSR;
367358

368359
/* create /proc/irq/<irq>/smp_affinity */
369-
proc_create_data("smp_affinity", umode, desc->dir,
370-
&irq_affinity_proc_ops, irqp);
360+
proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);
371361

372362
/* create /proc/irq/<irq>/affinity_hint */
373363
proc_create_single_data("affinity_hint", 0444, desc->dir,
374-
irq_affinity_hint_proc_show, irqp);
364+
irq_affinity_hint_proc_show, irqp);
375365

376366
/* create /proc/irq/<irq>/smp_affinity_list */
377367
proc_create_data("smp_affinity_list", umode, desc->dir,
378368
&irq_affinity_list_proc_ops, irqp);
379369

380-
proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
381-
irqp);
370+
proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show, irqp);
382371
# ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
383372
proc_create_single_data("effective_affinity", 0444, desc->dir,
384-
irq_effective_aff_proc_show, irqp);
373+
irq_effective_aff_proc_show, irqp);
385374
proc_create_single_data("effective_affinity_list", 0444, desc->dir,
386-
irq_effective_aff_list_proc_show, irqp);
375+
irq_effective_aff_list_proc_show, irqp);
387376
# endif
388377
#endif
389378
proc_create_single_data("spurious", 0444, desc->dir,
390-
irq_spurious_proc_show, (void *)(long)irq);
379+
irq_spurious_proc_show, (void *)(long)irq);
391380

392-
out_unlock:
393-
mutex_unlock(&register_lock);
394381
}
395382

396383
void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
@@ -468,7 +455,6 @@ int show_interrupts(struct seq_file *p, void *v)
468455
int i = *(loff_t *) v, j;
469456
struct irqaction *action;
470457
struct irq_desc *desc;
471-
unsigned long flags;
472458

473459
if (i > ACTUAL_NR_IRQS)
474460
return 0;
@@ -487,13 +473,13 @@ int show_interrupts(struct seq_file *p, void *v)
487473
seq_putc(p, '\n');
488474
}
489475

490-
rcu_read_lock();
476+
guard(rcu)();
491477
desc = irq_to_desc(i);
492478
if (!desc || irq_settings_is_hidden(desc))
493-
goto outsparse;
479+
return 0;
494480

495481
if (!desc->action || irq_desc_is_chained(desc) || !desc->kstat_irqs)
496-
goto outsparse;
482+
return 0;
497483

498484
seq_printf(p, "%*d:", prec, i);
499485
for_each_online_cpu(j) {
@@ -503,7 +489,7 @@ int show_interrupts(struct seq_file *p, void *v)
503489
}
504490
seq_putc(p, ' ');
505491

506-
raw_spin_lock_irqsave(&desc->lock, flags);
492+
guard(raw_spinlock_irq)(&desc->lock);
507493
if (desc->irq_data.chip) {
508494
if (desc->irq_data.chip->irq_print_chip)
509495
desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
@@ -532,9 +518,6 @@ int show_interrupts(struct seq_file *p, void *v)
532518
}
533519

534520
seq_putc(p, '\n');
535-
raw_spin_unlock_irqrestore(&desc->lock, flags);
536-
outsparse:
537-
rcu_read_unlock();
538521
return 0;
539522
}
540523
#endif

0 commit comments

Comments
 (0)