public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>, Jiri Slaby <jirislaby@kernel.org>
Subject: [patch 30/46] genirq/manage: Convert to lock guards
Date: Thu, 13 Mar 2025 17:00:34 +0100 (CET)	[thread overview]
Message-ID: <20250313155915.929305667@linutronix.de> (raw)
In-Reply-To: 20250313154615.860723120@linutronix.de

Convert lock/unlock pairs to guards.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/irq/manage.c |  155 +++++++++++++++++++---------------------------------
 1 file changed, 58 insertions(+), 97 deletions(-)

--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -41,8 +41,6 @@ static void __synchronize_hardirq(struct
 	bool inprogress;
 
 	do {
-		unsigned long flags;
-
 		/*
 		 * Wait until we're out of the critical section.  This might
 		 * give the wrong answer due to the lack of memory barriers.
@@ -51,7 +49,7 @@ static void __synchronize_hardirq(struct
 			cpu_relax();
 
 		/* Ok, that indicated we're done: double-check carefully. */
-		raw_spin_lock_irqsave(&desc->lock, flags);
+		guard(raw_spinlock_irqsave)(&desc->lock);
 		inprogress = irqd_irq_inprogress(&desc->irq_data);
 
 		/*
@@ -67,8 +65,6 @@ static void __synchronize_hardirq(struct
 			__irq_get_irqchip_state(irqd, IRQCHIP_STATE_ACTIVE,
 						&inprogress);
 		}
-		raw_spin_unlock_irqrestore(&desc->lock, flags);
-
 		/* Oops, that failed? */
 	} while (inprogress);
 }
@@ -456,16 +452,12 @@ static int __irq_set_affinity(unsigned i
 			      bool force)
 {
 	struct irq_desc *desc = irq_to_desc(irq);
-	unsigned long flags;
-	int ret;
 
 	if (!desc)
 		return -EINVAL;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	ret = irq_set_affinity_locked(irq_desc_get_irq_data(desc), mask, force);
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-	return ret;
+	guard(raw_spinlock_irqsave)(&desc->lock);
+	return irq_set_affinity_locked(irq_desc_get_irq_data(desc), mask, force);
 }
 
 /**
@@ -520,17 +512,16 @@ static void irq_affinity_notify(struct w
 		container_of(work, struct irq_affinity_notify, work);
 	struct irq_desc *desc = irq_to_desc(notify->irq);
 	cpumask_var_t cpumask;
-	unsigned long flags;
 
 	if (!desc || !alloc_cpumask_var(&cpumask, GFP_KERNEL))
 		goto out;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	if (irq_move_pending(&desc->irq_data))
-		irq_get_pending(cpumask, desc);
-	else
-		cpumask_copy(cpumask, desc->irq_common_data.affinity);
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
+	scoped_guard (raw_spinlock_irqsave, &desc->lock) {
+		if (irq_move_pending(&desc->irq_data))
+			irq_get_pending(cpumask, desc);
+		else
+			cpumask_copy(cpumask, desc->irq_common_data.affinity);
+	}
 
 	notify->notify(notify, cpumask);
 
@@ -554,7 +545,6 @@ int irq_set_affinity_notifier(unsigned i
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irq_affinity_notify *old_notify;
-	unsigned long flags;
 
 	/* The release function is promised process context */
 	might_sleep();
@@ -569,10 +559,10 @@ int irq_set_affinity_notifier(unsigned i
 		INIT_WORK(&notify->work, irq_affinity_notify);
 	}
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	old_notify = desc->affinity_notify;
-	desc->affinity_notify = notify;
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
+	scoped_guard (raw_spinlock_irqsave, &desc->lock) {
+		old_notify = desc->affinity_notify;
+		desc->affinity_notify = notify;
+	}
 
 	if (old_notify) {
 		if (cancel_work_sync(&old_notify->work)) {
@@ -593,7 +583,8 @@ EXPORT_SYMBOL_GPL(irq_set_affinity_notif
 int irq_setup_affinity(struct irq_desc *desc)
 {
 	struct cpumask *set = irq_default_affinity;
-	int ret, node = irq_desc_get_node(desc);
+	int node = irq_desc_get_node(desc);
+
 	static DEFINE_RAW_SPINLOCK(mask_lock);
 	static struct cpumask mask;
 
@@ -601,7 +592,7 @@ int irq_setup_affinity(struct irq_desc *
 	if (!__irq_can_set_affinity(desc))
 		return 0;
 
-	raw_spin_lock(&mask_lock);
+	guard(raw_spinlock)(&mask_lock);
 	/*
 	 * Preserve the managed affinity setting and a userspace affinity
 	 * setup, but make sure that one of the targets is online.
@@ -626,9 +617,7 @@ int irq_setup_affinity(struct irq_desc *
 		if (cpumask_intersects(&mask, nodemask))
 			cpumask_and(&mask, &mask, nodemask);
 	}
-	ret = irq_do_set_affinity(&desc->irq_data, &mask, false);
-	raw_spin_unlock(&mask_lock);
-	return ret;
+	return irq_do_set_affinity(&desc->irq_data, &mask, false);
 }
 #else
 /* Wrapper for ALPHA specific affinity selector magic */
@@ -1070,19 +1059,19 @@ static void irq_thread_check_affinity(st
 		return;
 	}
 
-	raw_spin_lock_irq(&desc->lock);
-	/*
-	 * This code is triggered unconditionally. Check the affinity
-	 * mask pointer. For CPU_MASK_OFFSTACK=n this is optimized out.
-	 */
-	if (cpumask_available(desc->irq_common_data.affinity)) {
-		const struct cpumask *m;
+	scoped_guard (raw_spinlock_irq, &desc->lock) {
+		/*
+		 * This code is triggered unconditionally. Check the affinity
+		 * mask pointer. For CPU_MASK_OFFSTACK=n this is optimized out.
+		 */
+		if (cpumask_available(desc->irq_common_data.affinity)) {
+			const struct cpumask *m;
 
-		m = irq_data_get_effective_affinity_mask(&desc->irq_data);
-		cpumask_copy(mask, m);
-		valid = true;
+			m = irq_data_get_effective_affinity_mask(&desc->irq_data);
+			cpumask_copy(mask, m);
+			valid = true;
+		}
 	}
-	raw_spin_unlock_irq(&desc->lock);
 
 	if (valid)
 		set_cpus_allowed_ptr(current, mask);
@@ -1250,9 +1239,8 @@ static void irq_wake_secondary(struct ir
 	if (WARN_ON_ONCE(!secondary))
 		return;
 
-	raw_spin_lock_irq(&desc->lock);
+	guard(raw_spinlock_irq)(&desc->lock);
 	__irq_wake_thread(desc, secondary);
-	raw_spin_unlock_irq(&desc->lock);
 }
 
 /*
@@ -1333,12 +1321,11 @@ void irq_wake_thread(unsigned int irq, v
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irqaction *action;
-	unsigned long flags;
 
 	if (!desc || WARN_ON(irq_settings_is_per_cpu_devid(desc)))
 		return;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irqsave)(&desc->lock);
 	for_each_action_of_desc(desc, action) {
 		if (action->dev_id == dev_id) {
 			if (action->thread)
@@ -1346,7 +1333,6 @@ void irq_wake_thread(unsigned int irq, v
 			break;
 		}
 	}
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
 }
 EXPORT_SYMBOL_GPL(irq_wake_thread);
 
@@ -1977,9 +1963,8 @@ static struct irqaction *__free_irq(stru
 		 * There is no interrupt on the fly anymore. Deactivate it
 		 * completely.
 		 */
-		raw_spin_lock_irqsave(&desc->lock, flags);
-		irq_domain_deactivate_irq(&desc->irq_data);
-		raw_spin_unlock_irqrestore(&desc->lock, flags);
+		scoped_guard (raw_spinlock_irqsave, &desc->lock)
+			irq_domain_deactivate_irq(&desc->irq_data);
 
 		irq_release_resources(desc);
 		chip_bus_sync_unlock(desc);
@@ -2064,8 +2049,6 @@ static const void *__cleanup_nmi(unsigne
 const void *free_nmi(unsigned int irq, void *dev_id)
 {
 	struct irq_desc *desc = irq_to_desc(irq);
-	unsigned long flags;
-	const void *devname;
 
 	if (!desc || WARN_ON(!irq_is_nmi(desc)))
 		return NULL;
@@ -2077,14 +2060,9 @@ const void *free_nmi(unsigned int irq, v
 	if (WARN_ON(desc->depth == 0))
 		disable_nmi_nosync(irq);
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-
+	guard(raw_spinlock_irqsave)(&desc->lock);
 	irq_nmi_teardown(desc);
-	devname = __cleanup_nmi(irq, desc);
-
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-
-	return devname;
+	return __cleanup_nmi(irq, desc);
 }
 
 /**
@@ -2288,7 +2266,6 @@ int request_nmi(unsigned int irq, irq_ha
 {
 	struct irqaction *action;
 	struct irq_desc *desc;
-	unsigned long flags;
 	int retval;
 
 	if (irq == IRQ_NOTCONNECTED)
@@ -2330,21 +2307,17 @@ int request_nmi(unsigned int irq, irq_ha
 	if (retval)
 		goto err_irq_setup;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-
-	/* Setup NMI state */
-	desc->istate |= IRQS_NMI;
-	retval = irq_nmi_setup(desc);
-	if (retval) {
-		__cleanup_nmi(irq, desc);
-		raw_spin_unlock_irqrestore(&desc->lock, flags);
-		return -EINVAL;
+	scoped_guard (raw_spinlock_irqsave, &desc->lock) {
+		/* Setup NMI state */
+		desc->istate |= IRQS_NMI;
+		retval = irq_nmi_setup(desc);
+		if (retval) {
+			__cleanup_nmi(irq, desc);
+			return -EINVAL;
+		}
+		return 0;
 	}
 
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-
-	return 0;
-
 err_irq_setup:
 	irq_chip_pm_put(&desc->irq_data);
 err_out:
@@ -2443,43 +2416,34 @@ static struct irqaction *__free_percpu_i
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irqaction *action;
-	unsigned long flags;
 
 	WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
 
 	if (!desc)
 		return NULL;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	scoped_guard (raw_spinlock_irqsave, &desc->lock) {
+		action = desc->action;
+		if (!action || action->percpu_dev_id != dev_id) {
+			WARN(1, "Trying to free already-free IRQ %d\n", irq);
+			return NULL;
+		}
 
-	action = desc->action;
-	if (!action || action->percpu_dev_id != dev_id) {
-		WARN(1, "Trying to free already-free IRQ %d\n", irq);
-		goto bad;
-	}
+		if (!cpumask_empty(desc->percpu_enabled)) {
+			WARN(1, "percpu IRQ %d still enabled on CPU%d!\n",
+			     irq, cpumask_first(desc->percpu_enabled));
+			return NULL;
+		}
 
-	if (!cpumask_empty(desc->percpu_enabled)) {
-		WARN(1, "percpu IRQ %d still enabled on CPU%d!\n",
-		     irq, cpumask_first(desc->percpu_enabled));
-		goto bad;
+		/* Found it - now remove it from the list of entries: */
+		desc->action = NULL;
+		desc->istate &= ~IRQS_NMI;
 	}
 
-	/* Found it - now remove it from the list of entries: */
-	desc->action = NULL;
-
-	desc->istate &= ~IRQS_NMI;
-
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-
 	unregister_handler_proc(irq, action);
-
 	irq_chip_pm_put(&desc->irq_data);
 	module_put(desc->owner);
 	return action;
-
-bad:
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-	return NULL;
 }
 
 /**
@@ -2649,7 +2613,6 @@ int request_percpu_nmi(unsigned int irq,
 {
 	struct irqaction *action;
 	struct irq_desc *desc;
-	unsigned long flags;
 	int retval;
 
 	if (!handler)
@@ -2685,10 +2648,8 @@ int request_percpu_nmi(unsigned int irq,
 	if (retval)
 		goto err_irq_setup;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irqsave)(&desc->lock);
 	desc->istate |= IRQS_NMI;
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-
 	return 0;
 
 err_irq_setup:


  parent reply	other threads:[~2025-03-13 16:00 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 15:59 [patch 00/46] genirq: Cleanups and conversion to lock guards Thomas Gleixner
2025-03-13 15:59 ` [patch 01/46] genirq: Provide conditional " Thomas Gleixner
2025-03-13 15:59 ` [patch 02/46] genirq/irqdesc: Switch to " Thomas Gleixner
2025-03-14 10:57   ` Jiri Slaby
2025-03-13 15:59 ` [patch 03/46] genirq/autoprobe: " Thomas Gleixner
2025-03-13 15:59 ` [patch 04/46] genirq/pm: " Thomas Gleixner
2025-03-13 15:59 ` [patch 05/46] genirq/resend: " Thomas Gleixner
2025-03-17  8:22   ` Shrikanth Hegde
2025-03-13 15:59 ` [patch 06/46] genirq/proc: " Thomas Gleixner
2025-03-13 15:59 ` [patch 07/46] genirq/spurious: Cleanup code Thomas Gleixner
2025-03-13 15:59 ` [patch 08/46] genirq/spurious: Switch to lock guards Thomas Gleixner
2025-03-13 15:59 ` [patch 09/46] genirq/cpuhotplug: Convert " Thomas Gleixner
2025-03-13 15:59 ` [patch 10/46] genirq/debugfs: " Thomas Gleixner
2025-03-13 16:00 ` [patch 11/46] genirq/chip: Prepare for code reduction Thomas Gleixner
2025-03-13 16:00 ` [patch 12/46] genirq/chip: Rework handle_nested_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 13/46] genirq/chip: Rework handle_simple_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 14/46] genirq/chip: Rework handle_untracked_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 15/46] genirq/chip: Rework handle_level_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 16/46] genirq/chip: Rework handle_eoi_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 17/46] genirq/chip: Rework handle_edge_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 18/46] genirq/chip: Rework handle_edge_eoi_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 19/46] genirq/chip: Rework handle_fasteoi_ack_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 20/46] genirq/chip: Rework handle_fasteoi_mask_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 21/46] genirq/chip: Use lock guards where applicable Thomas Gleixner
2025-03-13 16:00 ` [patch 22/46] genirq/chip: Rework irq_set_chip() Thomas Gleixner
2025-03-13 16:00 ` [patch 23/46] genirq/chip: Rework irq_set_irq_type() Thomas Gleixner
2025-03-13 16:00 ` [patch 24/46] genirq/chip: Rework irq_set_handler_data() Thomas Gleixner
2025-03-13 16:00 ` [patch 25/46] genirq/chip: Rework irq_set_msi_desc_off() Thomas Gleixner
2025-03-13 16:00 ` [patch 26/46] genirq/chip: Rework irq_set_chip_data() Thomas Gleixner
2025-03-13 16:00 ` [patch 27/46] genirq/chip: Rework irq_set_handler() variants Thomas Gleixner
2025-03-13 16:00 ` [patch 28/46] genirq/chip: Rework irq_modify_status() Thomas Gleixner
2025-03-13 16:00 ` [patch 29/46] genirq/manage: Cleanup kernel doc comments Thomas Gleixner
2025-03-13 16:00 ` Thomas Gleixner [this message]
2025-03-13 16:00 ` [patch 31/46] genirq/manage: Rework irq_update_affinity_desc() Thomas Gleixner
2025-03-13 16:00 ` [patch 32/46] genirq/manage: Rework __irq_apply_affinity_hint() Thomas Gleixner
2025-03-13 16:00 ` [patch 33/46] genirq/manage: Rework irq_set_vcpu_affinity() Thomas Gleixner
2025-03-13 16:00 ` [patch 34/46] genirq/manage: Rework __disable_irq_nosync() Thomas Gleixner
2025-03-13 16:00 ` [patch 35/46] genirq/manage: Rework enable_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 36/46] genirq/manage: Rework irq_set_irq_wake() Thomas Gleixner
2025-03-13 16:00 ` [patch 37/46] genirq/manage: Rework can_request_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 38/46] genirq/manage: Rework irq_set_parent() Thomas Gleixner
2025-03-13 16:00 ` [patch 39/46] genirq/manage: Rework enable_percpu_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 40/46] genirq/manage: Rework irq_percpu_is_enabled() Thomas Gleixner
2025-03-13 16:00 ` [patch 41/46] genirq/manage: Rework disable_percpu_irq() Thomas Gleixner
2025-03-13 16:00 ` [patch 42/46] genirq/manage: Rework prepare_percpu_nmi() Thomas Gleixner
2025-03-13 16:00 ` [patch 43/46] genirq/manage: Rework teardown_percpu_nmi() Thomas Gleixner
2025-03-13 16:00 ` [patch 44/46] genirq/manage: Rework irq_get_irqchip_state() Thomas Gleixner
2025-03-13 16:01 ` [patch 45/46] genirq/manage: Rework irq_set_irqchip_state() Thomas Gleixner
2025-03-13 16:01 ` [patch 46/46] genirq: Remove irq_[get|put]_desc*() Thomas Gleixner
2025-03-14  9:04 ` [patch 00/46] genirq: Cleanups and conversion to lock guards Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313155915.929305667@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox