From: Thomas Gleixner <tglx@linutronix.de>
To: Jiri Slaby <jirislaby@kernel.org>, LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Subject: [patch V2a 02/45] genirq/irqdesc: Switch to lock guards
Date: Wed, 30 Apr 2025 08:36:39 +0200 [thread overview]
Message-ID: <871ptaqhoo.ffs@tglx> (raw)
In-Reply-To: <b566459c-b0b6-4019-8231-04d246f07b0d@kernel.org>
Replace all lock/unlock pairs with lock guards and simplify the code flow.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2a: Fixup the stub function too - Jiry
---
kernel/irq/irqdesc.c | 129 +++++++++++++++++----------------------------------
1 file changed, 44 insertions(+), 85 deletions(-)
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -246,8 +246,7 @@ static struct kobject *irq_kobj_base;
#define IRQ_ATTR_RO(_name) \
static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
-static ssize_t per_cpu_count_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t per_cpu_count_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
ssize_t ret = 0;
@@ -266,99 +265,75 @@ static ssize_t per_cpu_count_show(struct
}
IRQ_ATTR_RO(per_cpu_count);
-static ssize_t chip_name_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t chip_name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
- ssize_t ret = 0;
- raw_spin_lock_irq(&desc->lock);
+ guard(raw_spinlock_irq)(&desc->lock);
if (desc->irq_data.chip && desc->irq_data.chip->name)
- ret = sysfs_emit(buf, "%s\n", desc->irq_data.chip->name);
- raw_spin_unlock_irq(&desc->lock);
-
- return ret;
+ return sysfs_emit(buf, "%s\n", desc->irq_data.chip->name);
+ return 0;
}
IRQ_ATTR_RO(chip_name);
-static ssize_t hwirq_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t hwirq_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
- ssize_t ret = 0;
+ guard(raw_spinlock_irq)(&desc->lock);
raw_spin_lock_irq(&desc->lock);
if (desc->irq_data.domain)
- ret = sysfs_emit(buf, "%lu\n", desc->irq_data.hwirq);
- raw_spin_unlock_irq(&desc->lock);
-
- return ret;
+ return sysfs_emit(buf, "%lu\n", desc->irq_data.hwirq);
+ return 0;
}
IRQ_ATTR_RO(hwirq);
-static ssize_t type_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
- ssize_t ret = 0;
- raw_spin_lock_irq(&desc->lock);
- ret = sysfs_emit(buf, "%s\n", irqd_is_level_type(&desc->irq_data) ? "level" : "edge");
- raw_spin_unlock_irq(&desc->lock);
-
- return ret;
+ guard(raw_spinlock_irq)(&desc->lock);
+ return sysfs_emit(buf, "%s\n", irqd_is_level_type(&desc->irq_data) ? "level" : "edge");
}
IRQ_ATTR_RO(type);
-static ssize_t wakeup_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t wakeup_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
- ssize_t ret = 0;
-
- raw_spin_lock_irq(&desc->lock);
- ret = sysfs_emit(buf, "%s\n", str_enabled_disabled(irqd_is_wakeup_set(&desc->irq_data)));
- raw_spin_unlock_irq(&desc->lock);
-
- return ret;
+ guard(raw_spinlock_irq)(&desc->lock);
+ return sysfs_emit(buf, "%s\n", str_enabled_disabled(irqd_is_wakeup_set(&desc->irq_data)));
}
IRQ_ATTR_RO(wakeup);
-static ssize_t name_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t name_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
- ssize_t ret = 0;
- raw_spin_lock_irq(&desc->lock);
+ guard(raw_spinlock_irq)(&desc->lock);
if (desc->name)
- ret = sysfs_emit(buf, "%s\n", desc->name);
- raw_spin_unlock_irq(&desc->lock);
-
- return ret;
+ return sysfs_emit(buf, "%s\n", desc->name);
+ return 0;
}
IRQ_ATTR_RO(name);
-static ssize_t actions_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buf)
+static ssize_t actions_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
struct irqaction *action;
ssize_t ret = 0;
char *p = "";
- raw_spin_lock_irq(&desc->lock);
- for_each_action_of_desc(desc, action) {
- ret += sysfs_emit_at(buf, ret, "%s%s", p, action->name);
- p = ",";
+ scoped_guard(raw_spinlock_irq, &desc->lock) {
+ for_each_action_of_desc(desc, action) {
+ ret += sysfs_emit_at(buf, ret, "%s%s", p, action->name);
+ p = ",";
+ }
}
- raw_spin_unlock_irq(&desc->lock);
if (ret)
ret += sysfs_emit_at(buf, ret, "\n");
-
return ret;
}
IRQ_ATTR_RO(actions);
@@ -414,19 +389,14 @@ static int __init irq_sysfs_init(void)
int irq;
/* Prevent concurrent irq alloc/free */
- irq_lock_sparse();
-
+ guard(mutex)(&sparse_irq_lock);
irq_kobj_base = kobject_create_and_add("irq", kernel_kobj);
- if (!irq_kobj_base) {
- irq_unlock_sparse();
+ if (!irq_kobj_base)
return -ENOMEM;
- }
/* Add the already allocated interrupts */
for_each_irq_desc(irq, desc)
irq_sysfs_add(irq, desc);
- irq_unlock_sparse();
-
return 0;
}
postcore_initcall(irq_sysfs_init);
@@ -569,12 +539,12 @@ static int alloc_descs(unsigned int star
return -ENOMEM;
}
-static int irq_expand_nr_irqs(unsigned int nr)
+static bool irq_expand_nr_irqs(unsigned int nr)
{
if (nr > MAX_SPARSE_IRQS)
- return -ENOMEM;
+ return false;
nr_irqs = nr;
- return 0;
+ return true;
}
int __init early_irq_init(void)
@@ -652,11 +622,9 @@ EXPORT_SYMBOL(irq_to_desc);
static void free_desc(unsigned int irq)
{
struct irq_desc *desc = irq_to_desc(irq);
- unsigned long flags;
- raw_spin_lock_irqsave(&desc->lock, flags);
- desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL);
- raw_spin_unlock_irqrestore(&desc->lock, flags);
+ scoped_guard(raw_spinlock_irqsave, &desc->lock)
+ desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL);
delete_irq_desc(irq);
}
@@ -675,16 +643,15 @@ static inline int alloc_descs(unsigned i
return start;
}
-static int irq_expand_nr_irqs(unsigned int nr)
+static inline bool irq_expand_nr_irqs(unsigned int nr)
{
- return -ENOMEM;
+ return false;
}
void irq_mark_irq(unsigned int irq)
{
- mutex_lock(&sparse_irq_lock);
+ guard(mutex)(&sparse_irq_lock);
irq_insert_desc(irq, irq_desc + irq);
- mutex_unlock(&sparse_irq_lock);
}
#ifdef CONFIG_GENERIC_IRQ_LEGACY
@@ -823,11 +790,9 @@ void irq_free_descs(unsigned int from, u
if (from >= nr_irqs || (from + cnt) > nr_irqs)
return;
- mutex_lock(&sparse_irq_lock);
+ guard(mutex)(&sparse_irq_lock);
for (i = 0; i < cnt; i++)
free_desc(from + i);
-
- mutex_unlock(&sparse_irq_lock);
}
EXPORT_SYMBOL_GPL(irq_free_descs);
@@ -844,11 +809,10 @@ EXPORT_SYMBOL_GPL(irq_free_descs);
*
* Returns the first irq number or error code
*/
-int __ref
-__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
- struct module *owner, const struct irq_affinity_desc *affinity)
+int __ref __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
+ struct module *owner, const struct irq_affinity_desc *affinity)
{
- int start, ret;
+ int start;
if (!cnt)
return -EINVAL;
@@ -866,22 +830,17 @@ int __ref
from = arch_dynirq_lower_bound(from);
}
- mutex_lock(&sparse_irq_lock);
+ guard(mutex)(&sparse_irq_lock);
start = irq_find_free_area(from, cnt);
- ret = -EEXIST;
if (irq >=0 && start != irq)
- goto unlock;
+ return -EEXIST;
if (start + cnt > nr_irqs) {
- ret = irq_expand_nr_irqs(start + cnt);
- if (ret)
- goto unlock;
+ if (!irq_expand_nr_irqs(start + cnt))
+ return -ENOMEM;
}
- ret = alloc_descs(start, cnt, node, affinity, owner);
-unlock:
- mutex_unlock(&sparse_irq_lock);
- return ret;
+ return alloc_descs(start, cnt, node, affinity, owner);
}
EXPORT_SYMBOL_GPL(__irq_alloc_descs);
next prev parent reply other threads:[~2025-04-30 6:36 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 6:54 [patch V2 00/45] genirq: Cleanups and conversion to lock guards Thomas Gleixner
2025-04-29 6:54 ` [patch V2 01/45] genirq: Provide conditional " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 02/45] genirq/irqdesc: Switch to " Thomas Gleixner
2025-04-30 5:54 ` Jiri Slaby
2025-04-30 6:36 ` Thomas Gleixner [this message]
2025-04-30 6:51 ` [patch V2a " Jiri Slaby
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 03/45] genirq/autoprobe: " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 04/45] genirq/pm: " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 05/45] genirq/resend: " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 06/45] genirq/proc: " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-06-08 12:45 ` [patch V2 06/45] " Zenghui Yu
2025-06-09 7:15 ` Zenghui Yu
2025-06-09 7:28 ` Jiri Slaby
2025-06-09 10:00 ` Thomas Gleixner
2025-06-09 9:50 ` Thomas Gleixner
2025-04-29 6:54 ` [patch V2 07/45] genirq/spurious: Cleanup code Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:54 ` [patch V2 08/45] genirq/spurious: Switch to lock guards Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 09/45] genirq/cpuhotplug: Convert " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-05-08 14:56 ` [patch V2 09/45] " Marek Szyprowski
2025-05-08 17:53 ` Thomas Gleixner
2025-04-29 6:55 ` [patch V2 10/45] genirq/debugfs: " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 11/45] genirq/chip: Prepare for code reduction Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 12/45] genirq/chip: Rework handle_nested_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-05-08 20:56 ` [patch V2 12/45] " Marek Szyprowski
2025-05-09 18:37 ` Thomas Gleixner
2025-04-29 6:55 ` [patch V2 13/45] genirq/chip: Rework handle_simple_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 14/45] genirq/chip: Rework handle_untracked_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 15/45] genirq/chip: Rework handle_level_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 16/45] genirq/chip: Rework handle_eoi_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 17/45] genirq/chip: Rework handle_edge_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 18/45] genirq/chip: Rework handle_fasteoi_ack_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 19/45] genirq/chip: Rework handle_fasteoi_mask_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 20/45] genirq/chip: Use lock guards where applicable Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 21/45] genirq/chip: Rework irq_set_chip() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 22/45] genirq/chip: Rework irq_set_irq_type() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 23/45] genirq/chip: Rework irq_set_handler_data() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 24/45] genirq/chip: Rework irq_set_msi_desc_off() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 25/45] genirq/chip: Rework irq_set_chip_data() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 26/45] genirq/chip: Rework irq_set_handler() variants Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-05-09 13:22 ` [patch V2 26/45] " Nathan Chancellor
2025-05-11 17:29 ` Miguel Ojeda
2025-05-11 17:49 ` Nathan Chancellor
2025-05-12 7:25 ` Jiri Slaby
2025-05-12 7:32 ` Jiri Slaby
2025-05-12 8:06 ` Jiri Slaby
2025-05-12 18:39 ` Thomas Gleixner
2025-04-29 6:55 ` [patch V2 27/45] genirq/chip: Rework irq_modify_status() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 28/45] genirq/manage: Cleanup kernel doc comments Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 29/45] genirq/manage: Convert to lock guards Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 30/45] genirq/manage: Rework irq_update_affinity_desc() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 31/45] genirq/manage: Rework __irq_apply_affinity_hint() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 32/45] genirq/manage: Rework irq_set_vcpu_affinity() Thomas Gleixner
2025-04-30 6:31 ` Jiri Slaby
2025-04-30 12:49 ` [patch V2a " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 33/45] genirq/manage: Rework __disable_irq_nosync() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 34/45] genirq/manage: Rework enable_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 35/45] genirq/manage: Rework irq_set_irq_wake() Thomas Gleixner
2025-04-30 6:37 ` Jiri Slaby
2025-04-30 12:42 ` Thomas Gleixner
2025-04-30 12:48 ` [patch V2a " Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-05-13 17:32 ` [patch V2a 35/45] " Jon Hunter
2025-05-13 22:55 ` Thomas Gleixner
2025-05-14 7:14 ` Jon Hunter
2025-04-29 6:55 ` [patch V2 36/45] genirq/manage: Rework can_request_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 37/45] genirq/manage: Rework irq_set_parent() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 38/45] genirq/manage: Rework enable_percpu_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 39/45] genirq/manage: Rework irq_percpu_is_enabled() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 40/45] genirq/manage: Rework disable_percpu_irq() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 41/45] genirq/manage: Rework prepare_percpu_nmi() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 42/45] genirq/manage: Rework teardown_percpu_nmi() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 43/45] genirq/manage: Rework irq_get_irqchip_state() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 44/45] genirq/manage: Rework irq_set_irqchip_state() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-04-29 6:55 ` [patch V2 45/45] genirq: Remove irq_[get|put]_desc*() Thomas Gleixner
2025-05-07 9:07 ` [tip: irq/core] " tip-bot2 for Thomas Gleixner
2025-05-06 14:24 ` [patch V2 00/45] 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=871ptaqhoo.ffs@tglx \
--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