[PATCH 1/9] irq/irqdesc: put the lock at the exact place in irq_sysfs_init()

Pingfan Liu
2022-04-20T14:05:48Z

sparse_irq_lock is used to protect irq_desc, and furthermore
irq_sysfs_init() is called only once, so put irq_lock_sparse() at the
exact place, where the race condition may start.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
To: linux-kernel@vger.kernel.org
---
kernel/irq/irqdesc.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 939d21cd55c3..8d0982233277 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -312,15 +312,14 @@ static int __init irq_sysfs_init(void)
struct irq_desc *desc;
int irq;

- /* Prevent concurrent irq alloc/free */
- irq_lock_sparse();
-
irq_kobj_base = kobject_create_and_add("irq", kernel_kobj);
if (!irq_kobj_base) {
- irq_unlock_sparse();
return -ENOMEM;
}

+ /* Prevent concurrent irq alloc/free */
+ irq_lock_sparse();
+
/* Add the already allocated interrupts */
for_each_irq_desc(irq, desc)
irq_sysfs_add(irq, desc);
--
2.31.1