Commit 659ff9c9 authored by Thomas Gleixner's avatar Thomas Gleixner
Browse files

genirq/proc: Switch to lock guards



Convert all lock/unlock pairs to guards and tidy up the code.

No functional change.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20250429065420.373998838@linutronix.de
parent 4bcdf074
Loading
Loading
Loading
Loading
+24 −41
Original line number Diff line number Diff line
@@ -81,20 +81,18 @@ static int show_irq_affinity(int type, struct seq_file *m)
static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
{
	struct irq_desc *desc = irq_to_desc((long)m->private);
	unsigned long flags;
	cpumask_var_t mask;

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

	raw_spin_lock_irqsave(&desc->lock, flags);
	scoped_guard(raw_spinlock_irq, &desc->lock) {
		if (desc->affinity_hint)
			cpumask_copy(mask, desc->affinity_hint);
	raw_spin_unlock_irqrestore(&desc->lock, flags);
	}

	seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
	free_cpumask_var(mask);

	return 0;
}

@@ -295,23 +293,18 @@ static int irq_spurious_proc_show(struct seq_file *m, void *v)

#define MAX_NAMELEN 128

static int name_unique(unsigned int irq, struct irqaction *new_action)
static bool name_unique(unsigned int irq, struct irqaction *new_action)
{
	struct irq_desc *desc = irq_to_desc(irq);
	struct irqaction *action;
	unsigned long flags;
	int ret = 1;

	raw_spin_lock_irqsave(&desc->lock, flags);
	guard(raw_spinlock_irq)(&desc->lock);
	for_each_action_of_desc(desc, action) {
		if ((action != new_action) && action->name &&
				!strcmp(new_action->name, action->name)) {
			ret = 0;
			break;
		    !strcmp(new_action->name, action->name))
			return false;
	}
	}
	raw_spin_unlock_irqrestore(&desc->lock, flags);
	return ret;
	return true;
}

void register_handler_proc(unsigned int irq, struct irqaction *action)
@@ -319,8 +312,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)
	char name [MAX_NAMELEN];
	struct irq_desc *desc = irq_to_desc(irq);

	if (!desc->dir || action->dir || !action->name ||
					!name_unique(irq, action))
	if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
		return;

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

	if (desc->dir)
		goto out_unlock;

	sprintf(name, "%d", irq);
		return;

	/* create /proc/irq/1234 */
	sprintf(name, "%d", irq);
	desc->dir = proc_mkdir(name, root_irq_dir);
	if (!desc->dir)
		goto out_unlock;
		return;

#ifdef CONFIG_SMP
	umode_t umode = S_IRUGO;
@@ -366,8 +357,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
		umode |= S_IWUSR;

	/* create /proc/irq/<irq>/smp_affinity */
	proc_create_data("smp_affinity", umode, desc->dir,
			 &irq_affinity_proc_ops, irqp);
	proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);

	/* create /proc/irq/<irq>/affinity_hint */
	proc_create_single_data("affinity_hint", 0444, desc->dir,
@@ -377,8 +367,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
	proc_create_data("smp_affinity_list", umode, desc->dir,
			 &irq_affinity_list_proc_ops, irqp);

	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
			irqp);
	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show, irqp);
# ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
	proc_create_single_data("effective_affinity", 0444, desc->dir,
				irq_effective_aff_proc_show, irqp);
@@ -389,8 +378,6 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
	proc_create_single_data("spurious", 0444, desc->dir,
				irq_spurious_proc_show, (void *)(long)irq);

out_unlock:
	mutex_unlock(&register_lock);
}

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

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

	rcu_read_lock();
	guard(rcu)();
	desc = irq_to_desc(i);
	if (!desc || irq_settings_is_hidden(desc))
		goto outsparse;
		return 0;

	if (!desc->action || irq_desc_is_chained(desc) || !desc->kstat_irqs)
		goto outsparse;
		return 0;

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

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

	seq_putc(p, '\n');
	raw_spin_unlock_irqrestore(&desc->lock, flags);
outsparse:
	rcu_read_unlock();
	return 0;
}
#endif